public function actionpostdelete($postId) { $model = BusinessPagePost::model()->find('id=:id', array('id' => $postId)); $comments = CommentBussinessPage::model()->findAll('post_id=:id', array('id' => $postId)); $likes = LikeBusinessPost::model()->findAll('post_id=:id', array('id' => $postId)); foreach ($comments as $c) { $c->delete(); } foreach ($likes as $l) { $l->delete(); } $model->delete(); echo "success"; }
public function actionDashboard() { $this->setSession(); $posts = array(); $allposts = array(); $i = 0; //$posts = Post::model()->findAll(array('select' => '*','condition' => 'user_id=:userId','params' => array(':userId' => Yii::app()->user->userId),'order'=>'date DESC')); $friends = UserFriend::model()->findAll('user_id=:uid', array(':uid' => Yii::app()->user->userId)); if (empty($friends)) { $post = Post::model()->findAll(array('select' => '*', 'condition' => 'user_id=:userId', 'params' => array(':userId' => Yii::app()->user->userId), 'order' => 'date DESC')); } else { $post = Post::model()->findAll(array('select' => '*', 'condition' => 'user_id=:userId', 'params' => array(':userId' => Yii::app()->user->userId), 'order' => 'date DESC')); } // $posts = Post::model()->findAll(array('select' => '*','order'=>'date DESC')); //$pages = Pages::model()->findAll('user_id=:userId',array(':userId'=>Yii::app()->user->userId)); $pages = BusinessPagePost::model()->with('page', 'user')->findAll('t.user_id=:userId', array(':userId' => Yii::app()->user->userId)); $result = array_merge($post, $pages); //return; //shuffle($result); /* foreach($result as $r): if(isset($r['page_id'])) { echo 'company message '.$r->user->userProfile->first_name.'<br/>'; } else { echo 'post message '.$r->message.'<br/>'; } endforeach; */ $this->layout = 'layout_user'; $this->render('dashboard', array('posts' => $result)); }