コード例 #1
0
ファイル: User.php プロジェクト: chezzy/yii-mblog
 /**
  * Checks if the currently logged in user is following the given user.
  * @param int $id     The ID to check
  * @return boolean
  */
 public static function isFollowing($id = NULL)
 {
     if ($id == NULL || Yii::app()->user->isGuest) {
         return false;
     }
     $following = Follower::model()->findByAttributes(array('follower_id' => Yii::app()->user->id, 'followee_id' => $id));
     return $following != NULL;
 }
コード例 #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Follower::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #3
0
ファイル: UserController.php プロジェクト: chezzy/yii-mblog
 public function actionFollowing($id = null)
 {
     if ($id == null) {
         if (Yii::app()->user->isGuest) {
             $this->redirect($this->createUrl('site/login'));
         }
         $id = Yii::app()->user->id;
     }
     $myFollowing = array();
     $following = Follower::model()->findAllByAttributes(array('follower_id' => $id));
     if ($following != null) {
         foreach ($following as $followee) {
             $myFollowing[] = $followee->followee_id;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $myFollowing);
     $following = User::model()->findAll($criteria);
     $this->render('following', array('users' => $following));
 }