Esempio n. 1
0
 public function testGetFilteredEventsDataProvider()
 {
     /*
      * This test is marked as skipped until it can be refactored. The test 
      * assumes that Events::getEvents and Events::getFilteredEventsDataProvider
      * return the same data, which may be true in some circumstances but depends
      * on the parameters passed to getEvents, which are currently incorrect. 
      */
     $this->markTestSkipped('Test requires refactor');
     TestingAuxLib::loadX2NonWebUser();
     $testUser = $this->users('testUser');
     TestingAuxLib::suLogin($testUser->username);
     Yii::app()->settings->historyPrivacy = null;
     $profile = Profile::model()->findByAttributes(array('username' => $testUser->username));
     $retVal = Events::getFilteredEventsDataProvider($profile, true, null, false);
     $dataProvider = $retVal['dataProvider'];
     $events = $dataProvider->getData();
     $expectedEvents = Events::getEvents(0, 0, count($events), $profile);
     // I'm not sure this assert is necessary, at the very least it needs
     // more thorough conditions
     // verify events from getData
     $this->assertEquals(Yii::app()->db->createCommand("\n                select id\n                from x2_events\n                where user='******' or visibility or (\n                    associationType='User' and associationId=:userId)\n                order by timestamp desc, id desc\n            ")->queryColumn(array(':userId' => $testUser->id)), array_map(function ($event) {
         return $event->id;
     }, $expectedEvents['events']));
     // ensure that getFilteredEventsDataProvider returns same events as getData
     $this->assertEquals(array_map(function ($event) {
         return $event->id;
     }, $expectedEvents['events']), array_map(function ($event) {
         return $event->id;
     }, $events));
 }
Esempio n. 2
0
 /**
  * Obtain all current notifications/events for the current web user.
  */
 public function actionGet()
 {
     if (Yii::app()->user->isGuest) {
         header('Content-type: application/json');
         echo CJSON::encode(array('sessionError' => Yii::t('app', 'Your X2Engine session has expired. You may select "cancel" to ignore this message and recover unsaved data from the current page. Otherwise, you will be redirected to the login page.')));
         Yii::app()->end();
     }
     if (!isset($_GET['lastNotifId'])) {
         // if the client doesn't specify the last
         $_GET['lastNotifId'] = 0;
     }
     // message ID received, send everything
     $notifications = $this->getNotifications($_GET['lastNotifId']);
     $notifCount = 0;
     if (count($notifications)) {
         $notifCount = X2Model::model('Notification')->countByAttributes(array('user' => Yii::app()->user->name), 'createDate < ' . time());
     }
     $chatMessages = array();
     $lastEventId = 0;
     $lastTimestamp = 0;
     // if the client specifies the last message ID received,
     if (isset($_GET['lastEventId']) && is_numeric($_GET['lastEventId'])) {
         // only send newer messages
         $lastEventId = $_GET['lastEventId'];
     }
     if (isset($_GET['lastTimestamp']) && is_numeric($_GET['lastTimestamp'])) {
         $lastTimestamp = $_GET['lastTimestamp'];
     }
     if ($lastEventId == 0) {
         // get page of newest events
         $retVal = Events::getFilteredEventsDataProvider(null, true, null, isset($_SESSSION['filters']));
         $dataProvider = $retVal['dataProvider'];
         $events = $dataProvider->getData();
     } else {
         // get new events
         $limit = null;
         $result = Events::getEvents($lastEventId, $lastTimestamp, $limit);
         $events = $result['events'];
     }
     $i = count($events) - 1;
     for ($i; $i > -1; --$i) {
         if (isset($events[$i])) {
             $userLink = '<span class="widget-event">' . $events[$i]->user . '</span>';
             $chatMessages[] = array((int) $events[$i]->id, (int) $events[$i]->timestamp, $userLink, $events[$i]->getText(array('truncated' => true)), Formatter::formatFeedTimestamp($events[$i]->timestamp));
         }
     }
     if (!empty($notifications) || !empty($chatMessages)) {
         header('Content-type: application/json');
         echo CJSON::encode(array('notifCount' => $notifCount, 'notifData' => $notifications, 'chatData' => $chatMessages));
     }
 }
Esempio n. 3
0
 public function testGetFilteredEventsDataProvider()
 {
     TestingAuxLib::loadX2NonWebUser();
     $testUser = $this->users('testUser');
     TestingAuxLib::suLogin($testUser->username);
     Yii::app()->settings->historyPrivacy = null;
     $profile = Profile::model()->findByAttributes(array('username' => $testUser->username));
     $retVal = Events::getFilteredEventsDataProvider($profile, true, null, false);
     $dataProvider = $retVal['dataProvider'];
     $events = $dataProvider->getData();
     $expectedEvents = Events::getEvents(0, 0, count($events), $profile);
     // verify events from getData
     $this->assertEquals(Yii::app()->db->createCommand("\n                select id\n                from x2_events\n                where user='******' or visibility or (\n                    associationType='User' and associationId=:userId)\n                order by timestamp desc, id desc\n            ")->queryColumn(array(':userId' => $testUser->id)), array_map(function ($event) {
         return $event->id;
     }, $expectedEvents['events']));
     // ensure that getFilteredEventsDataProvider returns same events as getData
     $this->assertEquals(array_map(function ($event) {
         return $event->id;
     }, $expectedEvents['events']), array_map(function ($event) {
         return $event->id;
     }, $events));
 }
Esempio n. 4
0
 public function getActivityFeedViewParams($id, $publicProfile)
 {
     Events::deleteOldEvents();
     $isMyProfile = !$publicProfile && $id === Yii::app()->params->profile->id;
     $profile = $this->loadModel($id);
     if (!Yii::app()->request->isAjaxRequest || Yii::app()->params->isMobileApp) {
         $_SESSION['lastDate'] = 0;
         unset($_SESSION['lastEventId']);
     }
     unset($_SESSION['feed-condition']);
     unset($_SESSION['feed-condition-params']);
     if (!isset($_GET['filters'])) {
         unset($_SESSION['filters']);
     }
     if (isset(Yii::app()->params->profile->defaultFeedFilters)) {
         $_SESSION['filters'] = json_decode(Yii::app()->params->profile->defaultFeedFilters, true);
     }
     $filters = null;
     $filtersOn = false;
     if (isset($_GET['filters'])) {
         $filters = $_GET;
         if ($_GET['filters']) {
             $filtersOn = true;
         }
     }
     $retVal = Events::getFilteredEventsDataProvider($profile, $isMyProfile, $filters, $filtersOn);
     $dataProvider = $retVal['dataProvider'];
     $lastTimestamp = $retVal['lastTimestamp'];
     $lastId = $retVal['lastId'];
     $data = $dataProvider->getData();
     if (isset($data[count($data) - 1])) {
         $firstId = $data[count($data) - 1]->id;
     } else {
         $firstId = 0;
     }
     if ($isMyProfile) {
         $users = User::getUserIds();
     } else {
         $users = array($profile->id => $profile->fullName);
     }
     $_SESSION['firstFlag'] = true;
     $stickyDataProvider = new CActiveDataProvider('Events', array('criteria' => array('condition' => 'sticky=1', 'order' => 'timestamp DESC, id DESC'), 'pagination' => array('pageSize' => 20)));
     $_SESSION['stickyFlag'] = false;
     $userModels = User::model()->active()->findAll();
     return array('model' => $profile, 'profileId' => $profile->id, 'isMyProfile' => $isMyProfile, 'dataProvider' => $dataProvider, 'users' => $users, 'lastEventId' => !empty($lastId) ? $lastId : 0, 'firstEventId' => !empty($firstId) ? $firstId : 0, 'lastTimestamp' => $lastTimestamp, 'stickyDataProvider' => $stickyDataProvider, 'userModels' => $userModels);
 }