/**
  * 
  *
  * @access public
  * @param
  * @return array
  * @static
  */
 public static function lookupNextSessionByCourse($a_ref_id)
 {
     global $tree, $ilDB;
     $sessions = $tree->getChildsByType($a_ref_id, 'sess');
     $obj_ids = array();
     foreach ($sessions as $tree_data) {
         $obj_ids[] = $tree_data['obj_id'];
     }
     if (!count($obj_ids)) {
         return false;
     }
     // Try to read the next sessions within the next 24 hours
     $now = new ilDate(time(), IL_CAL_UNIX);
     $tomorrow = clone $now;
     $tomorrow->increment(IL_CAL_DAY, 2);
     $query = "SELECT event_id FROM event_appointment " . "WHERE e_start > " . $ilDB->quote($now->get(IL_CAL_DATE, 'timestamp')) . ' ' . "AND e_start < " . $ilDB->quote($tomorrow->get(IL_CAL_DATE, 'timestamp')) . ' ' . "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . ' ' . "ORDER BY e_start ";
     $event_ids = array();
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $event_ids[] = $row->event_id;
     }
     if (count($event_ids)) {
         return $event_ids;
     }
     // Alternativ: get next event.
     $query = "SELECT event_id FROM event_appointment " . "WHERE e_start > " . $ilDB->now() . " " . "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . " " . "ORDER BY e_start ";
     $ilDB->setLimit(1);
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $event_id = $row->event_id;
     }
     return isset($event_id) ? array($event_id) : array();
 }
 public function getLuceneSearchString($a_value)
 {
     // see ilADTDateSearchBridgeRange::importFromPost();
     if ($a_value["tgl"]) {
         $start = $end = null;
         if ($a_value["lower"]["date"]) {
             $start = mktime(12, 0, 0, $a_value["lower"]["date"]["m"], $a_value["lower"]["date"]["d"], $a_value["lower"]["date"]["y"]);
         }
         if ($a_value["upper"]["date"]) {
             $end = mktime(12, 0, 0, $a_value["upper"]["date"]["m"], $a_value["upper"]["date"]["d"], $a_value["upper"]["date"]["y"]);
         }
         if ($start && $end && $start > $end) {
             $tmp = $start;
             $start = $end;
             $end = $tmp;
         }
         $start = new ilDate($start, IL_CAL_UNIX);
         $end = new ilDate($end, IL_CAL_UNIX);
         return "{" . $start->get(IL_CAL_DATE) . " TO " . $end->get(IL_CAL_DATE) . "}";
     }
 }
 /**
  * load from json
  *
  * @access public
  * @param object json representation
  * @throws ilException
  */
 public function loadFromJson($a_json)
 {
     global $ilLog;
     if (!is_object($a_json)) {
         $ilLog->write(__METHOD__ . ': Cannot load from JSON. No object given.');
         throw new ilException('Cannot parse ECSContent.');
     }
     $GLOBALS['ilLog']->write(__METHOD__ . ': ' . print_r($a_json, true));
     $this->room = $a_json->room;
     $this->begin = $a_json->begin;
     $this->end = $a_json->end;
     $this->cycle = $a_json->cycle;
     #$this->day = $a_json->day;
     $two = new ilDate('2000-01-02', IL_CAL_DATE);
     if (ilDate::_before(new ilDateTime($this->getUTBegin(), IL_CAL_UNIX), $two)) {
         $this->begin = '';
     }
     if (ilDate::_before(new ilDateTime($this->getUTEnd(), IL_CAL_UNIX), $two)) {
         $this->end = '';
     }
 }
 /**
  * update
  *
  * @access public
  * @return
  */
 public function update()
 {
     global $ilErr, $ilAccess, $tpl, $ilUser;
     // #19997 - see ilObjectListGUI::insertTimingsCommand()
     if (!$ilAccess->checkAccess('write', '', $this->parent_ref_id) && !$ilAccess->checkAccess('write', '', $this->getItemId())) {
         $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
     }
     $this->initFormEdit();
     if ($this->form->checkInput()) {
         include_once "Services/Object/classes/class.ilObjectActivation.php";
         $activation = new ilObjectActivation();
         $activation->setTimingType($this->form->getInput('timing_type'));
         $date = $this->form->getInput('timing_start');
         $date = new ilDateTime($date['date'] . ' ' . $date['time'], IL_CAL_DATETIME, $ilUser->getTimeZone());
         $activation->setTimingStart($date->get(IL_CAL_UNIX));
         $date = $this->form->getInput('timing_end');
         $date = new ilDateTime($date['date'] . ' ' . $date['time'], IL_CAL_DATETIME, $ilUser->getTimeZone());
         $activation->setTimingEnd($date->get(IL_CAL_UNIX));
         $date = $this->form->getInput('sug_start');
         $date = new ilDate($date['date'], IL_CAL_DATE);
         $activation->setSuggestionStart($date->get(IL_CAL_UNIX));
         $date = $this->form->getInput('sug_end');
         $date = new ilDate($date['date'], IL_CAL_DATE);
         $activation->setSuggestionEnd($date->get(IL_CAL_UNIX));
         $date = $this->form->getInput('early_start');
         $date = new ilDate($date['date'], IL_CAL_DATE);
         $activation->setEarliestStart($date->get(IL_CAL_UNIX));
         $date = $this->form->getInput('late_end');
         $date = new ilDate($date['date'], IL_CAL_DATE);
         $activation->setLatestEnd($date->get(IL_CAL_UNIX));
         $activation->toggleVisible((bool) $this->form->getInput('visible'));
         $activation->toggleChangeable((bool) $this->form->getInput('changeable'));
         if (!$activation->validateActivation()) {
             ilUtil::sendFailure($ilErr->getMessage());
             $this->form->setValuesByPost();
             $tpl->setContent($this->form->getHTML());
             return false;
         } else {
             $activation->update($this->getItemId());
             ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
             $this->ctrl->redirect($this, "edit");
         }
     } else {
         $this->form->setValuesByPost();
         $tpl->setContent($this->form->getHTML());
     }
 }
 public function checkReminder()
 {
     global $ilDB, $ilAccess;
     $now = time();
     $today = date("Y-m-d");
     // object settings / participation period
     if ($this->isOffline() || !$this->getReminderStatus() || $this->getStartDate() && $now < $this->getStartDate() || $this->getEndDate() && $now > $this->getEndDate()) {
         return false;
     }
     // reminder period
     $start = $this->getReminderStart();
     if ($start) {
         $start = $start->get(IL_CAL_DATE);
     }
     $end = $this->getReminderEnd();
     if ($end) {
         $end = $end->get(IL_CAL_DATE);
     }
     if ($today < $start || $end && $today > $end) {
         return false;
     }
     // object access period
     include_once "Services/Object/classes/class.ilObjectActivation.php";
     $item_data = ilObjectActivation::getItem($this->getRefId());
     if ($item_data["timing_type"] == ilObjectActivation::TIMINGS_ACTIVATION && ($now < $item_data["timing_start"] || $now > $item_data["timing_end"])) {
         return false;
     }
     // check frequency
     $cut = new ilDate($today, IL_CAL_DATE);
     $cut->increment(IL_CAL_DAY, $this->getReminderFrequency() * -1);
     if (!$this->getReminderLastSent() || $cut->get(IL_CAL_DATE) >= substr($this->getReminderLastSent(), 0, 10)) {
         $user_ids = $this->getNotificationTargetUserIds();
         if ($user_ids) {
             // gather participants who already finished
             $finished_ids = array();
             $set = $ilDB->query("SELECT user_fi FROM svy_finished" . " WHERE survey_fi = " . $ilDB->quote($this->getSurveyId(), "integer") . " AND state = " . $ilDB->quote(1, "text") . " AND " . $ilDB->in("user_fi", $user_ids, "", "integer"));
             while ($row = $ilDB->fetchAssoc($set)) {
                 $finished_ids[] = $row["user_fi"];
             }
             // some users missing out?
             $missing_ids = array_diff($user_ids, $finished_ids);
             if ($missing_ids) {
                 foreach ($missing_ids as $idx => $user_id) {
                     // should be able to participate
                     if (!$ilAccess->checkAccessOfUser($user_id, "read", "", $this->getRefId(), "svy", $this->getId())) {
                         unset($missing_ids[$idx]);
                     }
                 }
             }
             if ($missing_ids) {
                 $this->sentReminder($missing_ids);
             }
         }
         $this->setReminderLastSent($today);
         $this->saveToDb();
         return true;
     }
     return false;
 }
 /**
  * init initial date
  * @param ilDate $initialDate
  */
 protected function initInitialDate(ilDate $initialDate)
 {
     if (!isset($_GET['hour'])) {
         $this->initialDate = clone $initialDate;
         $this->default_fulltime = true;
     } else {
         if ((int) $_GET['hour'] < 10) {
             $time = '0' . (int) $_GET['hour'] . ':00:00';
         } else {
             $time = (int) $_GET['hour'] . ':00:00';
         }
         $this->initialDate = new ilDateTime($initialDate->get(IL_CAL_DATE) . ' ' . $time, IL_CAL_DATETIME, $this->timezone);
         $this->default_fulltime = false;
     }
 }
Example #7
0
 /**
  * Generate Calendar Entries
  *
  * @param
  * @return
  */
 function generateCalendarEntries($a_num_per_course = 10)
 {
     include_once "./Services/Calendar/classes/class.ilDateTime.php";
     include_once "./Services/Calendar/classes/class.ilCalendarEntry.php";
     include_once "./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php";
     include_once "./Services/Calendar/classes/class.ilCalendarCategories.php";
     $this->log("Creating Calendar Entries");
     $crs_ref_ids = ilUtil::_getObjectsByOperations("crs", "read", 0, $limit = 1000000);
     $cnt = 1;
     foreach ($crs_ref_ids as $rid) {
         $obj_id = ilObject::_lookupObjId($rid);
         $cat_id = ilCalendarCategories::_lookupCategoryIdByObjId($obj_id);
         $start = new ilDate(time(), IL_CAL_UNIX);
         $end = new ilDate(time(), IL_CAL_UNIX);
         $end->increment(IL_CAL_HOUR, 2);
         for ($i = 1; $i <= $a_num_per_course; $i++) {
             $this->log("Event " . $cnt);
             $entry = new ilCalendarEntry();
             $entry->setStart($start);
             //ilDateTiem
             $entry->setEnd($end);
             //ilDateTiem
             $entry->setFullday(false);
             //ilDateTiem
             $entry->setTitle("Event " . $cnt);
             //ilDateTiem
             $entry->save();
             $id = $entry->getEntryId();
             $ass = new ilCalendarCategoryAssignments($id);
             $ass->addAssignment($cat_id);
             $start->increment(IL_CAL_DAY, 1);
             $end->increment(IL_CAL_DAY, 1);
             //echo "-$cat_id-";
             //echo "+".ilDatePresentation::formatDate($start)."+";
             $cnt++;
         }
     }
 }
Example #8
0
 public static function handleDeletedGroups()
 {
     global $ilDB;
     $query = 'SELECT child, obd.obj_id FROM tree ' . 'JOIN object_reference obr ON child = ref_id ' . 'JOIN object_data obd ON obr.obj_id = obd.obj_id ' . 'WHERE type = ' . $ilDB->quote('xvit', 'text') . ' ' . 'AND tree < ' . $ilDB->quote(0, 'integer');
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         if (!ilObject::_hasUntrashedReference($row->obj_id)) {
             try {
                 $vgroup_id = ilObjVitero::lookupVGroupId($row->obj_id);
                 if (!$vgroup_id) {
                     continue;
                 }
                 $start = new ilDate(time(), IL_CAL_UNIX);
                 $end = clone $start;
                 $start->increment(IL_CAL_YEAR, -2);
                 $end->increment(IL_CAL_YEAR, 2);
                 $booking_service = new ilViteroBookingSoapConnector();
                 $books = $booking_service->getByGroupAndDate($vgroup_id, $start, $end);
                 if (is_object($books->booking)) {
                     try {
                         $booking_service->deleteBooking($books->booking->bookingid);
                     } catch (ilViteroConnectorException $e) {
                         $GLOBALS['ilLog']->write(__METHOD__ . ': Deleting deprecated booking failed with message: ' . $e->getMessage());
                     }
                 }
                 if (is_array($books->booking)) {
                     foreach ((array) $books->booking as $book) {
                         try {
                             $booking_service->deleteBooking($book->bookingid);
                         } catch (ilViteroConnectorException $e) {
                             $GLOBALS['ilLog']->write(__METHOD__ . ': Deleting deprecated booking failed with message: ' . $e->getMessage());
                         }
                     }
                 }
             } catch (ilViteroConnectorException $e) {
                 $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read bookings of group "' . $vgroup_id . '": ' . $e->getMessage());
             }
         }
         // Delete group
         try {
             $groups = new ilViteroGroupSoapConnector();
             $groupDefinition = new ilViteroGroupSoap();
             $groupDefinition->groupid = $vgroup_id;
             $groups->delete($groupDefinition);
             // Update vgroup id
             $query = 'UPDATE rep_robj_xvit_data ' . 'SET vgroup_id = 0 ' . 'WHERE obj_id = ' . $ilDB->quote($row->obj_id, 'integer');
             $ilDB->manipulate($query);
         } catch (ilViteroConnectorException $e) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Delete group failed: "' . $vgroup_id . '": ' . $e->getMessage());
         }
     }
 }
 /**
  * Events List CSV Export
  *
  * @access public
  * @param
  * 
  */
 public function exportCSV()
 {
     global $tree, $ilAccess;
     include_once 'Services/Utilities/classes/class.ilCSVWriter.php';
     include_once 'Modules/Session/classes/class.ilEventParticipants.php';
     $members = $this->members_obj->getParticipants();
     $members = ilUtil::_sortIds($members, 'usr_data', 'lastname', 'usr_id');
     $events = array();
     foreach ($tree->getSubtree($tree->getNodeData($this->course_ref_id), false, 'sess') as $event_id) {
         $tmp_event = ilObjectFactory::getInstanceByRefId($event_id, false);
         if (!is_object($tmp_event) or !$ilAccess->checkAccess('write', '', $event_id)) {
             continue;
         }
         $events[] = $tmp_event;
     }
     $this->csv = new ilCSVWriter();
     $this->csv->addColumn($this->lng->txt("lastname"));
     $this->csv->addColumn($this->lng->txt("firstname"));
     $this->csv->addColumn($this->lng->txt("login"));
     foreach ($events as $event_obj) {
         // TODO: do not export relative dates
         $this->csv->addColumn($event_obj->getTitle() . ' (' . $event_obj->getFirstAppointment()->appointmentToString() . ')');
     }
     $this->csv->addRow();
     foreach ($members as $user_id) {
         $name = ilObjUser::_lookupName($user_id);
         $this->csv->addColumn($name['lastname']);
         $this->csv->addColumn($name['firstname']);
         $this->csv->addColumn(ilObjUser::_lookupLogin($user_id));
         foreach ($events as $event_obj) {
             $event_part = new ilEventParticipants((int) $event_obj->getId());
             $this->csv->addColumn($event_part->hasParticipated($user_id) ? $this->lng->txt('event_participated') : $this->lng->txt('event_not_participated'));
         }
         $this->csv->addRow();
     }
     $date = new ilDate(time(), IL_CAL_UNIX);
     ilUtil::deliverData($this->csv->getCSVString(), $date->get(IL_CAL_FKT_DATE, 'Y-m-d') . "_course_events.csv", "text/csv");
 }
Example #10
0
 function setBirthday($a_birthday)
 {
     if (strlen($a_birthday)) {
         $date = new ilDate($a_birthday, IL_CAL_DATE);
         $this->birthday = $date->get(IL_CAL_DATE);
     } else {
         $this->birthday = null;
     }
 }
 /**
  * get a list of month days
  *
  * @access protected
  * @param
  * @return
  */
 protected function getMonthWeekDays($year, $month)
 {
     static $month_days = array();
     if (isset($month_days[$year][$month])) {
         return $month_days[$year][$month];
     }
     $month_str = $month < 10 ? '0' . $month : $month;
     $begin_month = new ilDate($year . '-' . $month_str . '-01', IL_CAL_DATE);
     $begin_month_info = $begin_month->get(IL_CAL_FKT_GETDATE);
     $days = array(0 => 'SU', 1 => 'MO', 2 => 'TU', 3 => 'WE', 4 => 'TH', 5 => 'FR', 6 => 'SA');
     for ($i = 0; $i < $begin_month_info['wday']; $i++) {
         next($days);
     }
     for ($i = $begin_month_info['yday']; $i < $begin_month_info['yday'] + ilCalendarUtil::_getMaxDayOfMonth($year, $month); $i++) {
         if (($current_day = current($days)) == false) {
             $current_day = reset($days);
         }
         $month_days[$year][$month][$current_day][] = $i;
         next($days);
     }
     return $month_days[$year][$month];
 }
 /**
  * Check input, strip slashes etc. set alert, if input is not ok.
  *
  * @return	boolean		Input ok, true/false
  */
 public function checkInput()
 {
     global $lng, $ilUser;
     if ($this->getDisabled()) {
         return true;
     }
     $ok = true;
     // Start
     $_POST[$this->getPostVar()]['start']["date"]["y"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["y"]);
     $_POST[$this->getPostVar()]['start']["date"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["m"]);
     $_POST[$this->getPostVar()]['start']["date"]["d"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["d"]);
     $_POST[$this->getPostVar()]['start']["time"]["h"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["h"]);
     $_POST[$this->getPostVar()]['start']["time"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["m"]);
     $_POST[$this->getPostVar()]['start']["time"]["s"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["s"]);
     // verify date
     $dt['year'] = (int) $_POST[$this->getPostVar()]['start']['date']['y'];
     $dt['mon'] = (int) $_POST[$this->getPostVar()]['start']['date']['m'];
     $dt['mday'] = (int) $_POST[$this->getPostVar()]['start']['date']['d'];
     $dt['hours'] = (int) $_POST[$this->getPostVar()]['start']['time']['h'];
     $dt['minutes'] = (int) $_POST[$this->getPostVar()]['start']['time']['m'];
     $dt['seconds'] = (int) $_POST[$this->getPostVar()]['start']['time']['s'];
     if ($this->getShowTime()) {
         $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE, $ilUser->getTimeZone());
     } else {
         $date = new ilDate($dt, IL_CAL_FKT_GETDATE);
     }
     if ($_POST[$this->getPostVar()]['start']["date"]["d"] != $date->get(IL_CAL_FKT_DATE, 'd', $ilUser->getTimeZone()) || $_POST[$this->getPostVar()]['start']["date"]["m"] != $date->get(IL_CAL_FKT_DATE, 'm', $ilUser->getTimeZone()) || $_POST[$this->getPostVar()]['start']["date"]["y"] != $date->get(IL_CAL_FKT_DATE, 'Y', $ilUser->getTimeZone())) {
         // #11847
         $this->invalid_input['start'] = $_POST[$this->getPostVar()]['start']["date"];
         $this->setAlert($lng->txt("exc_date_not_valid"));
         $ok = false;
     }
     #$_POST[$this->getPostVar()]['start']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
     #$_POST[$this->getPostVar()]['start']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
     $this->setStart($date);
     // End
     $_POST[$this->getPostVar()]['end']["date"]["y"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["y"]);
     $_POST[$this->getPostVar()]['end']["date"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["m"]);
     $_POST[$this->getPostVar()]['end']["date"]["d"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["d"]);
     $_POST[$this->getPostVar()]['end']["time"]["h"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["h"]);
     $_POST[$this->getPostVar()]['end']["time"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["m"]);
     $_POST[$this->getPostVar()]['end']["time"]["s"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["s"]);
     // verify date
     $dt['year'] = (int) $_POST[$this->getPostVar()]['end']['date']['y'];
     $dt['mon'] = (int) $_POST[$this->getPostVar()]['end']['date']['m'];
     $dt['mday'] = (int) $_POST[$this->getPostVar()]['end']['date']['d'];
     $dt['hours'] = (int) $_POST[$this->getPostVar()]['end']['time']['h'];
     $dt['minutes'] = (int) $_POST[$this->getPostVar()]['end']['time']['m'];
     $dt['seconds'] = (int) $_POST[$this->getPostVar()]['end']['time']['s'];
     if ($this->getShowTime()) {
         $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE, $ilUser->getTimeZone());
     } else {
         $date = new ilDate($dt, IL_CAL_FKT_GETDATE);
     }
     if ($_POST[$this->getPostVar()]['end']["date"]["d"] != $date->get(IL_CAL_FKT_DATE, 'd', $ilUser->getTimeZone()) || $_POST[$this->getPostVar()]['end']["date"]["m"] != $date->get(IL_CAL_FKT_DATE, 'm', $ilUser->getTimeZone()) || $_POST[$this->getPostVar()]['end']["date"]["y"] != $date->get(IL_CAL_FKT_DATE, 'Y', $ilUser->getTimeZone())) {
         $this->invalid_input['end'] = $_POST[$this->getPostVar()]['end']["date"];
         $this->setAlert($lng->txt("exc_date_not_valid"));
         $ok = false;
     }
     #$_POST[$this->getPostVar()]['end']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
     #$_POST[$this->getPostVar()]['end']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
     $this->setEnd($date);
     return $ok;
 }
 /**
  * Load values from post
  *
  * @access public
  * 
  */
 public function loadFromPost()
 {
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php';
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     if (!isset($_POST['md'])) {
         return false;
     }
     foreach ($_POST['md'] as $field_id => $value) {
         $def = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($field_id);
         switch ($def->getFieldType()) {
             case ilAdvancedMDFieldDefinition::TYPE_DATE:
                 if (is_array($value) and $_POST['md_activated'][$field_id]) {
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) 0;
                     $dt['minutes'] = (int) 0;
                     $dt['seconds'] = (int) 0;
                     $date = new ilDate($dt, IL_CAL_FKT_GETDATE);
                     $value = $date->get(IL_CAL_UNIX);
                 } else {
                     $value = 0;
                 }
                 break;
             case ilAdvancedMDFieldDefinition::TYPE_DATETIME:
                 if (is_array($value) and $_POST['md_activated'][$field_id]) {
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) $value['time']['h'];
                     $dt['minutes'] = (int) $value['time']['m'];
                     $dt['seconds'] = (int) 0;
                     $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE);
                     $value = $date->get(IL_CAL_UNIX);
                 } else {
                     $value = 0;
                 }
                 break;
             default:
                 $value = ilUtil::stripSlashes($value);
                 break;
         }
         $val = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
         $val->setValue($value);
         $this->values[] = $val;
         unset($value);
     }
     $this->loadECSDurationPost();
 }
 /**
  * Returns a list of survey codes for file export
  *
  * @param array $a_array An array of all survey codes that should be exported
  * @return string A comma separated list of survey codes an URLs for file export
  * @access public
  */
 function getSurveyCodesForExport($a_array)
 {
     global $ilDB, $ilUser;
     $result = $ilDB->queryF("SELECT svy_anonymous.*, svy_finished.state FROM svy_anonymous " . "LEFT JOIN svy_finished ON svy_anonymous.survey_key = svy_finished.anonymous_id " . "WHERE svy_anonymous.survey_fi = %s AND svy_anonymous.user_key IS NULL", array('integer'), array($this->getSurveyId()));
     $export = "";
     $default_lang = $ilUser->getPref("survey_code_language");
     $lang = strlen($default_lang) ? "&lang=" . $default_lang : "";
     while ($row = $ilDB->fetchAssoc($result)) {
         if (in_array($row["survey_key"], $a_array) || count($a_array) == 0) {
             $export .= $row["survey_key"] . ",";
             // No relative (today, tomorrow...) dates in export.
             $date = new ilDate($row['tstamp'], IL_CAL_UNIX);
             $created = $date->get(IL_CAL_DATE);
             $export .= "{$created},";
             if ($this->isSurveyCodeUsed($row["survey_key"])) {
                 $export .= "1,";
             } else {
                 $export .= "0,";
             }
             $url = ILIAS_HTTP_PATH . "/goto.php?cmd=infoScreen&target=svy_" . $this->getRefId() . "&client_id=" . CLIENT_ID . "&accesscode=" . $row["survey_key"] . $lang;
             $export .= $url . "\n";
         }
     }
     return $export;
 }
 /**
  * init period of events
  *
  * @access protected
  * @param ilDate seed
  * @return
  */
 protected function initPeriod(ilDate $seed)
 {
     switch ($this->type) {
         case self::TYPE_DAY:
             $this->start = clone $seed;
             $this->end = clone $seed;
             $this->start->increment(IL_CAL_DAY, -2);
             $this->end->increment(IL_CAL_DAY, 2);
             break;
         case self::TYPE_WEEK:
             $this->start = clone $seed;
             $start_info = $this->start->get(IL_CAL_FKT_GETDATE, '', 'UTC');
             $day_diff = $this->weekstart - $start_info['isoday'];
             if ($day_diff == 7) {
                 $day_diff = 0;
             }
             $this->start->increment(IL_CAL_DAY, $day_diff);
             $this->start->increment(IL_CAL_DAY, -1);
             $this->end = clone $this->start;
             $this->end->increment(IL_CAL_DAY, 9);
             break;
         case self::TYPE_MONTH:
             $year_month = $seed->get(IL_CAL_FKT_DATE, 'Y-m', 'UTC');
             list($year, $month) = explode('-', $year_month);
             $this->start = new ilDate($year_month . '-01', IL_CAL_DATE);
             $this->start->increment(IL_CAL_DAY, -6);
             $this->end = new ilDate($year_month . '-' . ilCalendarUtil::_getMaxDayOfMonth($year, $month), IL_CAL_DATE);
             $this->end->increment(IL_CAL_DAY, 6);
             break;
         case self::TYPE_INBOX:
             $this->start = $seed;
             $this->end = clone $this->start;
             $this->end->increment(IL_CAL_MONTH, 3);
             break;
     }
     return true;
 }
 /** 
  * Called from ilLuceneAdvancedQueryParser
  * Parse a field specific query
  */
 public function parseFieldQuery($a_field, $a_query)
 {
     switch ($a_field) {
         case 'lom_content':
             return $a_query;
         case 'general_offline':
             switch ($a_query) {
                 case self::OFFLINE_QUERY:
                     return 'offline:1';
                 default:
                     return '-offline:1';
             }
             return '';
             // General
         // General
         case 'lom_language':
             return 'lomLanguage:' . $a_query;
         case 'lom_keyword':
             return 'lomKeyword:' . $a_query;
         case 'lom_coverage':
             return 'lomCoverage:' . $a_query;
         case 'lom_structure':
             return 'lomStructure:' . $a_query;
             // Lifecycle
         // Lifecycle
         case 'lom_status':
             return 'lomStatus:' . $a_query;
         case 'lom_version':
             return 'lomVersion:' . $a_query;
             // Begin Contribute
         // Begin Contribute
         case 'lom_role':
             return 'lomRole:' . $a_query;
         case 'lom_role_entry':
             return 'lomRoleEntity:' . $a_query;
             // End contribute
             // Technical
         // End contribute
         // Technical
         case 'lom_format':
             return 'lomFormat:' . $a_query;
         case 'lom_operating_system':
             return 'lomOS:' . $a_query;
         case 'lom_browser':
             return 'lomBrowser:' . $a_query;
             // Educational
         // Educational
         case 'lom_interactivity':
             return 'lomInteractivity:' . $a_query;
         case 'lom_resource':
             return 'lomResource:' . $a_query;
         case 'lom_level_start':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getInteractivityLevelSelect(0, 'lom_level', array(), true);
             for ($i = $a_query; $i <= count($options); $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomLevel:"' . $options[$i] . '" ';
             }
             return $q_string;
         case 'lom_level_end':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getInteractivityLevelSelect(0, 'lom_level', array(), true);
             for ($i = 1; $i <= $a_query; $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomLevel:"' . $options[$i] . '" ';
             }
             return $q_string;
         case 'lom_density_start':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getSemanticDensitySelect(0, 'lom_density', array(), true);
             for ($i = $a_query; $i <= count($options); $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomDensity:"' . $options[$i] . '" ';
             }
             return $q_string;
         case 'lom_density_end':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getSemanticDensitySelect(0, 'lom_density', array(), true);
             for ($i = 1; $i <= $a_query; $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomDensity:"' . $options[$i] . '" ';
             }
             return $q_string;
         case 'lom_user_role':
             return 'lomUserRole:' . $a_query;
         case 'lom_context':
             return 'lomContext:' . $a_query;
         case 'lom_difficulty_start':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getDifficultySelect(0, 'lom_difficulty', array(), true);
             for ($i = $a_query; $i <= count($options); $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomDifficulty:"' . $options[$i] . '" ';
             }
             return $q_string;
         case 'lom_difficulty_end':
             $q_string = '';
             include_once './Services/MetaData/classes/class.ilMDUtilSelect.php';
             $options = ilMDUtilSelect::_getDifficultySelect(0, 'lom_difficulty', array(), true);
             for ($i = 1; $i <= $a_query; $i++) {
                 if (strlen($q_string)) {
                     $q_string .= 'OR ';
                 }
                 $q_string .= 'lomDifficulty:"' . $options[$i] . '" ';
             }
             return $q_string;
             // Rights
         // Rights
         case 'lom_costs':
             return 'lomCosts:' . $a_query;
         case 'lom_copyright':
             return 'lomCopyright:' . $a_query;
             // Classification
         // Classification
         case 'lom_purpose':
             return 'lomPurpose:' . $a_query;
         case 'lom_taxon':
             return 'lomTaxon:' . $a_query;
         default:
             if (substr($a_field, 0, 3) != 'adv') {
                 break;
             }
             // Advanced meta data
             $field_id = substr($a_field, 4);
             include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
             $field = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($field_id);
             switch ($field->getFieldType()) {
                 case ilAdvancedMDFieldDefinition::TYPE_TEXT:
                 case ilAdvancedMDFieldDefinition::TYPE_SELECT:
                     return 'advancedMetaData_' . $field_id . ':' . $a_query;
                 case ilAdvancedMDFieldDefinition::TYPE_DATE:
                     $value = $_POST['adv_' . $field_id . '_start'];
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) 0;
                     $dt['minutes'] = (int) 0;
                     $dt['seconds'] = (int) 0;
                     $date = new ilDate($dt, IL_CAL_FKT_GETDATE);
                     $ustart = $date->get(IL_CAL_UNIX);
                     $value = $_POST['adv_' . $field_id . '_end'];
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) 0;
                     $dt['minutes'] = (int) 0;
                     $dt['seconds'] = (int) 0;
                     $date = new ilDate($dt, IL_CAL_FKT_GETDATE);
                     $uend = $date->get(IL_CAL_UNIX);
                     return 'advancedMetaData_' . $field_id . ':{' . $ustart . ' TO ' . $uend . '}';
                 case ilAdvancedMDFieldDefinition::TYPE_DATETIME:
                     $value = $_POST['adv_' . $field_id . '_start'];
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) $value['time']['h'];
                     $dt['minutes'] = (int) $value['time']['m'];
                     $dt['seconds'] = (int) 0;
                     $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE);
                     $ustart = $date->get(IL_CAL_UNIX);
                     $value = $_POST['adv_' . $field_id . '_end'];
                     $dt['year'] = (int) $value['date']['y'];
                     $dt['mon'] = (int) $value['date']['m'];
                     $dt['mday'] = (int) $value['date']['d'];
                     $dt['hours'] = (int) $value['time']['h'];
                     $dt['minutes'] = (int) $value['time']['m'];
                     $dt['seconds'] = (int) 0;
                     $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE);
                     $uend = $date->get(IL_CAL_UNIX);
                     return 'advancedMetaData_' . $field_id . ':{' . $ustart . ' TO ' . $uend . '}';
             }
             break;
     }
 }
 /**
  * Build a month day list
  *
  * @access public
  * @param int month
  * @param int year
  * @param int weekstart (0 => Sunday,1 => Monday)
  * @return ilDateList
  * 
  */
 public static function _buildMonthDayList($a_month, $a_year, $weekstart)
 {
     include_once 'Services/Calendar/classes/class.ilDateList.php';
     $day_list = new ilDateList(ilDateList::TYPE_DATE);
     $prev_month = $a_month == 1 ? 12 : $a_month - 1;
     $prev_year = $prev_month == 12 ? $a_year - 1 : $a_year;
     $next_month = $a_month == 12 ? 1 : $a_month + 1;
     $next_year = $a_month == 12 ? $a_year + 1 : $a_year;
     $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month);
     $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month);
     $week_day['year'] = $a_year;
     $week_day['mon'] = $a_month;
     $week_day['mday'] = 1;
     $week_day['hours'] = 0;
     $week_day['minutes'] = 0;
     $week_day = new ilDate($week_day, IL_CAL_FKT_GETDATE);
     $weekday = $week_day->get(IL_CAL_FKT_DATE, 'w');
     $first_day_offset = $weekday - $weekstart < 0 ? 6 : $weekday - $weekstart;
     for ($i = 0; $i < 42; $i++) {
         if ($i < $first_day_offset) {
             $day = $days_in_prev_month - $first_day_offset + $i + 1;
             $day_list->add(new ilDate(gmmktime(0, 0, 0, $prev_month, $days_in_prev_month - $first_day_offset + $i + 1, $prev_year), IL_CAL_UNIX));
         } elseif ($i < $days_in_month + $first_day_offset) {
             $day = $i - $first_day_offset + 1;
             $day_list->add(new ilDate(gmmktime(0, 0, 0, $a_month, $i - $first_day_offset + 1, $a_year), IL_CAL_UNIX));
         } else {
             $day = $i - $days_in_month - $first_day_offset + 1;
             $day_list->add(new ilDate(gmmktime(0, 0, 0, $next_month, $i - $days_in_month - $first_day_offset + 1, $next_year), IL_CAL_UNIX));
         }
         if ($i == 34 and ($day < 15 or $day == $days_in_month)) {
             break;
         }
     }
     return $day_list;
 }
Example #18
0
 /**
  * write a new event
  *
  * @access protected
  */
 protected function writeEvent()
 {
     $entry = new ilCalendarEntry();
     // Search for summary
     foreach ($this->getContainer()->getItemsByName('SUMMARY', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setTitle($this->purgeString($item->getValue()));
             break;
         }
     }
     // Search description
     foreach ($this->getContainer()->getItemsByName('DESCRIPTION', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setDescription($this->purgeString($item->getValue()));
             break;
         }
     }
     // Search location
     foreach ($this->getContainer()->getItemsByName('LOCATION', false) as $item) {
         if (is_a($item, 'ilICalProperty')) {
             $entry->setLocation($this->purgeString($item->getValue()));
             break;
         }
     }
     foreach ($this->getContainer()->getItemsByName('DTSTART') as $start) {
         $fullday = false;
         foreach ($start->getItemsByName('VALUE') as $type) {
             if ($type->getValue() == 'DATE') {
                 $fullday = true;
             }
         }
         $start_tz = $this->default_timezone;
         foreach ($start->getItemsByName('TZID') as $param) {
             $start_tz = $this->getTZ($param->getValue());
         }
         if ($fullday) {
             $start = new ilDate($start->getValue(), IL_CAL_DATE);
         } else {
             $start = new ilDateTime($start->getValue(), IL_CAL_DATETIME, $start_tz->getIdentifier());
         }
         $entry->setStart($start);
         $entry->setFullday($fullday);
     }
     foreach ($this->getContainer()->getItemsByName('DTEND') as $end) {
         $fullday = false;
         foreach ($end->getItemsByName('VALUE') as $type) {
             if ($type->getValue() == 'DATE') {
                 $fullday = true;
             }
         }
         $end_tz = $this->default_timezone;
         foreach ($end->getItemsByName('TZID') as $param) {
             $end_tz = $this->getTZ($param->getValue());
         }
         if ($fullday) {
             $end = new ilDate($end->getValue(), IL_CAL_DATE);
             $end->increment(IL_CAL_DAY, -1);
         } else {
             $end = new ilDateTime($end->getValue(), IL_CAL_DATETIME, $end_tz->getIdentifier());
         }
         $entry->setEnd($end);
         $entry->setFullday($fullday);
     }
     // save calendar event
     if ($this->category->getLocationType() == ilCalendarCategory::LTYPE_REMOTE) {
         $entry->setAutoGenerated(true);
     }
     $entry->save();
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     $ass = new ilCalendarCategoryAssignments($entry->getEntryId());
     $ass->addAssignment($this->category->getCategoryID());
     // Recurrences
     foreach ($this->getContainer()->getItemsByName('RRULE') as $recurrence) {
         #var_dump("<pre>",$recurrence,"</pre>");
         include_once './Services/Calendar/classes/class.ilCalendarRecurrence.php';
         $rec = new ilCalendarRecurrence();
         $rec->setEntryId($entry->getEntryId());
         foreach ($recurrence->getItemsByName('FREQ') as $freq) {
             switch ($freq->getValue()) {
                 case 'DAILY':
                 case 'WEEKLY':
                 case 'MONTHLY':
                 case 'YEARLY':
                     $rec->setFrequenceType((string) $freq->getValue());
                     break;
                 default:
                     $this->log->write(__METHOD__ . ': Cannot handle recurring event of type: ' . $freq->getValue());
                     break 3;
             }
         }
         foreach ($recurrence->getItemsByName('COUNT') as $value) {
             $rec->setFrequenceUntilCount((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('UNTIL') as $until) {
             $rec->setFrequenceUntilDate(new ilDate($until->getValue(), IL_CAL_DATE));
             break;
         }
         foreach ($recurrence->getItemsByName('INTERVAL') as $value) {
             $rec->setInterval((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYDAY') as $value) {
             $rec->setBYDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYWEEKNO') as $value) {
             $rec->setBYWEEKNO((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYMONTH') as $value) {
             $rec->setBYMONTH((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYMONTHDAY') as $value) {
             $rec->setBYMONTHDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYYEARDAY') as $value) {
             $rec->setBYYEARDAY((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('BYSETPOS') as $value) {
             $rec->setBYSETPOS((string) $value->getValue());
             break;
         }
         foreach ($recurrence->getItemsByName('WKST') as $value) {
             $rec->setWeekstart((string) $value->getValue());
             break;
         }
         $rec->save();
     }
 }