Kimai_Database_Mysql::assign_activityToProjects PHP Method

assign_activityToProjects() public method

Assigns an activity to 1-n projects by adding entries to the cross table
Author: ob/th
public assign_activityToProjects ( integer $activityID, array $projectIDs ) : boolean
$activityID integer id of the activity to which projects will be assigned
$projectIDs array contains one or more projectIDs
return boolean true on success, false on failure
    public function assign_activityToProjects($activityID, $projectIDs)
    {
        if (!$this->conn->TransactionBegin()) {
            $this->logLastError('assign_activityToProjects');
            return false;
        }
        $table = $this->kga['server_prefix'] . "projects_activities";
        $filter['activityID'] = MySQL::SQLValue($activityID, MySQL::SQLVALUE_NUMBER);
        $d_query = MySQL::BuildSQLDelete($table, $filter);
        $d_result = $this->conn->Query($d_query);
        if ($d_result == false) {
            $this->logLastError('assign_activityToProjects');
            $this->conn->TransactionRollback();
            return false;
        }
        foreach ($projectIDs as $projectID) {
            $values['projectID'] = MySQL::SQLValue($projectID, MySQL::SQLVALUE_NUMBER);
            $values['activityID'] = MySQL::SQLValue($activityID, MySQL::SQLVALUE_NUMBER);
            $query = MySQL::BuildSQLInsert($table, $values);
            $result = $this->conn->Query($query);
            if ($result == false) {
                $this->logLastError('assign_activityToProjects');
                $this->conn->TransactionRollback();
                return false;
            }
        }
        if ($this->conn->TransactionEnd() == true) {
            return true;
        } else {
            $this->logLastError('assign_activityToProjects');
            return false;
        }
    }
Kimai_Database_Mysql