Exemplo n.º 1
0
 protected function event_data($event)
 {
     $data = parent::event_data($event);
     $event = $data['event'];
     // this is a guaranteed object of type Model_Event
     $lecture = $event->lectures->find();
     $teacher = ORM::factory('user', $lecture->user_id);
     return array_merge($data, array('lecture' => $lecture, 'course' => $lecture->course, 'teacher' => $teacher));
 }
 /**
  * Редактирует событие
  * @return void
  */
 function edit()
 {
     $user = Core::getInstance()->user;
     // Определяем массив данных для обработки
     $request = _Core_Request::getCurrent();
     $event_array = array('id' => (int) $request->post['id'], 'chain' => (int) $request->post['chain'], 'type' => (int) $request->post['type'], 'account' => (int) $request->post['account'], 'amount' => (double) str_replace(' ', '', $request->post['amount']), 'category' => (int) $request->post['category'] <= 0 ? null : (int) $request->post['category'], 'date' => Helper_Date::RusDate2Mysql($this->getDateOperation()), 'comment' => (string) $request->post['comment'], 'tags' => isset($request->post['tags']) ? explode(',', $request->post['tags']) : array(), 'convert' => isset($request->post['convert']) ? $request->post['convert'] : 0, 'close' => isset($request->post['close']) ? $request->post['close'] : 0, 'currency' => isset($request->post['currency']) ? $request->post['currency'] : 0, 'toAccount' => isset($request->post['toAccount']) ? $request->post['toAccount'] : null, 'target' => isset($request->post['target']) ? $request->post['target'] : null, 'last' => isset($request->post['last']) ? Helper_Date::RusDate2Mysql($request->post['last']) : '0000-00-00', 'time' => isset($request->post['time']) ? $request->post['time'] : date("H:i:s"), 'every' => isset($request->post['every']) ? (int) $request->post['every'] : 0, 'repeat' => isset($request->post['repeat']) ? (int) $request->post['repeat'] : 1, 'week' => isset($request->post['week']) ? $request->post['week'] : '0000000', 'accepted' => isset($request->post['accepted']) ? (int) $request->post['accepted'] : 0);
     // Напоминания
     $notifications = $this->_readNotificationsFromRequest($request);
     $event_array = array_merge($event_array, $notifications);
     $event = new Calendar_Event(new Calendar_Model($event_array, $user), $user);
     if (!$event->checkData()) {
         $this->tpl->assign('error', array('text' => implode(",\n", $event->getErrors())));
     } else {
         // Если нет цепочки, значит только одна операция
         if ($event_array['chain'] === 0) {
             $operation = new Operation_Model();
             if ($event_array['type'] <= 1) {
                 if ($event_array['type'] == 0) {
                     $event_array['amount'] = abs($event_array['amount']) * -1;
                 } else {
                     $event_array['amount'] = abs($event_array['amount']);
                 }
                 $operation->edit($event_array['type'], $event_array['id'], $event_array['amount'], $event_array['date'], $event_array['category'], $event_array['comment'], $event_array['account'], $event_array['tags'], $event_array['accepted'], $notifications);
             } elseif ($event_array['type'] == 2) {
                 $operation->editTransfer($event_array['id'], $event_array['amount'], $event_array['convert'], $event_array['date'], $event_array['account'], $event_array['toAccount'], $event_array['comment'], $event_array['tags'], $event_array['accepted'], $notifications);
             }
             $this->tpl->assign('result', array('text' => 'Регулярная операция изменена'));
         } else {
             $calendar = new Calendar($user);
             $calendar->edit($event);
             $this->tpl->assign('result', array('text' => 'Регулярные операции изменены'));
         }
         // @FIXME Перенести этот блок кода в календарь
         Core::getInstance()->user->initUserEvents();
         Core::getInstance()->user->save();
         $this->tpl->assign('future', Core::getInstance()->user->getUserEvents('reminder'));
         $this->tpl->assign('overdue', Core::getInstance()->user->getUserEvents('overdue'));
         $this->tpl->assign('calendar', Core::getInstance()->user->getUserEvents('calendar'));
     }
 }
Exemplo n.º 3
0
 public function action_day_events()
 {
     $year = $this->request->param('year', date('Y'));
     $month = $this->request->param('month', date('m'));
     $day = $this->request->param('day', date('d'));
     $event_type = $this->request->param('event_type');
     $date = date('Y-m-d', mktime(0, 0, 0, (int) $month, (int) $day, $year));
     $events = Model_Event::daily_events($date);
     $day_events = array();
     foreach ($events as $event) {
         $day_events[] = Calendar_Event::factory($event->eventtype)->day_event($event);
     }
     $view = View::factory('calendar/day_events')->set('date', $date)->set('day_events', $day_events);
     $this->content = $view;
 }
Exemplo n.º 4
0
 public function repeatWeekly(Calendar_Event $event)
 {
     if (!isset($_POST['weekday_repeat']) || !is_array($_POST['weekday_repeat'])) {
         $this->message = dgettext('calendar', 'You must choose which weekdays to repeat.');
         return false;
     }
     $time_unit = $event->start_time + 86400;
     $copy_event = $event->repeatClone();
     $time_diff = $event->end_time - $event->start_time;
     $max_count = 0;
     $repeat_days =& $_POST['weekday_repeat'];
     $dst_start = date('I', $event->start_time);
     while ($time_unit <= $event->end_repeat) {
         if (!in_array(strftime('%u', $time_unit), $repeat_days)) {
             $time_unit += 86400;
             continue;
         }
         $dst_current = date('I', $time_unit);
         if ($dst_current != $dst_start) {
             if ($dst_current) {
                 $time_unit -= 3600;
             } else {
                 $time_unit += 3600;
             }
             $dst_start = $dst_current;
         }
         $copy_event->id = 0;
         $max_count++;
         if ($max_count > CALENDAR_MAXIMUM_REPEATS) {
             return PHPWS_Error::get(CAL_REPEAT_LIMIT_PASSED, 'calendar', 'Calendar_Admin::repeatWeekly');
         }
         $copy_event->start_time = $time_unit;
         $copy_event->end_time = $time_unit + $time_diff;
         $result = $copy_event->save();
         if (PHPWS_Error::isError($result)) {
             return $result;
         }
         $time_unit += 86400;
     }
     return TRUE;
 }
Exemplo n.º 5
0
 /**
  * Подтверждает события
  * @param array int
  */
 public function acceptEvents($ids)
 {
     $overdue = Core::getInstance()->user->getUserEvents('overdue');
     $future = Core::getInstance()->user->getUserEvents('future');
     $calendar = Core::getInstance()->user->getUserEvents('calendar');
     $newIds = array();
     foreach ($ids as $id) {
         if (isset($overdue[$id])) {
             $operation = $overdue[$id];
         } elseif (isset($future[$id])) {
             $operation = $future[$id];
         } elseif (isset($calendar[$id])) {
             $operation = $calendar[$id];
         } else {
             $this->_errors['error'] = "Не найдена операция для подтверждения";
         }
         $operation['accepted'] = 1;
         $operation['category'] = $operation['cat_id'];
         $operation['account'] = $operation['account_id'];
         $operation['toAccount'] = $operation['transfer'];
         $operation['amount'] = $operation['money'];
         $event = new Calendar_Event(new Calendar_Model($operation, Core::getInstance()->user), Core::getInstance()->user);
         if (!$event->checkData()) {
             $this->_errors = array_merge($this->_errors, $event->getErrors());
         } else {
             $newIds[] = $id;
         }
     }
     if (count($newIds) > 0) {
         // Получаем список событий, отмечаем что они выполненные
         return Calendar_Model::acceptEvents($this->_user, $newIds);
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public function post($suggested = false)
 {
     return parent::post(true);
 }
Exemplo n.º 7
0
 function exportEvent($event_id)
 {
     PHPWS_Core::initModClass('calendar', 'Event.php');
     $event = new Calendar_Event($event_id, $this);
     if ($event->id) {
         $tpl = $event->icalTags();
     } else {
         $tpl['EMPTY'] = ' ';
     }
     $content = PHPWS_Template::process($tpl, 'calendar', 'ical.tpl');
     header("Content-type: text/calendar");
     header('Content-Disposition: attachment; filename="icalexport.ics"');
     echo $content;
     exit;
 }
Exemplo n.º 8
0
 /**
  * Добавляет рег. операции
  * @param oldUser $user
  * @param Calendar_Event $event
  * @param int $chain
  * @param array $arrayDays
  */
 private function createOperations(oldUser $user, Calendar_Event $event, $chain, $arrayDays)
 {
     // Создаём повторы события в виде неподтверждённых операций
     $operationsArray = array();
     foreach ($arrayDays as $value) {
         // @TODO Посмотреть, как можно адаптировать $event->__getArray()
         $operationsArray[] = array('type' => $event->getType(), 'account' => $event->getAccount(), 'amount' => $event->getAmount(), 'category' => $event->getCategory(), 'date' => $value, 'comment' => $event->getComment(), 'tags' => $event->getTags(), 'convert' => $event->getConvert(), 'close' => $event->getClose(), 'currency' => $event->getCurrency(), 'toAccount' => $event->getToAccount(), 'target' => $event->getTarget(), 'last' => $event->getLast(), 'time' => $event->getTime(), 'every' => $event->getEvery(), 'repeat' => $event->getRepeat(), 'week' => $event->getWeek(), 'accepted' => 0, 'chain' => $chain, 'mailEnabled' => $event->getMailEnabled(), 'mailDaysBefore' => $event->getMailDaysBefore(), 'mailHour' => $event->getMailHour(), 'mailMinutes' => $event->getMailMinutes(), 'smsEnabled' => $event->getSmsEnabled(), 'smsDaysBefore' => $event->getSmsDaysBefore(), 'smsHour' => $event->getSmsHour(), 'smsMinutes' => $event->getSmsMinutes());
     }
     $operation = new Operation_Model();
     // Расход и доход
     if ($event->getType() <= 1) {
         return $operation->addSome($operationsArray);
     } elseif ($event->getType() == 2) {
         return $operation->addSomeTransfer($operationsArray);
     }
 }
Exemplo n.º 9
0
 protected function event_data($event)
 {
     $data = parent::event_data($event);
     $exam = ORM::factory('exam')->where('event_id', ' = ', (int) $event->id)->find();
     return array_merge($data, array('exam' => $exam, 'course' => $exam->course, 'examgroup' => $exam->examgroup));
 }