Kimai_Database_Mysql::assign_activityToGroups PHP Method

assign_activityToGroups() public method

Assigns an activity to 1-n groups by adding entries to the cross table
Author: ob/th
public assign_activityToGroups ( integer $activityID, array $groupIDs ) : boolean
$activityID integer activityID of the project to which the groups will be assigned
$groupIDs array contains one or more groupIDs
return boolean true on success, false on failure
    public function assign_activityToGroups($activityID, $groupIDs)
    {
        if (!$this->conn->TransactionBegin()) {
            $this->logLastError('assign_activityToGroups');
            return false;
        }
        $table = $this->kga['server_prefix'] . "groups_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_activityToGroups');
            $this->conn->TransactionRollback();
            return false;
        }
        foreach ($groupIDs as $groupID) {
            $values['groupID'] = MySQL::SQLValue($groupID, 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_activityToGroups');
                $this->conn->TransactionRollback();
                return false;
            }
        }
        if ($this->conn->TransactionEnd() == true) {
            return true;
        } else {
            $this->logLastError('assign_activityToGroups');
            return false;
        }
    }
Kimai_Database_Mysql