Beispiel #1
0
 public function afterLoad(&$response, &$model, &$params)
 {
     //		if (isset($response['data']['name']))
     //			$response['data']['subject'] = $response['data']['name'];
     $response = self::reminderSecondsToForm($response);
     $response['data']['start_time'] = date(\GO::user()->time_format, $model->start_time);
     $response['data']['end_time'] = date(\GO::user()->time_format, $model->end_time);
     if (isset($response['data']['rrule']) && !empty($response['data']['rrule'])) {
         $rRule = new \GO\Base\Util\Icalendar\Rrule();
         $rRule->readIcalendarRruleString($model->start_time, $model->rrule);
         $createdRule = $rRule->createJSONOutput();
         $response['data'] = array_merge($response['data'], $createdRule);
     }
     $response['data']['start_date'] = \GO\Base\Util\Date::get_timestamp($model->start_time, false);
     $response['data']['end_date'] = \GO\Base\Util\Date::get_timestamp($model->end_time, false);
     if (\GO::modules()->customfields) {
         $response['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Calendar\\Model\\Event", $model->calendar->group_id);
     }
     $response['group_id'] = $model->calendar->group_id;
     if (!$model->id) {
         $days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
         $response['data'][$days[date('w', $model->start_time)]] = 1;
     }
     if (!$model->isResource() && $model->id > 0) {
         $this->_loadResourceEvents($model, $response);
     }
     //		$response['data']['has_other_participants']=$model->hasOtherParticipants(\GO::user()->id);
     $response['data']['user_name'] = $model->user ? $model->user->name : "Unknown";
     if (empty($params['id'])) {
         $participantModel = $model->getDefaultOrganizerParticipant();
         $response['participants'] = array('results' => array($participantModel->toJsonArray($model->start_time, $model->end_time)), 'total' => 1, 'success' => true);
         if (!empty($params['linkModelNameAndId'])) {
             $arr = explode(':', $params['linkModelNameAndId']);
             if ($arr[0] == 'GO\\Addressbook\\Model\\Contact') {
                 $contact = \GO\Addressbook\Model\Contact::model()->findByPk($arr[1]);
                 if ($contact) {
                     $participantModel = new \GO\Calendar\Model\Participant();
                     $participantModel->setContact($contact);
                     $response['participants']['results'][] = $participantModel->toJsonArray($model->start_time, $model->end_time);
                     $response['participants']['total'] = 2;
                 }
             }
         }
     } else {
         $particsStmt = \GO\Calendar\Model\Participant::model()->findByAttribute('event_id', $params['id']);
         $response['participants'] = array('results' => array(), 'total' => 0, 'success' => true);
         while ($participantModel = $particsStmt->fetch()) {
             $record = $participantModel->toJsonArray($model->start_time, $model->end_time);
             if (!empty($params['exception_date'])) {
                 unset($record['id']);
             }
             $response['participants']['results'][] = $record;
             $response['participants']['total'] += 1;
         }
         if ($response['participants']['total'] == 0) {
             $participantModel = $model->getDefaultOrganizerParticipant();
             $response['participants'] = array('results' => array($participantModel->toJsonArray($model->start_time, $model->end_time)), 'total' => 1, 'success' => true);
         }
     }
     return parent::afterLoad($response, $model, $params);
 }
 public function actionGetUserGroups($params)
 {
     $ids = json_decode($params['groups']);
     $store = new \GO\Base\Data\ArrayStore();
     $addedUsers = array();
     foreach ($ids as $group_id) {
         $group = \GO\Base\Model\Group::model()->findByPk($group_id, false, true);
         $stmt = $group->users();
         foreach ($stmt as $user) {
             if (!in_array($user->id, $addedUsers)) {
                 $addedUsers[] = $user->id;
                 $participant = new \GO\Calendar\Model\Participant();
                 $participant->user_id = $user->id;
                 $participant->name = $user->name;
                 $participant->email = $user->email;
                 $store->addRecord($participant->toJsonArray($params['start_time'], $params['end_time']));
             }
         }
     }
     return $store->getData();
 }