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; }
/** * 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++; } } }
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()); } } }
/** * get new/changed events * * @param bool $a_include_subitem_calendars E.g include session calendars of courses. * @return object $events[] Array of changed events * @access protected * @return */ public function getChangedEvents($a_include_subitem_calendars = false) { global $ilDB; include_once './Services/Calendar/classes/class.ilCalendarCategories.php'; $cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($a_include_subitem_calendars); $cats = $this->hidden_cat->filterHidden($cats, ilCalendarCategories::_getInstance($this->user->getId())->getCategoriesInfo()); if (!count($cats)) { return array(); } $start = new ilDate(date('Y-m-d', time()), IL_CAL_DATE); $start->increment(IL_CAL_MONTH, -1); $query = "SELECT ce.cal_id cal_id FROM cal_entries ce " . "JOIN cal_cat_assignments ca ON ca.cal_id = ce.cal_id " . "WHERE last_update > " . $ilDB->quote($start->get(IL_CAL_DATETIME), 'timestamp') . " " . "AND " . $ilDB->in('ca.cat_id', $cats, false, 'integer') . ' ' . "ORDER BY last_update"; $res = $this->db->query($query); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { if (!$this->hidden_cat->isAppointmentVisible($row->cal_id)) { $events[] = new ilCalendarEntry($row->cal_id); } } return $events ? $events : array(); }
/** * 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(); } }