示例#1
0
 /**
  * handle common tasks for the romm request form
  * (set properties, searching etc.)
  */
 public static function process_form($request, $admission_turnout = null)
 {
     if (Request::submitted('room_request_form')) {
         CSRFProtection::verifyUnsafeRequest();
         if (Request::submitted('send_room')) {
             $request->setResourceId(Request::option('select_room'));
         } else {
             $request->setResourceId(Request::option('selected_room'));
         }
         if (Request::submitted('reset_resource_id')) {
             $request->setResourceId('');
         }
         if (Request::submitted('reset_room_type')) {
             $request->setCategoryId('');
         }
         if (Request::get('comment') !== null) {
             $request->setComment(Request::get('comment'));
         }
         if (Request::get('reply_recipients') !== null) {
             $request->reply_recipients = Request::get('reply_recipients');
         }
         if (!Request::submitted('reset_room_type')) {
             $request->setCategoryId(Request::option('select_room_type'));
         }
         //Property Requests
         if ($request->getCategoryId()) {
             $request_property_val = Request::getArray('request_property_val');
             foreach ($request->getAvailableProperties() as $prop) {
                 if ($prop["system"] == 2) {
                     //it's the property for the seat/room-size!
                     if (Request::get('seats_are_admission_turnout') && $admission_turnout) {
                         $request->setPropertyState($prop['property_id'], $admission_turnout);
                     } else {
                         if (!Request::submitted('send_room_type')) {
                             $request->setPropertyState($prop['property_id'], abs($request_property_val[$prop['property_id']]));
                         }
                     }
                 } else {
                     $request->setPropertyState($prop['property_id'], $request_property_val[$prop['property_id']]);
                 }
             }
         }
         if (Request::get('search_exp_room') && Request::submitted('search_room') || Request::submitted('search_properties')) {
             $tmp_search_result = $request->searchRoomsToRequest(Request::get('search_exp_room'), Request::submitted('search_properties'));
             $search_by_properties = Request::submitted('search_properties');
             $search_result = array();
             if (count($tmp_search_result)) {
                 $timestamps = $events = array();
                 foreach ($request->getAffectedDates() as $date) {
                     if (!isset($date->room_assignment)) {
                         $timestamps[] = $date->date;
                         $timestamps[] = $date->end_time;
                         $event = new AssignEvent($date->id, $date->date, $date->end_time, null, null, '');
                         $events[$event->getId()] = $event;
                     }
                 }
                 $check_result = array();
                 if (count($events)) {
                     $checker = new CheckMultipleOverlaps();
                     $checker->setTimeRange(min($timestamps), max($timestamps));
                     foreach (array_keys($tmp_search_result) as $room) {
                         $checker->addResource($room);
                     }
                     $checker->checkOverlap($events, $check_result, "assign_id");
                 }
                 foreach ($tmp_search_result as $room_id => $name) {
                     if (isset($check_result[$room_id])) {
                         $details = $check_result[$room_id];
                         if (count($details) >= round(count($events) * Config::get()->RESOURCES_ALLOW_SINGLE_ASSIGN_PERCENTAGE / 100)) {
                             $overlap_status = 'status-red';
                         } elseif (count($details)) {
                             $overlap_status = 'status-yellow';
                         }
                     } else {
                         $overlap_status = 'status-green';
                     }
                     $search_result[$room_id] = array('name' => $name, 'overlap_status' => $overlap_status);
                 }
             }
         }
     }
     return compact('search_result', 'search_by_properties', 'request', 'admission_turnout');
 }
示例#2
0
    function showSearchList($search_array, $check_assigns = FALSE)
    {
        //create the query
        if ($search_array['resources_search_range']){
            $search_only = $this->getResourcesSearchRange($search_array['resources_search_range']);
        }

        $parameters = array();
        if ($search_array['properties']) {
            $query = "SELECT a.resource_id, COUNT(a.resource_id) AS resource_id_count
                      FROM resources_objects_properties AS a
                      LEFT JOIN resources_objects AS b USING (resource_id)
                      LEFT JOIN resources_categories USING (category_id)";
            if (!hasGlobalOccupationAccess()) {
                $query .= " LEFT JOIN `resources_user_resources` AS rur ON (rur.`resource_id` = b.`resource_id`)";
            }
            $query .= " WHERE ";

            $conditions = array();
            $i = 0;
            foreach ($search_array['properties'] as $key => $val) {
                // if ($val == 'on') {
                //     $val = 1;
                // }

                //let's create some possible wildcards
                if (strpos($val, '<=') !== false) {
                    $val     = (int) substr($val, strpos($val, '<=') + 2);
                    $linking = '<=';
                } elseif (strpos($val, '>=') !== false) {
                    $val     = (int) substr($val, strpos($val, '>=') + 2);
                    $linking = '>=';
                } elseif (strpos($val, '<') !== false) {
                    $val     = (int) substr($val, strpos($val, '<') + 1);
                    $linking = '<';
                } elseif (strpos($val, '>') !== false) {
                    $val     = (int) substr($val, strpos($val, '>') + 1);
                    $linking = '>';
                } else {
                    $linking = '=';
                }
                $conditions[] = "(property_id = :key{$i} AND state {$linking} :state{$i})";
                $parameters[':key' . $i]   = $key;
                $parameters[':state' . $i] = $val;

                $i += 1;
            }
            $query .= (count($conditions) > 0)
                    ? implode(' OR ', $conditions)
                    : '1';

            $query .= " AND b.name LIKE CONCAT('%', :needle, '%')";
            $parameters[':needle'] = $search_array['search_exp'];

            if ($this->supress_hierachy_levels) {
                $query .= " AND b.category_id != ''";
            }
            if ($this->show_only_rooms) {
                $query .= " AND is_room = 1";
            }
            if ($search_array['resources_search_range']) {
                $query .= " AND b.resource_id IN (:resource_ids)";
                $parameters[':resource_ids'] = $resource_ids ?: '';
            }

            if (!hasGlobalOccupationAccess()) {
                $query .= " AND (b.`owner_id`=:user OR rur.`user_id`=:user)";
                $parameters[':user'] = $GLOBALS['user']->id;
            }

            $query .= " GROUP BY a.resource_id
                        HAVING resource_id_count = :count";
            $parameters[':count'] = $i;

            $query .=" ORDER BY b.name";
        } else {
            $query = "SELECT resource_id
                      FROM resources_objects AS ro
                      LEFT JOIN resources_categories USING (category_id)";

            if (!hasGlobalOccupationAccess()) {
                $query .= " LEFT JOIN `resources_user_resources` USING (`resource_id`)";
            }
            $query .= " WHERE ro.name LIKE CONCAT('%', :needle, '%')";

            $parameters[':needle'] = $search_array['search_exp'];

            if ($this->supress_hierachy_levels) {
                $query .= " AND ro.category_id != ''";
            }
            if ($this->show_only_rooms) {
                $query .= " AND is_room = 1";
            }
            if ($search_array['resources_search_range']) {
                $query .= " AND ro.resource_id IN (:resource_ids)";
                $parameters[':resource_ids'] = $search_only ?: '';
            }

            if (!hasGlobalOccupationAccess()) {
                $query .= " AND (ro.`owner_id`=:user OR `user_id`=:user)";
                $parameters[':user'] = $GLOBALS['user']->id;
            }

            $query .= " ORDER BY ro.name";
        }

        $statement = DBManager::get()->prepare($query);
        $statement->execute($parameters);
        $resource_ids = $statement->fetchAll(PDO::FETCH_COLUMN);

        //if we have an empty result
        if (count($resource_ids) == 0 && $level == 0) {
            return FALSE;
        }

        foreach ($resource_ids as $resource_id) {
            $found_resources[$resource_id] = TRUE;
        }
        $day_of_week = false;
        //do further checks to determine free resources inthe given time range
        if ($search_array["search_assign_begin"] && $check_assigns) {
            $multiOverlaps = new CheckMultipleOverlaps;

            // >> changed for advanced search for room administrators
            if ($search_array["search_repeating"])
            {
                // is this slot empty for the rest of the term?
                $semester_data = new SemesterData();
                $semester = $semester_data->getSemesterDataByDate($search_array["search_assign_begin"]);
                // create the dummy assign object
                $assObj = new AssignObject('');
                $assObj->setBegin($search_array["search_assign_begin"]);
                $assObj->setEnd($search_array["search_assign_end"]);
                $assObj->setRepeatEnd($semester["vorles_ende"]);
                $assObj->setRepeatInterval(1);
                $assObj->setRepeatQuantity(-1);

                // calculate stud.IP-day-of-week
                $day_of_week = date("w", $search_array["search_assign_begin"]);
                $day_of_week = $day_of_week == 0 ? 7 : $day_of_week;

                $assObj->setRepeatDayOfWeek($day_of_week);
                // set time range for checks
                $multiOverlaps->setAutoTimeRange(Array($assObj));
                // generate and get the events represented by assign object
                $events = $assObj->getEvents();

                foreach($events as $ev)
                {
                    $event[$ev->getId()] = $ev;
                }
            } else
            {
                // the code for one specific slot
                $assEvt = new AssignEvent('', $search_array["search_assign_begin"], $search_array["search_assign_end"], '', '');
                $multiOverlaps->setTimeRange($search_array["search_assign_begin"], $search_array["search_assign_end"]);
                $event[$assEvt->getId()] = $assEvt;
            }
            // << changed for advanced search for room administrators

            //add the found resources to the check-set
            foreach ($found_resources as $key=>$val) {
                $multiOverlaps->addResource($key, $day_of_week);
            }

            $multiOverlaps->checkOverlap($event, $result);
            //output
            foreach ($found_resources as $key=>$val) {
                if (!$result[$key]) {
                    $this->showListObject($key);
                    $result_count++;
                }
            }
        } else {
            //output
            foreach ($found_resources as $key=>$val) {
                $this->showListObject($key);
                $result_count++;
            }
        }

    return $result_count;
    }
示例#3
0
文件: helpers.php 项目: ratbird/hope
 function bookable_rooms_action()
 {
     if (!getGlobalPerms($GLOBALS['user']->id) == 'admin') {
         $resList = new ResourcesUserRoomsList($GLOBALS['user']->id, false, false, false);
         if (!$resList->roomsExist()) {
             throw new AccessDeniedException();
         }
     }
     $select_options = Request::optionArray('rooms');
     $rooms = array_filter($select_options, function ($v) {
         return strlen($v) === 32;
     });
     $events = array();
     $dates = array();
     $timestamps = array();
     if (count(Request::getArray('new_date'))) {
         $new_date = array();
         foreach (Request::getArray('new_date') as $one) {
             if ($one['name'] == 'startDate') {
                 $dmy = explode('.', $one['value']);
                 $new_date['day'] = (int) $dmy[0];
                 $new_date['month'] = (int) $dmy[1];
                 $new_date['year'] = (int) $dmy[2];
             }
             $new_date[$one['name']] = (int) $one['value'];
         }
         if (check_singledate($new_date['day'], $new_date['month'], $new_date['year'], $new_date['start_stunde'], $new_date['start_minute'], $new_date['end_stunde'], $new_date['end_minute'])) {
             $start = mktime($new_date['start_stunde'], $new_date['start_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']);
             $ende = mktime($new_date['end_stunde'], $new_date['end_minute'], 0, $new_date['month'], $new_date['day'], $new_date['year']);
             $timestamps[] = $start;
             $timestamps[] = $ende;
             $event = new AssignEvent('new_date', $start, $ende, null, null, '');
             $events[$event->getId()] = $event;
         }
     }
     foreach (Request::optionArray('selected_dates') as $one) {
         $date = new SingleDate($one);
         if ($date->getStartTime()) {
             $timestamps[] = $date->getStartTime();
             $timestamps[] = $date->getEndTime();
             $event = new AssignEvent($date->getTerminID(), $date->getStartTime(), $date->getEndTime(), null, null, '');
             $events[$event->getId()] = $event;
             $dates[$date->getTerminID()] = $date;
         }
     }
     if (count($events)) {
         $result = array();
         $checker = new CheckMultipleOverlaps();
         $checker->setTimeRange(min($timestamps), max($timestamps));
         foreach ($rooms as $room) {
             $checker->addResource($room);
         }
         $checker->checkOverlap($events, $result, "assign_id");
         foreach ((array) $result as $room_id => $details) {
             foreach ($details as $termin_id => $conflicts) {
                 if ($termin_id == 'new_date' && Request::option('singleDateID')) {
                     $assign_id = SingleDateDB::getAssignID(Request::option('singleDateID'));
                 } else {
                     $assign_id = SingleDateDB::getAssignID($termin_id);
                 }
                 $filter = function ($a) use($assign_id) {
                     if ($a['assign_id'] && $a['assign_id'] == $assign_id) {
                         return false;
                     }
                     return true;
                 };
                 if (!count(array_filter($conflicts, $filter))) {
                     unset($result[$room_id][$termin_id]);
                 }
             }
         }
         $result = array_filter($result);
         $this->render_json(array_keys($result));
         return;
     }
     $this->render_nothing();
 }