/** * Ensure that list of viewable calendars correctly reflects calendar permissions records */ public function testGetViewableUserCalendarNames() { TestingAuxLib::loadX2NonWebUser(); TestingAuxLib::suLogin('admin'); $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames()); $this->assertEquals(array_merge(array('Anyone'), Yii::app()->db->createCommand("\n SELECT username\n FROM x2_users\n ")->queryColumn()), ArrayUtil::sort($viewable)); $user = $this->users('testUser'); TestingAuxLib::suLogin('testuser'); $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames()); $grantedUsers = array_unique(array_merge(array('Anyone', 'testuser'), Yii::app()->db->createCommand("\n /**\n * get names of users who have granted view permission to testuser and names of\n * users who have not set up calendar permissions\n */\n SELECT distinct(username)\n FROM x2_users as t, x2_calendar_permissions\n WHERE other_user_id=:userId OR t.id NOT in (\n SELECT distinct(user_id)\n FROM x2_calendar_permissions\n )\n ")->queryColumn(array(':userId' => $user->id)))); $this->assertEquals(ArrayUtil::sort($grantedUsers), ArrayUtil::sort($viewable)); TestingAuxLib::restoreX2WebUser(); }
/** * Retrives all checked calendar events * @param int $start starting unix time to fetch events between * @param int $end ending unix time to fetch events between */ public function feedAll($start = null, $end = null) { // default window is +/- one month if (!isset($start)) { $start = strtotime("-1 month"); } $end = strtotime("+1 month"); $this->calendarUsers = X2CalendarPermissions::getViewableUserCalendarNames(); $this->groupCalendars = X2Calendar::getViewableGroupCalendarNames(); $this->calendarFilter = X2Calendar::getCalendarFilters(); $user = User::model()->findByPk(Yii::app()->user->getId()); $showCalendars = json_decode($user->showCalendars, true); //fix showCalendars['groupCalendars'] if (!isset($showCalendars['groupCalendars'])) { $showCalendars['groupCalendars'] = array(); $user->showCalendars = json_encode($showCalendars); $user->update(); } // get a list of all calendars to show $events = array(); foreach ($showCalendars['userCalendars'] as $cal) { $events = array_merge($events, $this->feedUser($cal, $start, $end)); } foreach ($showCalendars['groupCalendars'] as $cal) { $events = array_merge($events, $this->feedGroup($cal, $start, $end)); } return $events; }
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/fullcalendar-1.6.1/fullcalendar/gcal.js'); Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/js/calendar.js', CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/X2Dialog.js'); // register jquery timepicker css and js // (used inside js dialog because CJuiDateTimePicker is a php library that won't work inside a js dialog) //Yii::app()->clientScript->registerCssFile(Yii::app()->getBaseUrl() .'/protected/extensions/CJuiDateTimePicker/assets/jquery-ui-timepicker-addon.css'); //Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/protected/extensions/CJuiDateTimePicker/assets/jquery-ui-timepicker-addon.js'); $menuOptions = array('index', 'myPermissions'); if (Yii::app()->params->isAdmin) { $menuOptions[] = 'userPermissions'; } if (Yii::app()->settings->googleIntegration) { $menuOptions[] = 'sync'; } $this->insertMenu($menuOptions); $this->calendarUsers = X2CalendarPermissions::getViewableUserCalendarNames(); $this->groupCalendars = X2Calendar::getViewableGroupCalendarNames(); //$this->sharedCalendars = X2Calendar::getViewableCalendarNames(); //$this->googleCalendars = X2Calendar::getViewableGoogleCalendarNames(); $this->calendarFilter = X2Calendar::getCalendarFilters(); // urls for ajax (and other javascript) calls $urls = X2Calendar::getCalendarUrls(); $user = User::model()->findByPk(Yii::app()->user->getId()); $showCalendars = json_decode($user->showCalendars, true); // fix showCalendars['groupCalendars'] if (!isset($showCalendars['groupCalendars'])) { $showCalendars['groupCalendars'] = array(); $user->showCalendars = json_encode($showCalendars); $user->update(); } $userCalendars = $showCalendars['userCalendars'];