コード例 #1
0
 /**
  * Add My saved calendars.
  *
  * @param SavedCalendarSubscriptions $savedCalendarSubscriptions
  * @param User $user
  * @param string $selectedCalendarIds
  * @return \SavedCalendarSubscriptions
  */
 private static function addMySavedCalendars(SavedCalendarSubscriptions $savedCalendarSubscriptions, User $user, $selectedCalendarIds)
 {
     $mySavedCalendars = CalendarUtil::getUserSavedCalendars($user);
     if (count($mySavedCalendars) == 0) {
         $mySavedCalendars = CalendarUtil::loadDefaultCalendars($user);
         $selectedCalendarIds = $mySavedCalendars[0]->id . ',' . $mySavedCalendars[1]->id;
         // Not Coding Standard
     }
     ZurmoConfigurationUtil::setByUserAndModuleName($user, 'CalendarsModule', 'myCalendarSelections', $selectedCalendarIds);
     $selectedCalendarIdArray = array();
     if ($selectedCalendarIds != null) {
         $selectedCalendarIdArray = explode(',', $selectedCalendarIds);
         // Not Coding Standard
     }
     foreach ($mySavedCalendars as $key => $mySavedCalendar) {
         CalendarUtil::setMyCalendarColor($mySavedCalendar, $user);
         if (in_array($mySavedCalendar->id, $selectedCalendarIdArray)) {
             $savedCalendarSubscriptions->addMySavedCalendar($mySavedCalendar, true);
         } else {
             $savedCalendarSubscriptions->addMySavedCalendar($mySavedCalendar, false);
         }
     }
 }
コード例 #2
0
 public function testLoadDefaultCalendars()
 {
     $user = UserTestHelper::createBasicUser('jim');
     Yii::app()->user->userModel = $user;
     $this->assertEquals(0, count(CalendarUtil::getUserSavedCalendars($user)));
     SavedCalendarSubscriptions::makeByUser($user);
     $this->assertEquals(2, count(CalendarUtil::getUserSavedCalendars($user)));
     $calendars = CalendarUtil::getUserSavedCalendars($user);
     $model = $calendars[0];
     $data = unserialize($model->serializedData);
     $filtersData = $data[ComponentForReportForm::TYPE_FILTERS];
     $this->assertEquals(strval($user), $filtersData[0]['stringifiedModelForValue']);
     $this->assertEquals($user->id, $filtersData[0]['value']);
     $this->assertEquals('1', $data['filtersStructure']);
 }