예제 #1
0
 /**
  * @NoAdminRequired
  */
 public function getTasks()
 {
     $sMode = (string) $this->params('mode');
     $calId = (int) $this->params('calid');
     $atasksModeAllowed = array('dayselect' => 1, 'showall' => 1, 'today' => 1, 'tomorrow' => 1, 'actweek' => 1, 'withoutdate' => 1, 'missedactweek' => 1, 'alltasks' => 1, 'alltasksdone' => 1, 'sharedtasks' => 1, 'comingsoon' => 1);
     $tasks = array();
     if (intval($calId) > 0 && $sMode === '') {
         $cDataTimeLine = new Timeline();
         $cDataTimeLine->setTimeLineMode('');
         $cDataTimeLine->setCalendarId($calId);
         $tasks = $cDataTimeLine->generateCalendarSingleOutput();
     }
     // Get Timelined tasks
     if ($sMode !== '' && $atasksModeAllowed[$sMode] && $sMode !== 'sharedtasks') {
         $calendars = CalendarCalendar::allCalendars($this->userId, true);
         $activeCalendars = '';
         foreach ($calendars as $calendar) {
             $isAktiv = $calendar['active'];
             if ($this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']) != '') {
                 $isAktiv = $this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']);
             }
             if (!array_key_exists('active', $calendar)) {
                 $isAktiv = 1;
             }
             if ((int) $isAktiv === 1 && (int) $calendar['issubscribe'] === 0) {
                 $activeCalendars[] = $calendar;
             }
         }
         $cDataTimeLine = new Timeline();
         if ($sMode === 'dayselect') {
             $sDay = $this->params('sday');
             $timeStampDay = strtotime($sDay);
             $cDataTimeLine->setTimeLineDay($timeStampDay);
         }
         $cDataTimeLine->setTimeLineMode($sMode);
         $cDataTimeLine->setCalendars($activeCalendars);
         $tasks = $cDataTimeLine->generateTasksAllOutput();
     }
     //Get Shared Tasks
     if ($sMode !== '' && $atasksModeAllowed[$sMode] && $sMode === 'sharedtasks') {
         $singletodos = \OCP\Share::getItemsSharedWith(CalendarApp::SHARETODO, Vtodo::FORMAT_TODO);
         if (is_array($singletodos)) {
             $tasks = $singletodos;
         }
     }
     $response = new JSONResponse();
     $response->setData($tasks);
     return $response;
 }
예제 #2
0
파일: app.php 프로젝트: ejouvin/tasksplus
 public static function allInPeriodCalendar($aCalendar, $MODE = 'today', $sDay = '')
 {
     //today,tomorrow,actweek,withoutdate,missedtasks
     $sharedwithByTodo = self::getTodoSharees();
     $cDataTimeLine = new Timeline();
     $cDataTimeLine->setTimeLineMode($MODE);
     if ($MODE === 'dayselect') {
         $cDataTimeLine->setTimeLineDay($sDay);
     }
     $cDataTimeLine->setCalendars($aCalendar);
     $aSQL = $cDataTimeLine->getTimeLineDB();
     $startDate = $cDataTimeLine->getStartDate();
     $endDate = $cDataTimeLine->getEndDate();
     //\OCP\Util::writeLog(self::$appname,'sql->where: '.$aSQL['wheresql'], \OCP\Util::DEBUG);
     $stmt = \OCP\DB::prepare('SELECT * FROM `' . CalendarApp::CldObjectTable . '` WHERE  `objecttype`= ? ' . $aSQL['wheresql'] . ' ORDER BY relatedto ASC, calendarid ASC, startdate DESC');
     $result = $stmt->execute($aSQL['execsql']);
     $calendarobjects = array();
     while ($row = $result->fetchRow()) {
         //$row['permissions'] = \OCP\PERMISSION_ALL;
         $row['shared'] = 0;
         if (is_array($sharedwithByTodo) && isset($sharedwithByTodo[$row['id']])) {
             $row['shared'] = 1;
         }
         if ($row['repeating'] === 1) {
             $start = new \DateTime($row['startdate']);
             $end = new \DateTime($row['enddate']);
             $startDB = new \DateTime($startDate);
             $endDB = new \DateTime($endDate);
             $object = VObject::parse($row['calendardata']);
             $vtodo = $object->VTODO;
             $rrule = explode(';', $vtodo->getAsString('RRULE'));
             foreach ($rrule as $rule) {
                 list($attr, $val) = explode('=', $rule);
                 if ($attr === 'FREQ') {
                     if ($val === 'WEEKLY') {
                         $endTS = $end->format('U');
                         //Get day of Week
                         $dayOfWeekrRule = date('w', $start->format('U'));
                         $dayOfWeek = date('w', $startDB->format('U'));
                         $startDBU = $startDB->format('U');
                         if ($MODE != 'actweek') {
                             if ($dayOfWeekrRule == $dayOfWeek && $startDBU < $endTS) {
                                 $calendarobjects[] = $row;
                             }
                         } else {
                             $endDBU = $endDB->format('U');
                             if ($endTS > $endDBU) {
                                 $calendarobjects[] = $row;
                                 //\OCP\Util::writeLog('calendar','Events Shared Found: ->'.$MODE, \OCP\Util::DEBUG);
                             }
                         }
                     }
                     if ($val === 'DAILY') {
                         $dayOfWeek = date('w', $startDB->format('U'));
                         $endTS = $end->format('U');
                         $startDBU = $startDB->format('U');
                         if ($MODE !== 'actweek') {
                             if ($dayOfWeek != 0 && $dayOfWeek != 6 && $startDBU < $endTS) {
                                 $calendarobjects[] = $row;
                             }
                         } else {
                             for ($i = 1; $i < 6; $i++) {
                                 $row['day'] = $i;
                                 $calendarobjects[] = $row;
                             }
                         }
                     }
                 }
             }
         } else {
             $calendarobjects[] = $row;
         }
     }
     $tasksFiltered = array();
     foreach ($calendarobjects as $taskHaupt) {
         $bsub = false;
         $uidName = '';
         foreach ($calendarobjects as $taskSub) {
             if ($taskHaupt['eventuid'] !== '' && $taskHaupt['eventuid'] === $taskSub['relatedto']) {
                 $bsub = true;
                 $uidName = $taskHaupt['summary'];
             }
         }
         $taskHaupt['subtask'] = $bsub;
         if ($bsub === false) {
             $taskHaupt['uidname'] = $uidName;
         }
         $tasksFiltered[] = $taskHaupt;
     }
     return $tasksFiltered;
 }