Example #1
0
function getMyRoomRequests($user_id = '', $semester_id = null, $only_not_closed = true, $single_request = null, $sem_type = null, $faculty = null, $tagged = null)
{
    global $user, $perm, $RELATIVE_PATH_RESOURCES;
    $db = DBManager::get();
    if (!$user_id) {
        $user_id = $user->id;
    }
    $parameters = array();
    if ($only_not_closed) {
        $criteria = ' closed = 0 ';
    } else {
        $criteria = ' 1 ';
    }
    if ($single_request) {
        $criteria .= " AND rr.request_id = :request_id";
        $parameters[':request_id'] = $single_request;
    } elseif ($semester_id) {
        $semester = Semester::find($semester_id);
        $sem_criteria = ' AND t.date BETWEEN ' . (int) $semester['beginn'] . ' AND ' . (int) $semester['ende'];
        if ($sem_type) {
            $criteria .= " AND EXISTS (SELECT * FROM seminare WHERE seminare.Seminar_id=rr.seminar_id AND seminare.status=" . (int) $sem_type . ") ";
        }
        if ($faculty) {
            $criteria .= " AND EXISTS (SELECT * FROM seminare INNER JOIN Institute USING(Institut_id) WHERE seminare.Seminar_id=rr.seminar_id AND fakultaets_id=" . DBManager::get()->quote($faculty) . ") ";
        }
        if ($tagged) {
            $criteria .= " AND NOT EXISTS (SELECT * FROM resources_requests_user_status WHERE resources_requests_user_status.request_id=rr.request_id AND resources_requests_user_status.user_id=" . DBManager::get()->quote($user_id) . ") ";
        }
    }
    $query0 = "SELECT request_id, closed, rr.resource_id\n               FROM resources_requests AS rr\n               WHERE %s ";
    $queries = array();
    $queries[] = "SELECT request_id\n                  FROM resources_requests AS rr\n                  INNER JOIN termine t\n                     ON (t.termin_id = rr.termin_id AND t.date > UNIX_TIMESTAMP() {$sem_criteria})\n                  WHERE rr.termin_id <> '' AND %s";
    $presence_type_clause = getPresenceTypeClause();
    $queries[] = "SELECT DISTINCT request_id\n                  FROM resources_requests AS rr\n                  INNER JOIN termine AS t\n                     ON (rr.seminar_id = t.range_id AND\n                         t.date_typ IN {$presence_type_clause} AND\n                         t.date > UNIX_TIMESTAMP() {$sem_criteria})\n                  WHERE rr.termin_id = '' AND rr.metadate_id = '' AND %s ";
    $queries[] = "SELECT DISTINCT request_id\n                  FROM resources_requests AS rr\n                  INNER JOIN termine AS t ON (t.metadate_id = rr.metadate_id AND t.date > UNIX_TIMESTAMP() {$sem_criteria})\n                  WHERE rr.metadate_id <> '' AND %s ";
    $requests = array();
    if (getGlobalPerms($user_id) == 'admin') {
        $query = sprintf($query0, $criteria);
        $statement = DBManager::get()->prepare($query);
        $statement->execute($parameters);
        while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
            $requests[$row['request_id']] = array('my_sem' => true, 'my_res' => strlen($row['resource_id']) > 0, 'closed' => $row['closed'], 'resource_id' => $row['resource_id']);
        }
        foreach ($queries as $q) {
            $query = sprintf($q, $criteria);
            $statement = DBManager::get()->prepare($query);
            $statement->execute($parameters);
            while ($request_id = $statement->fetchColumn()) {
                $requests[$request_id]['have_times'] = 1;
            }
        }
    } else {
        //load all my resources
        $resList = new ResourcesUserRoomsList($user_id, FALSE, FALSE);
        $my_res = $resList->getRooms();
        if (count($my_res) > 0) {
            foreach (array_keys($my_res) as $res_id) {
                $object_perms = ResourceObjectPerms::Factory($res_id, $user_id);
                if (!$object_perms->havePerm('tutor')) {
                    unset($my_res[$res_id]);
                }
            }
        }
        if (count($my_res) > 0) {
            $res_criteria = $criteria . " AND rr.resource_id IN (:resource_ids)";
            $params = $parameters;
            $params[':resource_ids'] = array_keys($my_res);
            $query = sprintf($query0, $res_criteria);
            $statement = DBManager::get()->prepare($query);
            $statement->execute($params);
            while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
                $requests[$row['request_id']] = array('my_res' => true, 'closed' => $row['closed'], 'resource_id' => $row['resource_id']);
            }
            foreach ($queries as $q) {
                $query = sprintf($q, $res_criteria);
                $statement = DBManager::get()->prepare($query);
                $statement->execute($params);
                while ($request_id = $statement->fetchColumn()) {
                    $requests[$request_id]['have_times'] = 1;
                }
            }
            //load all my seminars
            $my_sems = search_administrable_seminars();
            if (count($my_sems) > 0) {
                $sem_criteria = $criteria . " AND rr.seminar_id IN (:seminar_ids)";
                $params = $parameters;
                $params[':seminar_ids'] = array_keys($my_sems);
                $query = sprintf($query0, $sem_criteria);
                $statement = DBManager::get()->prepare($query);
                $statement->execute($params);
                while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
                    $request_id = $row['request_id'];
                    $requests[$request_id]['my_sem'] = true;
                    $requests[$request_id]['closed'] = $row['closed'];
                    $requests[$request_id]['resource_id'] = $row['resource_id'];
                }
                foreach ($queries as $q) {
                    $query = sprintf($q, $sem_criteria);
                    $statement = DBManager::get()->prepare($query);
                    $statement->execute($params);
                    while ($request_id = $statement->fetchColumn()) {
                        $requests[$request_id]['have_times'] = 1;
                    }
                }
            }
        }
    }
    return $requests;
}
Example #2
0
 public function searchRoomsToRequest($search_exp, $properties = false)
 {
     $permitted_rooms = null;
     if (getGlobalPerms($GLOBALS['user']->id) != 'admin' && !Config::GetInstance()->getValue('RESOURCES_ALLOW_ROOM_REQUESTS_ALL_ROOMS')) {
         $my_rooms = new ResourcesUserRoomsList($GLOBALS['user']->id, false, false, true);
         $global_resources = DBManager::get()->query("SELECT resource_id FROM resources_objects WHERE owner_id='global'")->fetchAll(PDO::FETCH_COLUMN);
         $permitted_rooms = array_unique(array_merge(array_keys($my_rooms->getRooms()), $global_resources));
     }
     return $this->searchRooms($search_exp, $properties, 0, 0, true, $permitted_rooms);
 }
Example #3
0
 function createVirtualGroups(){
     $db = DBManager::get();
     $room_list = new ResourcesUserRoomsList($GLOBALS['user']->id, false, false, true);
     $res_obj = ResourceObject::Factory();
     $offset = count($this->groups);
     if ($room_list->numberOfRooms()){
         $rs = $db->query("SELECT parent_id,resource_id 
             FROM resources_objects 
             WHERE resource_id IN('"
             . join("','", array_keys($room_list->getRooms()))."') ORDER BY name");
         foreach($rs->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP) as $parent_id => $resource_ids){
             if (is_array($resource_ids) && count($resource_ids)){
                 $res_obj->restore($parent_id);
                 $this->groups[$offset]['name'] = $res_obj->getPathToString(true);
                 foreach ($resource_ids as $resource_id){
                     $this->groups[$offset]['resources'][] = $resource_id;  
                 }
                 ++$offset;
             }
         }
     }
 }