Esempio n. 1
0
 /**
  * Carrega uma tabela listando as postagens existentes no sistema
  */
 public function listPostsAction()
 {
     $this->session->start();
     if ($this->session->get('user_id') != NULL) {
         $vars = $this->getUserLoggedInformation();
         $user = Users::findFirstByUser_id($this->session->get('user_id'));
         if ($user->user_type_id < 3) {
             $posts = Posts::find(array("order" => "post_date_posted DESC"));
         } elseif ($user->user_type_id == 3) {
             $usr = Users::find(array("conditions" => "user_type_id > :user_type_id: OR user_id = :user_id: ", "bind" => array("user_type_id" => $user->user_type_id, "user_id" => $user->user_id)));
             foreach ($usr as $u) {
                 $arr_id_users[] = $u->user_id;
             }
             $string_users = implode(",", $arr_id_users);
             $posts = Posts::find(array("conditions" => "post_author IN ({$string_users})", "order" => "post_date_posted DESC"));
         } else {
             $posts = Posts::findByPost_author($user->user_id);
         }
         $vars['menus'] = $this->getSideBarMenus();
         $vars['posts'] = $posts;
         $vars['categories'] = $this->getCategoriesByPost($posts);
         $this->view->setVars($vars);
         $this->view->render("post", "listPosts");
     } else {
         $this->response->redirect(URL_PROJECT . 'admin');
     }
 }