Example #1
0
	static function getResources( $course )
	{	
		$resources =array();
		//for cycleDates
		foreach ($course->metadate->cycles AS $cycle_date)
		{
			$metadate_id	= $cycle_date->metadate_id;
			$termine		= \CycleDataDB::getTermine($metadate_id);
			
			//filter the resources
			$resourcesForTermin = array();
			foreach ($termine AS $termin)
			{
				if (($termin["resource_id"]!="") 
					&& (!in_array($termin["resource_id"], $resourcesForTermin)))
				{
					//wenn resource_id gefunden in array packen
					array_push($resourcesForTermin, $termin["resource_id"]);
				}
			}
			// all resources fot current cycle are 
			//stored in $resourcesForTermin
			
			// for all resources fot the current date
			foreach ($resourcesForTermin AS $resourceID)
			{
				$resObject = \ResourceObject::Factory( $resourceID );
				$location = Resource::getLocationForResource($resObject);
				$resources[$metadate_id]["id"]			= $resourceID;
				$resources[$metadate_id]["name"]		= $resObject->	getName();
				$resources[$metadate_id]["description"]	= $resObject->getDescription();
				$resources[$metadate_id]["longitude"]	= $location["longitude"];
				$resources[$metadate_id]["latitude"]	= $location["latitude"]; 
			}
		}
		return $resources;
	}
 function getDates($seminar_id, $start_time = 0, $end_time = 0)
 {
     $dow_array = array(_("So"), _("Mo"), _("Di"), _("Mi"), _("Do"), _("Fr"), _("Sa"));
     $cycles_array = array(_("wöchentlich"), _("zweiwöchentlich"), _("dreiwöchentlich"));
     $cont = array();
     // irregular dates
     $meta = new MetaDate($seminar_id);
     if ($meta->getTurnus() == 1) {
         $cont['REGULAR_DATES']['TURNUS'] = true;
     }
     if ($meta->getStartWoche()) {
         $cont['REGULAR_DATES']['START_WEEK'] = $meta->getStartWoche();
     }
     //$cont['REGULAR_TYPE'] = $GLOBALS['TERMIN_TYP'][$meta->getArt()]['name'];
     $i = 0;
     $cycle_data = $meta->getCycleData();
     foreach ($cycle_data as $metadate_id => $cycle) {
         $cont['REGULAR_DATES']['REGULAR_DATE'][$i] = array('DAY_OF_WEEK' => $dow_array[$cycle['day']], 'START_TIME' => sprintf('%02d:%02d', $cycle['start_hour'], $cycle['start_minute']), 'END_TIME' => sprintf('%02d:%02d', $cycle['end_hour'], $cycle['end_minute']), 'START_WEEK' => $cycle['week_offset'] + 1, 'CYCLE' => $cycles_array[(int) $cycle['cycle']], 'REGULAR_DESCRIPTION' => ExternModule::ExtHtmlReady(trim($cycle['desc'])), 'REGULAR_DELIMITER' => true);
         $k = 0;
         if (Config::get()->RESOURCES_ENABLE) {
             if (($resource_ids = CycleDataDB::getPredominantRoomDB($metadate_id, $start_time, $end_time)) !== false) {
                 foreach ($resource_ids as $resource_id => $foo) {
                     $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['ROOMS'][$k]['ROOM'] = ExternModule::ExtHtmlReady(trim(ResourceObject::Factory($resource_id)->getName()));
                     $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['ROOMS'][$k]['ROOMS_DELIMITER'] = true;
                     $k++;
                 }
                 unset($cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['ROOMS'][$k - 1]['ROOMS_DELIMITER']);
             }
         }
         if (!$k) {
             if (($free_rooms = CycleDataDB::getFreeTextPredominantRoomDB($metadate_id, $start_time, $end_time)) !== false) {
                 foreach ($free_rooms as $free_room => $foo) {
                     $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['FREE_ROOMS'][$k]['FREE_ROOM'] = ExternModule::ExtHtmlReady(trim($free_room));
                     $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['FREE_ROOMS'][$k]['FREE_ROOMS_DELIMITER'] = true;
                     $k++;
                 }
                 unset($cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['FREE_ROOMS'][$k - 1]['FREE_ROOMS_DELIMITER']);
             } else {
                 $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['NO_ROOM'] = true;
             }
         }
         //      if (!$k) {
         //      $cont['REGULAR_DATES']['REGULAR_DATE'][$i]['REGULAR_ROOMS']['NO_FREE_ROOM'] = true;
         //}
         $i++;
     }
     // remove last delimiter
     if ($i) {
         unset($cont['REGULAR_DATES']['REGULAR_DATE'][$i - 1]['REGULAR_DELIMITER']);
     }
     // regular dates
     if ($start_time && $end_time) {
         $dates = SeminarDB::getSingleDates($seminar_id, $start_time, $end_time);
     } else {
         $dates = array();
     }
     $i = 0;
     $selected_types = $this->config->getValue('Main', 'selectedeventtypes');
     foreach ($dates as $date) {
         if (in_array('all', $selected_types) || in_array('meeting', $selected_types) && $GLOBALS['TERMIN_TYP'][$date['date_typ']]['sitzung'] || in_array('other', $selected_types) && !$GLOBALS['TERMIN_TYP'][$date['date_typ']]['sitzung'] || in_array($date['date_typ'], $selected_types)) {
             $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i] = array('DAY_OF_WEEK' => $dow_array[date('w', $date['date'])], 'START_TIME' => date('H:i', $date['date']), 'END_TIME' => date('H:i', $date['end_time']), 'DATE' => date('d.m.y', $date['date']), 'IRREGULAR_DESCRIPTION' => ExternModule::ExtHtmlReady(trim($date['description'])), 'IRREGULAR_DELIMITER' => true);
             if ($GLOBALS['TERMIN_TYP'][$date['date_typ']]['sitzung']) {
                 $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i]['IRREGULAR_TYPE_MEETING'] = $GLOBALS['TERMIN_TYP'][$date['date_typ']]['name'];
             } else {
                 $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i]['IRREGULAR_TYPE_OTHER'] = $GLOBALS['TERMIN_TYP'][$date['date_typ']]['name'];
             }
             if (Config::get()->RESOURCES_ENABLE && $date['resource_id']) {
                 $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i]['IRREGULAR_ROOM'] = ExternModule::ExtHtmlReady(trim(ResourceObject::Factory($date['resource_id'])->getName()));
             } else {
                 if (trim($date['raum'])) {
                     $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i]['IRREGULAR_ROOM'] = ExternModule::ExtHtmlReady(trim($date['raum']));
                 } else {
                     $cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i]['IRREGULAR_NO_ROOM'] = true;
                 }
             }
         }
         $i++;
     }
     // remove last delimiter
     if ($i) {
         unset($cont['IRREGULAR_DATES']['IRREGULAR_DATE'][$i - 1]['IRREGULAR_DELIMITER']);
     }
     return $cont;
 }
Example #3
0
 /**
  * change existing cycledate, changes also corresponding single dates
  *
  * @param array assoc, see CycleData, metadate_id must be in $data['cycle_id']
  * @return number|boolean
  */
 function editCycle($data = array())
 {
     $cycle = $this->cycles[$data['cycle_id']];
     $new_start = mktime((int) $data['start_stunde'], (int) $data['start_minute']);
     $new_end = mktime((int) $data['end_stunde'], (int) $data['end_minute']);
     $old_start = mktime($cycle->getStartStunde(), $cycle->getStartMinute());
     $old_end = mktime($cycle->getEndStunde(), $cycle->getEndMinute());
     if ($new_start >= $old_start && $new_end <= $old_end && $data['day'] == $cycle->day && $data['endWeek'] == $cycle->end_offset) {
         // Zeitraum wurde verkuerzt, Raumbuchungen bleiben erhalten...
         if ($this->setCycleData($data, $cycle)) {
             $termine = $cycle->getSingleDates();
             foreach ($termine as $key => $val) {
                 $tos = $val->getStartTime();
                 $toe = $val->getEndTime();
                 if ($toe > time()) {
                     $t_start = mktime((int) $data['start_stunde'], (int) $data['start_minute'], 0, date('m', $tos), date('d', $tos), date('Y', $tos));
                     $t_end = mktime((int) $data['end_stunde'], (int) $data['end_minute'], 0, date('m', $toe), date('d', $toe), date('Y', $toe));
                     $termine[$key]->setTime($t_start, $t_end);
                     $termine[$key]->store();
                 } else {
                     unset($termine[$key]);
                 }
             }
             $this->sortCycleData();
         }
         return sizeof($termine);
     } else {
         if ($this->setCycleData($data, $cycle)) {
             // collect all existing themes (issues) for this cycle:
             $issues = array();
             $issue_objects = array();
             $singledate_count = 0;
             // loop through the single dates and look for themes (issues)
             $termine = $cycle->getSingleDates();
             foreach ($termine as $key => $termin) {
                 // get all isues of this date ( zero, one, or more, if the expert view is activated)
                 // and store them at the relative position of this single date
                 $issues[$singledate_count] = $termin->getIssueIDs();
                 $singledate_count++;
             }
             // remove all SingleDates in the future for this CycleData
             $count = CycleDataDB::deleteNewerSingleDates($data['cycle_id'], time(), true);
             // create new SingleDates
             $this->createSingleDates(array('metadate_id' => $cycle->getMetaDateId(), 'startAfterTimeStamp' => time()));
             // clear all loaded SingleDates so no odd ones remain. The Seminar-Class will load them fresh when needed
             $cycle->termine = NULL;
             // read all new single dates
             $termine = $cycle->getSingleDates();
             // new dates counter
             $new_singledate_count = 0;
             // loop through the single dates and add the themes (issues)
             foreach ($termine as $key => $termin) {
                 // check, if there are issues for this single date
                 if ($issues[$new_singledate_count] != NULL) {
                     // add all issues:
                     foreach ($issues[$new_singledate_count] as $issue_key => $issue_id) {
                         $termin->addIssueID($issue_id);
                         $termin->store();
                     }
                 }
                 unset($issues[$new_singledate_count]);
                 $new_singledate_count++;
             }
             // delete issues, that are not assigned to a single date because of to few dates
             // (only if the schedule expert view is off)
             if (!Config::get()->RESOURCES_ENABLES_EXPERT_SCHEDULE_VIEW) {
                 if ($new_singledate_count < $singledate_count) {
                     for ($i = $new_singledate_count; $i < $singledate_count; $i++) {
                         if ($issues[$i] != NULL) {
                             foreach ($issues[$i] as $issue_id) {
                                 // delete this issue
                                 IssueDB::deleteIssue($issue_id);
                             }
                         }
                     }
                 }
             }
             $this->sortCycleData();
             return $count;
         }
     }
     return FALSE;
 }
Example #4
0
    /**
     * This function returns an associative array of the dates owned by this seminar
     *
     * @returns  mixed  a multidimensional array of seminar-dates
     */
    public function getUndecoratedData($filter = false)
    {

        // Caching
        $cache = StudipCacheFactory::getCache();
        $cache_key = 'course/undecorated_data/'. $this->id;

        if ($filter) {
            $sub_key = $_SESSION['_language'] .'/'. $this->filterStart .'-'. $this->filterEnd;
        } else {
            $sub_key = $_SESSION['_language'] .'/unfiltered';
        }

        $data = unserialize($cache->read($cache_key));

        // build cache from scratch
        if (!$data || !$data[$sub_key]) {
            $cycles = $this->metadate->getCycleData();
            $dates = $this->getSingleDates($filter, $filter);
            $rooms = array();

            foreach (array_keys($cycles) as $id) {
                $cycles[$id]['first_date'] = CycleDataDB::getFirstDate($id);
                if (!empty($cycles[$id]['assigned_rooms'])) {
                    foreach ($cycles[$id]['assigned_rooms'] as $room_id => $count) {
                        $rooms[$room_id] += $count;
                    }
                }
            }

            // besser wieder mit direktem Query statt Objekten
            if (is_array($cycles) && (sizeof($cycles) == 0)) {
                $cycles = FALSE;
            }

            $ret['regular']['turnus_data'] = $cycles;

            // the irregular single-dates
            foreach ($dates as $val) {
                $zw = array(
                    'metadate_id' => $val->getMetaDateID(),
                    'termin_id'   => $val->getTerminID(),
                    'date_typ'    => $val->getDateType(),
                    'start_time'  => $val->getStartTime(),
                    'end_time'    => $val->getEndTime(),
                    'mkdate'      => $val->getMkDate(),
                    'chdate'      => $val->getMkDate(),
                    'ex_termin'   => $val->isExTermin(),
                    'orig_ex'     => $val->isExTermin(),
                    'range_id'    => $val->getRangeID(),
                    'author_id'   => $val->getAuthorID(),
                    'resource_id' => $val->getResourceID(),
                    'raum'        => $val->getFreeRoomText(),
                    'typ'         => $val->getDateType(),
                    'tostring'    => $val->toString()
                );

                if ($val->getResourceID()) {
                    $rooms[$val->getResourceID()]++;
                }

                $ret['irregular'][$val->getTerminID()] = $zw;
            }

            $ret['rooms'] = $rooms;
            $ret['ort']   = $this->location;

            $data[$sub_key] = $ret;

            // write data to cache
            $cache->write($cache_key, serialize($data), 600);
        }

        return $data[$sub_key];
    }
Example #5
0
    /**
     * returns an assoc array, keys are resource_id of rooms values are number of dates for this room
     * give timestamps as params to filter by time range
     *
     * @param int $filterStart
     * @param int $filterEnd
     * @return array
     */
    function getPredominantRoom($filterStart = 0, $filterEnd = 0)
    {
        if ($rooms = CycleDataDB::getPredominantRoomDB($this->metadate_id, $filterStart, $filterEnd)) {
            return $rooms;
        }

        return false;
    }