示例#1
0
 public static function loadByRepeatId($rp_id)
 {
     $db = JFactory::getDBO();
     $sql = "SELECT * FROM #__jevents_exception WHERE rp_id=" . intval($rp_id);
     $db->setQuery($sql);
     $data = $db->loadObject();
     if (!$data || is_null($data)) {
         return false;
     } else {
         $exception = new iCalException($db);
         $exception->bind(get_object_vars($data));
         return $exception;
     }
 }
示例#2
0
 function _deleteFuture()
 {
     $cid = JRequest::getVar('cid', array(0));
     if (!is_array($cid)) {
         $cid = array(intval($cid));
     }
     JArrayHelper::toInteger($cid);
     $db = JFactory::getDBO();
     foreach ($cid as $id) {
         // I should be able to do this in one operation but that can come later
         $event = $this->queryModel->listEventsById(intval($id), 1, "icaldb");
         if (!JEVHelper::canDeleteEvent($event)) {
             throw new Exception(JText::_('ALERTNOTAUTH'), 403);
             return false;
         }
         $query = "SELECT * FROM #__jevents_repetition WHERE rp_id={$id}";
         $db->setQuery($query);
         $repeatdata = null;
         $repeatdata = $db->loadObject();
         if (is_null($repeatdata)) {
             throw new Exception(JText::_('NO_SUCH_EVENT'), 4777);
             return;
         }
         $query = "SELECT detail_id FROM #__jevents_vevent WHERE ev_id={$repeatdata->eventid}";
         $db->setQuery($query);
         $eventdetailid = $db->loadResult();
         // Find detail ids for future repetitions that don't match the global event detail
         $query = "SELECT eventdetail_id FROM #__jevents_repetition WHERE eventid=" . $repeatdata->eventid . " AND startrepeat>='" . $repeatdata->startrepeat . "' AND eventdetail_id<>" . $eventdetailid;
         $db->setQuery($query);
         $detailids = $db->loadColumn();
         // Find repeat ids future repetitions
         $query = "SELECT rp_id FROM #__jevents_repetition WHERE eventid=" . $repeatdata->eventid . " AND startrepeat>='" . $repeatdata->startrepeat . "'";
         $db->setQuery($query);
         $rp_ids = $db->loadColumn();
         foreach ($rp_ids as $rp_id) {
             // May want to send notification messages etc.
             $dispatcher = JDispatcher::getInstance();
             // just incase we don't have jevents plugins registered yet
             JPluginHelper::importPlugin("jevents");
             $res = $dispatcher->trigger('onDeleteEventRepeat', $rp_id);
         }
         // Change the underlying event repeat rule details  !!
         $query = "SELECT * FROM #__jevents_rrule WHERE eventid={$repeatdata->eventid}";
         $db->setQuery($query);
         $this->rrule = null;
         $this->rrule = $db->loadObject();
         $this->rrule = iCalRRule::iCalRRuleFromDB(get_object_vars($this->rrule));
         if (intval($this->rrule->until) > 0) {
             // Find latest matching repetition
             $query = "SELECT max(startrepeat) FROM #__jevents_repetition WHERE eventid=" . $repeatdata->eventid . " AND startrepeat<'" . $repeatdata->startrepeat . "'";
             $db->setQuery($query);
             $lastrepeat = $db->loadResult();
             $this->rrule->until = JevDate::strtotime($lastrepeat);
         } else {
             // Find latest matching repetition
             $query = "SELECT count(startrepeat) FROM #__jevents_repetition WHERE eventid=" . $repeatdata->eventid . " AND startrepeat<'" . $repeatdata->startrepeat . "'";
             $db->setQuery($query);
             $countrepeat = $db->loadResult();
             $this->rrule->count = $countrepeat;
         }
         $this->rrule->store();
         if (!is_null($detailids) && count($detailids) > 0) {
             $query = "DELETE FROM #__jevents_vevdetail WHERE evdet_id IN (" . implode(",", $detailids) . ")";
             $db->setQuery($query);
             $db->query();
             // I also need to clean out associated custom data
             $dispatcher = JDispatcher::getInstance();
             // just incase we don't have jevents plugins registered yet
             JPluginHelper::importPlugin("jevents");
             $res = $dispatcher->trigger('onDeleteEventDetails', array(implode(",", $detailids)));
         }
         // setup exception data
         foreach ($rp_ids as $rp_id) {
             $query = "SELECT * FROM #__jevents_repetition WHERE rp_id={$rp_id}";
             $db->setQuery($query);
             $data = null;
             $data = $db->loadObject();
             $exception = iCalException::loadByRepeatId($rp_id);
             if (!$exception) {
                 $exception = new iCalException($db);
                 $exception->bind(get_object_vars($data));
             }
             $exception->exception_type = 0;
             // deleted
             $exception->store();
         }
         $query = "DELETE FROM #__jevents_repetition WHERE eventid=" . $repeatdata->eventid . " AND startrepeat>='" . $repeatdata->startrepeat . "'";
         $db->setQuery($query);
         $db->query();
         // Also clear out defunct exceptions
         $query = "DELETE FROM #__jevents_exception WHERE eventid=" . $repeatdata->eventid . " AND startrepeat>='" . $repeatdata->startrepeat . "' and exception_type=1 ";
         $db->setQuery($query);
         $db->query();
     }
 }
 function delete()
 {
     // clean out the cache
     $cache =& JFactory::getCache('com_jevents');
     $cache->clean(JEV_COM_COMPONENT);
     if (!JEVHelper::isEventCreator()) {
         JError::raiseError(403, JText::_('ALERTNOTAUTH'));
     }
     $cid = JRequest::getVar('cid', array(0));
     if (!is_array($cid)) {
         $cid = array(intval($cid));
     }
     JArrayHelper::toInteger($cid);
     $db =& JFactory::getDBO();
     foreach ($cid as $id) {
         $evid = JRequest::getInt("evid", 0);
         if ($evid > 0 && $id == $evid) {
             continue;
         }
         // I should be able to do this in one operation but that can come later
         $event = $this->queryModel->listEventsById(intval($id), 1, "icaldb");
         if (!JEVHelper::canDeleteEvent($event)) {
             JError::raiseError(403, JText::_('ALERTNOTAUTH'));
         }
         $query = "SELECT * FROM #__jevents_repetition WHERE rp_id={$id}";
         $db->setQuery($query);
         $data = null;
         $data = $db->loadObject();
         $query = "SELECT detail_id FROM #__jevents_vevent WHERE ev_id={$data->eventid}";
         $db->setQuery($query);
         $eventdetailid = $db->loadResult();
         // only remove the detail id if its different for this repetition i.e. not the global one!
         if ($eventdetailid != $data->eventdetail_id) {
             $query = "DELETE FROM #__jevents_vevdetail WHERE evdet_id = " . $data->eventdetail_id;
             $db->setQuery($query);
             $db->query();
             // I also need to clean out associated custom data
             $dispatcher =& JDispatcher::getInstance();
             // just incase we don't have jevents plugins registered yet
             JPluginHelper::importPlugin("jevents");
             $res = $dispatcher->trigger('onDeleteEventDetails', array($data->eventdetail_id));
         }
         // create exception based on deleted repetition
         $rp_id = $id;
         $exception = iCalException::loadByRepeatId($rp_id);
         if (!$exception) {
             $exception = new iCalException($db);
             $exception->bind(get_object_vars($data));
         }
         $exception->exception_type = 0;
         // deleted
         $exception->store();
         $query = "DELETE FROM #__jevents_repetition WHERE rp_id={$id}";
         $db->setQuery($query);
         $db->query();
     }
     if (JFactory::getApplication()->isAdmin()) {
         $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task=icalrepeat.list&cid[]=" . $data->eventid, "ICal Repeat deleted");
     } else {
         $Itemid = JRequest::getInt("Itemid");
         list($year, $month, $day) = JEVHelper::getYMD();
         $this->setRedirect(JRoute::_('index.php?option=' . JEV_COM_COMPONENT . "&task=day.listevents&year={$year}&month={$month}&day={$day}&Itemid={$Itemid}", false), "ICal Repeat deleted");
     }
 }