Kimai_Database_Mysql::get_projects PHP Method

get_projects() public method

returns list of projects for specific group as array
Author: th
public get_projects ( array $groups = null ) : array
$groups array ID of user in database
return array
    public function get_projects(array $groups = null)
    {
        $p = $this->kga['server_prefix'];
        if (empty($groups)) {
            $query = "SELECT project.*, customer.name AS customerName, customer.visible as customerVisible\n                  FROM {$p}projects AS project\n                  JOIN {$p}customers AS customer USING(customerID)\n                  WHERE project.trash=0";
        } else {
            $query = "SELECT DISTINCT project.*, customer.name AS customerName, customer.visible as customerVisible\n                  FROM {$p}projects AS project\n                  JOIN {$p}customers AS customer USING(customerID)\n                  JOIN {$p}groups_projects USING(projectID)\n                  WHERE {$p}groups_projects.groupID IN (" . implode($groups, ',') . ")\n                  AND project.trash=0";
        }
        if ($this->kga->getSettings()->isFlipProjectDisplay()) {
            $query .= " ORDER BY project.visible DESC, customer.visible DESC, customerName, name;";
        } else {
            $query .= " ORDER BY project.visible DESC, customer.visible DESC, name, customerName;";
        }
        $result = $this->conn->Query($query);
        if ($result == false) {
            $this->logLastError('get_projects');
            return false;
        }
        $rows = $this->conn->RecordsArray(MYSQLI_ASSOC);
        if ($rows) {
            $arr = array();
            $i = 0;
            foreach ($rows as $row) {
                $arr[$i]['projectID'] = $row['projectID'];
                $arr[$i]['customerID'] = $row['customerID'];
                $arr[$i]['name'] = $row['name'];
                $arr[$i]['comment'] = $row['comment'];
                $arr[$i]['visible'] = $row['visible'];
                $arr[$i]['filter'] = $row['filter'];
                $arr[$i]['trash'] = $row['trash'];
                $arr[$i]['budget'] = $row['budget'];
                $arr[$i]['effort'] = $row['effort'];
                $arr[$i]['approved'] = $row['approved'];
                $arr[$i]['internal'] = $row['internal'];
                $arr[$i]['customerName'] = $row['customerName'];
                $arr[$i]['customerVisible'] = $row['customerVisible'];
                $i++;
            }
            return $arr;
        }
        return array();
    }

Usage Example

Beispiel #1
0
/**
 * @param Kimai_Database_Mysql $database
 * @param array $kgaUser
 * @param bool $viewOtherGroupsAllowed
 * @return array
 * @throws Zend_View_Exception
 */
function getActivitiesData(Kimai_Database_Mysql $database, $kgaUser, $viewOtherGroupsAllowed)
{
    $groups = null;
    if (!$database->global_role_allows($kgaUser['globalRoleID'], 'core-activity-otherGroup-view')) {
        $groups = $kgaUser['groups'];
    }
    $activity_filter = isset($_REQUEST['activity_filter']) ? intval($_REQUEST['activity_filter']) : -2;
    switch ($activity_filter) {
        case -2:
            // -2 is not a valid project id this will give us all unassigned activities.
            $activities = $database->get_activities_by_project(-2, $groups);
            break;
        case -1:
            $activities = $database->get_activities($groups);
            break;
        default:
            $activities = $database->get_activities_by_project($activity_filter, $groups);
    }
    foreach ($activities as $row => $activity) {
        $groupNames = array();
        foreach ($database->activity_get_groups($activity['activityID']) as $groupID) {
            if (!$viewOtherGroupsAllowed && array_search($groupID, $kgaUser['groups']) === false) {
                continue;
            }
            $data = $database->group_get_data($groupID);
            $groupNames[] = $data['name'];
        }
        $activities[$row]['groups'] = implode(", ", $groupNames);
        $activities[$row]['projects'] = $database->activity_get_projects($activity['activityID']) ?: array();
    }
    $result = array();
    if (count($activities) > 0) {
        $result['activities'] = $activities;
    } else {
        $result['activities'] = array();
    }
    $result['projects'] = $database->get_projects($groups);
    $result['selected_activity_filter'] = $activity_filter;
    return $result;
}
Kimai_Database_Mysql