private function build_table()
 {
     $table_model = new SQLHTMLTableModel(NewsSetup::$news_table, 'table', array(new HTMLTableColumn(LangLoader::get_message('form.name', 'common'), 'name'), new HTMLTableColumn(LangLoader::get_message('category', 'categories-common'), 'id_category'), new HTMLTableColumn(LangLoader::get_message('author', 'common'), 'display_name'), new HTMLTableColumn(LangLoader::get_message('form.date.creation', 'common'), 'creation_date'), new HTMLTableColumn(LangLoader::get_message('status', 'common'), 'approbation_type'), new HTMLTableColumn('')), new HTMLTableSortingRule('creation_date', HTMLTableSortingRule::DESC));
     $table = new HTMLTable($table_model);
     $table_model->set_caption($this->lang['news.management']);
     $results = array();
     $result = $table_model->get_sql_results('news LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = news.author_user_id');
     foreach ($result as $row) {
         $news = new News();
         $news->set_properties($row);
         $category = $news->get_category();
         $user = $news->get_author_user();
         $edit_link = new LinkHTMLElement(NewsUrlBuilder::edit_news($news->get_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit');
         $delete_link = new LinkHTMLElement(NewsUrlBuilder::delete_news($news->get_id()), '', array('title' => LangLoader::get_message('delete', 'common'), 'data-confirmation' => 'delete-element'), 'fa fa-delete');
         $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true);
         $author = $user->get_id() !== User::VISITOR_LEVEL ? new LinkHTMLElement(UserUrlBuilder::profile($user->get_id()), $user->get_display_name(), !empty($user_group_color) ? array('style' => 'color: ' . $user_group_color) : array(), UserService::get_level_class($user->get_level())) : $user->get_display_name();
         $results[] = new HTMLTableRow(array(new HTMLTableRowCell(new LinkHTMLElement(NewsUrlBuilder::display_news($category->get_id(), $category->get_rewrited_name(), $news->get_id(), $news->get_rewrited_name()), $news->get_name()), 'left'), new HTMLTableRowCell(new LinkHTMLElement(NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()), $category->get_name())), new HTMLTableRowCell($author), new HTMLTableRowCell($news->get_creation_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($news->get_status()), new HTMLTableRowCell($edit_link->display() . $delete_link->display())));
     }
     $table->set_rows($table_model->get_number_of_matching_rows(), $results);
     $this->view->put('table', $table->display());
 }
 protected function get_category_url(Category $category)
 {
     return NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name());
 }
 private function generate_response(View $tpl)
 {
     $news = $this->get_news();
     $response = new SiteDisplayResponse($tpl);
     $graphical_environment = $response->get_graphical_environment();
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['news'], NewsUrlBuilder::home());
     if ($this->get_news()->get_id() === null) {
         $graphical_environment->set_page_title($this->lang['news.add'], $this->lang['news']);
         $breadcrumb->add($this->lang['news.add'], NewsUrlBuilder::add_news($news->get_id_cat()));
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['news.add']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(NewsUrlBuilder::add_news($news->get_id_cat()));
     } else {
         $graphical_environment->set_page_title($this->lang['news.edit'], $this->lang['news']);
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['news.edit']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(NewsUrlBuilder::edit_news($news->get_id()));
         $categories = array_reverse(NewsService::get_categories_manager()->get_parents($news->get_id_cat(), true));
         foreach ($categories as $id => $category) {
             if ($category->get_id() != Category::ROOT_CATEGORY) {
                 $breadcrumb->add($category->get_name(), NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
             }
         }
         $category = $news->get_category();
         $breadcrumb->add($news->get_name(), NewsUrlBuilder::display_news($category->get_id(), $category->get_rewrited_name(), $news->get_id(), $news->get_rewrited_name()));
         $breadcrumb->add($this->lang['news.edit'], NewsUrlBuilder::edit_news($news->get_id()));
     }
     return $response;
 }
예제 #4
0
 public function get_array_tpl_vars()
 {
     $news_config = NewsConfig::load();
     $category = $this->get_category();
     $contents = FormatingHelper::second_parse($this->contents);
     $description = $this->get_real_short_contents();
     $user = $this->get_author_user();
     $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true);
     $number_comments = CommentsService::get_number_comments('news', $this->id);
     $sources = $this->get_sources();
     $nbr_sources = count($sources);
     return array('C_VISIBLE' => $this->is_visible(), 'C_EDIT' => $this->is_authorized_to_edit(), 'C_DELETE' => $this->is_authorized_to_delete(), 'C_PICTURE' => $this->has_picture(), 'C_USER_GROUP_COLOR' => !empty($user_group_color), 'C_AUTHOR_DISPLAYED' => $news_config->get_author_displayed(), 'C_READ_MORE' => !$this->get_short_contents_enabled() && $description != $contents && strlen($description) >= $news_config->get_number_character_to_cut(), 'C_SOURCES' => $nbr_sources > 0, 'ID' => $this->id, 'NAME' => $this->name, 'CONTENTS' => $contents, 'DESCRIPTION' => $description, 'DATE' => $this->creation_date->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE_TEXT), 'DATE_DAY' => $this->creation_date->get_day(), 'DATE_MONTH' => $this->creation_date->get_month(), 'DATE_YEAR' => $this->creation_date->get_year(), 'DATE_ISO8601' => $this->creation_date->format(Date::FORMAT_ISO8601), 'DATE_DAY' => $this->creation_date->get_day(), 'DATE_MONTH' => $this->creation_date->get_month(), 'DATE_YEAR' => $this->creation_date->get_year(), 'STATUS' => $this->get_status(), 'C_AUTHOR_EXIST' => $user->get_id() !== User::VISITOR_LEVEL, 'PSEUDO' => $user->get_display_name(), 'USER_LEVEL_CLASS' => UserService::get_level_class($user->get_level()), 'USER_GROUP_COLOR' => $user_group_color, 'C_COMMENTS' => !empty($number_comments), 'L_COMMENTS' => CommentsService::get_lang_comments('news', $this->id), 'NUMBER_COMMENTS' => CommentsService::get_number_comments('news', $this->id), 'C_ROOT_CATEGORY' => $category->get_id() == Category::ROOT_CATEGORY, 'CATEGORY_ID' => $category->get_id(), 'CATEGORY_NAME' => $category->get_name(), 'CATEGORY_DESCRIPTION' => $category->get_description(), 'CATEGORY_IMAGE' => $category->get_image()->rel(), 'U_EDIT_CATEGORY' => $category->get_id() == Category::ROOT_CATEGORY ? NewsUrlBuilder::configuration()->rel() : NewsUrlBuilder::edit_category($category->get_id())->rel(), 'U_SYNDICATION' => SyndicationUrlBuilder::rss('news', $this->id_cat)->rel(), 'U_AUTHOR_PROFILE' => UserUrlBuilder::profile($this->get_author_user()->get_id())->rel(), 'U_LINK' => NewsUrlBuilder::display_news($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel(), 'U_CATEGORY' => NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())->rel(), 'U_EDIT' => NewsUrlBuilder::edit_news($this->id)->rel(), 'U_DELETE' => NewsUrlBuilder::delete_news($this->id)->rel(), 'U_PICTURE' => $this->get_picture()->rel(), 'U_COMMENTS' => NewsUrlBuilder::display_comments_news($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel());
 }
 private function generate_response()
 {
     $response = new SiteDisplayResponse($this->tpl);
     $graphical_environment = $response->get_graphical_environment();
     $graphical_environment->set_page_title($this->get_category()->get_name(), $this->lang['news']);
     $graphical_environment->get_seo_meta_data()->set_description($this->get_category()->get_description());
     $graphical_environment->get_seo_meta_data()->set_canonical_url(NewsUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), AppContext::get_request()->get_getint('page', 1)));
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['news'], NewsUrlBuilder::home());
     $categories = array_reverse(NewsService::get_categories_manager()->get_parents($this->get_category()->get_id(), true));
     foreach ($categories as $id => $category) {
         if ($category->get_id() != Category::ROOT_CATEGORY) {
             $breadcrumb->add($category->get_name(), NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
         }
     }
     return $response;
 }