Kimai_Database_Mysql::customer_get_groupIDs PHP Method

customer_get_groupIDs() public method

returns all IDs of the groups of the given customer
Author: th
public customer_get_groupIDs ( integer $customerID ) : array
$customerID integer id of the customer
return array contains the groupIDs of the groups or false on error
    public function customer_get_groupIDs($customerID)
    {
        $filter['customerID'] = MySQL::SQLValue($customerID, MySQL::SQLVALUE_NUMBER);
        $columns[] = "groupID";
        $table = $this->kga['server_prefix'] . "groups_customers";
        $result = $this->conn->SelectRows($table, $filter, $columns);
        if ($result == false) {
            return false;
        }
        $groupIDs = array();
        $counter = 0;
        $rows = $this->conn->RecordsArray(MYSQLI_ASSOC);
        if ($this->conn->RowCount()) {
            foreach ($rows as $row) {
                $groupIDs[$counter] = $row['groupID'];
                $counter++;
            }
            return $groupIDs;
        } else {
            $this->logLastError('customer_get_groupIDs');
            return false;
        }
    }

Usage Example

Beispiel #1
0
/**
 * @param Kimai_Database_Mysql $database
 * @param array $kgaUser
 * @param bool $viewOtherGroupsAllowed
 * @return array
 */
function getCustomersData(Kimai_Database_Mysql $database, $kgaUser, $viewOtherGroupsAllowed)
{
    if ($database->global_role_allows($kgaUser['globalRoleID'], 'core-customer-otherGroup-view')) {
        $customers = $database->get_customers();
    } else {
        $customers = $database->get_customers($kgaUser['groups']);
    }
    foreach ($customers as $row => $data) {
        $groupNames = array();
        $groups = $database->customer_get_groupIDs($data['customerID']);
        if ($groups !== false) {
            foreach ($groups as $groupID) {
                if (!$viewOtherGroupsAllowed && array_search($groupID, $kgaUser['groups']) === false) {
                    continue;
                }
                $data = $database->group_get_data($groupID);
                $groupNames[] = $data['name'];
            }
            $customers[$row]['groups'] = implode(", ", $groupNames);
        }
    }
    return array('customers' => $customers);
}
Kimai_Database_Mysql