public static function getCalendarFilters() { $user = User::model()->findByPk(Yii::app()->user->id); $calendarFilters = explode(',', $user->calendarFilter); $filters = X2Calendar::getCalendarFilterNames(); $filterList = array(); foreach ($filters as $filter) { if (in_array($filter, $calendarFilters)) { $filterList[$filter] = true; } else { $filterList[$filter] = false; } } return $filterList; }
/** * return a json string of actions associated with the specified shared calendar */ public function actionJsonFeedShared($calendarId) { $actions = Actions::model()->findAllByAttributes(array('calendarId' => $calendarId)); $events = array(); $user = User::model()->findByPk(Yii::app()->user->id); // get user profile $filter = explode(',', $user->calendarFilter); // action types user doesn't want filtered $possibleFilters = X2Calendar::getCalendarFilterNames(); // action types that can be filtered foreach ($actions as $action) { if ($action->visibility >= 1 || $action->assignedTo == Yii::app()->user->name || Yii::app()->user->name == 'admin') { // don't show private actions, unless they belong to current user if (in_array($action->type, $possibleFilters)) { // type of action user might filter? if (!in_array($action->type, $filter)) { // filter actions user doesn't want to see continue; } } if (!in_array('completed', $filter)) { // filter completed actions if user doesn't want to see them if ($action->complete == 'Yes') { continue; } } $description = $action->actionDescription; $title = substr($description, 0, 30); if ($action->type == 'event') { $events[] = array('title' => $title, 'description' => $description, 'start' => date('Y-m-d H:i', $action->dueDate), 'id' => $action->id, 'complete' => $action->complete, 'associationType' => $action->associationType, 'type' => 'event', 'allDay' => false); end($events); $last = key($events); if ($action->completeDate) { $events[$last]['end'] = date('Y-m-d H:i', $action->completeDate); } if ($action->allDay) { $events[$last]['allDay'] = $action->allDay; } if ($action->color) { $events[$last]['color'] = $action->color; } if ($action->associationType == 'contacts') { $events[$last]['associationUrl'] = $this->createUrl('/contacts/default/view/id/' . $action->associationId); $events[$last]['associationName'] = $action->associationName; } } else { if ($action->associationType == 'contacts') { $events[] = array('title' => $title, 'description' => $description, 'start' => date('Y-m-d H:i', $action->dueDate), 'id' => $action->id, 'complete' => $action->complete, 'associationType' => 'contacts', 'associationUrl' => $this->createUrl('/contacts/default/view/id/' . $action->associationId), 'associationName' => $action->associationName, 'allDay' => false); end($events); $last = key($events); if ($action->allDay) { $events[$last]['allDay'] = $action->allDay; } if ($action->color) { $events[$last]['color'] = $action->color; } } else { $events[] = array('title' => $title, 'description' => $description, 'start' => date('Y-m-d H:i', $action->dueDate), 'id' => $action->id, 'complete' => $action->complete, 'allDay' => false); end($events); $last = key($events); if ($action->allDay) { $events[$last]['allDay'] = $action->allDay; } if ($action->color) { $events[$last]['color'] = $action->color; } } } } } echo json_encode($events); }