Kimai_Database_Mysql::project_get_groupIDs PHP Method

project_get_groupIDs() public method

returns all the groups of the given project
Author: th
public project_get_groupIDs ( array $projectID ) : array
$projectID array ID of the project
return array contains the groupIDs of the groups or false on error
    public function project_get_groupIDs($projectID)
    {
        $filter['projectID'] = MySQL::SQLValue($projectID, MySQL::SQLVALUE_NUMBER);
        $columns[] = "groupID";
        $table = $this->kga['server_prefix'] . "groups_projects";
        $result = $this->conn->SelectRows($table, $filter, $columns);
        if ($result == false) {
            $this->logLastError('project_get_groupIDs');
            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 {
            return false;
        }
    }

Usage Example

Beispiel #1
0
/**
 * @param Kimai_Database_Mysql $database
 * @param array $kgaUser
 * @param bool $viewOtherGroupsAllowed
 * @return array
 */
function getProjectsData(Kimai_Database_Mysql $database, $kgaUser, $viewOtherGroupsAllowed)
{
    if ($database->global_role_allows($kgaUser['globalRoleID'], 'core-project-otherGroup-view')) {
        $projects = $database->get_projects();
    } else {
        $projects = $database->get_projects($kgaUser['groups']);
    }
    $result = array();
    if ($projects !== null && is_array($projects)) {
        foreach ($projects as $row => $project) {
            $groupNames = array();
            foreach ($database->project_get_groupIDs($project['projectID']) as $groupID) {
                if (!$viewOtherGroupsAllowed && array_search($groupID, $kgaUser['groups']) === false) {
                    continue;
                }
                $data = $database->group_get_data($groupID);
                $groupNames[] = $data['name'];
            }
            $projects[$row]['groups'] = implode(", ", $groupNames);
        }
        $result['projects'] = $projects;
    }
    return $result;
}
Kimai_Database_Mysql