/** * Carrega a tela principal do backend */ public function indexAction() { $this->session->start(); if ($this->session->get("user_id") != NULL) { $posts = Posts::findByPost_status_id(1); $vars = $this->getUserLoggedInformation(); $vars += $this->getApiSocialsData(); //Busca as últimas 15 postagens $posts = Posts::find(array("conditions" => "post_status_id = :status:", "order" => "post_date_posted DESC", "limit" => 15, "bind" => array("status" => 1))); //Conta o total de postagens existentes; $vars['total_posts'] = count($posts); //Cria uma prévia do conteúdo da postagem foreach ($posts as $post) { $post_content[$post->post_id] = substr(strip_tags($post->post_content), 0, 500) . "..."; } $vars['posts'] = $posts; $vars['post_content'] = $post_content; $vars['menus'] = $this->getSideBarMenus(); $this->view->setVars($vars); $this->view->render('dashboard', 'index'); } else { $this->response->redirect(URL_PROJECT . "admin"); } }
/** * 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'); } }