Exemplo n.º 1
0
 /**
  * 更新一个markable对象的mark表记录
  * @param $id:markable对象的id
  */
 public function run($id)
 {
     //得到当前的questionable对象
     $controller = $this->getController();
     $model = $controller->loadModel($id);
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->attributes = $_POST['Comment'];
         if ($model->addComment($comment)) {
             $model->upTime = time();
             $model->save();
             //发送消息
             //$comment = $event->params['comment'];
             if ($model->asa('followable')) {
                 $follows = $model->getAllFollows();
                 foreach ($follows as $follow) {
                     if ($follow->userId != $comment->userId && $follow->userId != $comment->referId) {
                         Notice::send($follow->userId, $model->entity->type . "_comment_added", array('commentId' => $comment->id));
                     }
                 }
             }
             Yii::app()->user->setFlash('success', '评论成功!');
         } else {
             Yii::app()->user->setFlash('error', '抱歉,评论失败!');
         }
     }
     $controller->redirect(array('view', 'id' => $model->id));
 }
 /**
  * 处理被回复事件
  */
 public function handleOnRecommentAdded($event)
 {
     $owner = $this->getOwner();
     $comment = $event->params['comment'];
     if ($owner->userId != $comment->userId) {
         return Notice::send($owner->userId, "comment_recomment_added", array('commentId' => $comment->id));
     }
 }
Exemplo n.º 3
0
 /**
  * 申请发布事件
  * @param unknown_type $event
  */
 public function handleOnApplied($event)
 {
     $owner = $this->getOwner();
     $admins = UserInfo::getAllAdmins();
     foreach ($admins as $user) {
         Notice::send($user->id, 'entity_applied', array('entityId' => $owner->entityId));
     }
 }
Exemplo n.º 4
0
 /**
  * 
  * (non-PHPdoc)
  * @see AbleBehavior::handleOnAdded()
  */
 public function handleOnAdded($event)
 {
     //只对follow用户的情形发通知
     $follow = $event->params['follow'];
     if ($follow->followableEntity->type == "user") {
         $user = $follow->followableEntity->getModel();
         if (isset($user->fanNum)) {
             $user->fanNum = $this->getFanCount();
             $user->save();
         }
         Notice::send($user->id, "follow_user", array('userId' => $follow->userId));
     }
 }
Exemplo n.º 5
0
 /**
  * 关注或取消赞成
  * @param unknown_type $id
  */
 public function run($id, $value)
 {
     $model = $this->controller->loadModel($id, $value);
     $model->toggleVote(Yii::app()->user->id, $value);
     $vote = Vote::model()->findByAttributes(array('voteableEntityId' => $model->entityId, 'userId' => Yii::app()->user->id));
     if (isset($vote) && $vote) {
         if ($vote->userId != $model->userId) {
             $result = Notice::send($model->userId, $model->entity->type . "_vote_added", array('voteId' => $vote->id));
         }
     }
     //feed
     //	Feed::send("vote_added", array('voteid'=>$vote->id));
     $this->controller->renderPartial('//vote/result', array('score' => $model->voteUpNum, 'voteUpers' => $model->getVoteUperDataProvider()->getData()));
 }
Exemplo n.º 6
0
 /**
  * 覆盖父类的时间相应函数
  * @see AbleBehavior::handleOnAdded()
  */
 public function handleOnAdded($event)
 {
     //更新Num
     $this->refreshMediaNum();
     //发送消息
     $media = $event->params['media'];
     $follows = $owner->getAllFollows();
     foreach ($follows as $follow) {
         if ($follow->userId != $media->userId && $follow->userId != $media->referId) {
             Notice::send($follow->userId, "media_added", array('entityId' => $owner->entityId, 'mediaid' => $media->id));
         }
     }
     //feed
     Feed::send("media_added", array('entityId' => $owner->entityId, 'mediaid' => $media->id));
 }
 /**
  * 添加comment
  */
 public function addComment($comment)
 {
     //$this->addItem($comment);
     $comment->addTime = time();
     $comment->userId = Yii::app()->user->id;
     $comment->commentableEntityId = $this->getOwner()->entityId;
     $result = $comment->save();
     if ($result) {
         if ($comment->referId && $comment->userId != $comment->refer->userId) {
             //触发onRecommented事件
             //	$referComment = Comment::model()->findByPk($comment->referId);
             //	$referComment->onRecommentAdded(new CEvent($referComment,array('comment'=>$comment)));
             $type = $comment->commentableEntity->type;
             Notice::send($comment->refer->userId, $type . "_comment_recomment_added", array('commentId' => $comment->id));
         }
         $this->onAdded(new CEvent($this, array('comment' => $comment)));
     }
     return $result;
 }
Exemplo n.º 8
0
 /**
  * 创建小组页面和处理
  */
 public function actionCreate()
 {
     $model = new Group();
     if (isset($_POST['Group'])) {
         $model->attributes = $_POST['Group'];
         $model->addTime = time();
         $model->userId = Yii::app()->user->id;
         $model->status = "apply";
         if ($model->save()) {
             //			$model->addMember(Yii::app()->user->id,array('superAdmin'));
             $member = new GroupMember();
             $member->groupId = $model->id;
             $member->userId = Yii::app()->user->id;
             $member->setArrRoles(array('superAdmin'));
             $member->save();
             $admins = UserInfo::getAllAdmins();
             foreach ($admins as $user) {
                 Notice::send($user->id, 'group_apply', array('groupId' => $model->getPrimaryKey()));
             }
             Yii::app()->user->setFlash('success', '申请已提交,请继续完善小组资料');
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $user = UserInfo::model()->findByPk(Yii::app()->user->id);
     $this->render('create', array('model' => $model, 'user' => $user));
 }
Exemplo n.º 9
0
 public function actionAddComment($id)
 {
     $model = $this->loadModel($id);
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->attributes = $_POST['Comment'];
         if ($model->addComment($comment)) {
             $model->upTime = time();
             $model->save();
             //发送消息
             if ($model->asa('followable')) {
                 $follows = $model->getAllFollows();
                 foreach ($follows as $follow) {
                     if ($follow->userId != $comment->userId && $follow->userId != $comment->referId) {
                         Notice::send($follow->userId, $model->entity->type . "_comment_added", array('commentId' => $comment->id));
                     }
                 }
             }
             //更新回复统计
             $member = CourseMember::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'courseId' => $model->courseId));
             if ($member) {
                 $criteria = new CDbCriteria();
                 $criteria->join = "inner join {{course_post}} p on p.entityId=t.commentableEntityId";
                 $criteria->condition = "p.courseId=" . intval($model->courseId) . " and t.userId=" . Yii::app()->user->id;
                 //	Comment::model()->count($criteria);
                 $member->commentNum = Comment::model()->count($criteria);
                 $member->save();
             }
             Yii::app()->user->setFlash('success', '回复成功!');
         } else {
             Yii::app()->user->setFlash('error', '抱歉,回复失败!');
         }
     }
     $this->redirect(array('view', 'id' => $model->id));
 }