$link=''; if ((!Yii::app()->user->isGuest) AND ($list<>NULL)) { $li=$list[0]->key;//find postID $userID=Yii::app()->user->id; $models = Comment::model()->findAll( array("condition"=>"userId= $userID",'select'=>'id',)); //find all review post by user $list3 = CHtml::listData($models, 'id' ,'userId'); for ($i = 0; $i < count($list3); $i++) { $key=key($list3); if ($key<>NULL) { $getID= PostsComments::model()->findAll( array("condition"=>"commentId=$key AND postId=$li",'select'=>'commentId, postId',)); $list2 = CHtml::listData($getID, 'commentId' ,'postId'); $commentId=key($list2);//get lay id review ma nguoi dung da post if ($commentId<>NULL) { $count=$count+1; $link=$commentId; } } next($list3); } } if ($count<>0) { echo "<br>";
protected function beforeDelete() { //ko co id teacher nhu o afterSave nen phai get lay $getID= PostsComments::model()->findAll( array("condition"=>"commentId=$this->id")); $li = CHtml::listData($getID,'postId','commentId'); $key=key($li); $model2 = School::model()->findAll( array("condition"=>"id = $key",'select'=>'rate1,rate2,rate3,rate4,rate5,count',)); if ($model2<>NULL) { self::minusPointTeacher($model2,$key); } $models = Teacher::model()->findAll( array("condition"=>"id = $key",'select'=>'rate1,rate2,rate3,rate4,rate5,count',)); if ($models<>NULL) { self::minusPointSchool($models,$key); } return parent::beforeDelete(); }