public function get_feed_data_struct($idcat = 0, $name = '')
    {
        if (NewsService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) {
            $querier = PersistenceContext::get_querier();
            $category = NewsService::get_categories_manager()->get_categories_cache()->get_category($idcat);
            $site_name = GeneralConfig::load()->get_site_name();
            $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name;
            $feed_module_name = LangLoader::get_message('feed.name', 'common', 'news');
            $data = new FeedData();
            $data->set_title($feed_module_name . ' - ' . $site_name);
            $data->set_date(new Date());
            $data->set_link(SyndicationUrlBuilder::rss('news', $idcat));
            $data->set_host(HOST);
            $data->set_desc($feed_module_name . ' - ' . $site_name);
            $data->set_lang(LangLoader::get_message('xml_lang', 'main'));
            $data->set_auth_bit(Category::READ_AUTHORIZATIONS);
            $categories = NewsService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
            $ids_categories = array_keys($categories);
            $now = new Date();
            $results = $querier->select('SELECT news.id, news.id_category, news.name, news.rewrited_name, news.contents, news.short_contents, news.creation_date, news.picture_url, cat.rewrited_name AS rewrited_name_cat
				FROM ' . NewsSetup::$news_table . ' news
				LEFT JOIN ' . NewsSetup::$news_cats_table . ' cat ON cat.id = news.id_category
				WHERE id_category IN :cats_ids
				AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0))) 
				ORDER BY news.creation_date DESC', array('cats_ids' => $ids_categories, 'timestamp_now' => $now->get_timestamp()));
            foreach ($results as $row) {
                $row['rewrited_name_cat'] = !empty($row['id_category']) ? $row['rewrited_name_cat'] : 'root';
                $link = NewsUrlBuilder::display_news($row['id_category'], $row['rewrited_name_cat'], $row['id'], $row['rewrited_name']);
                $item = new FeedItem();
                $item->set_title($row['name']);
                $item->set_link($link);
                $item->set_guid($link);
                $item->set_desc(FormatingHelper::second_parse($row['contents']));
                $item->set_date(new Date($row['creation_date'], Timezone::SERVER_TIMEZONE));
                $item->set_image_url($row['picture_url']);
                $item->set_auth(NewsService::get_categories_manager()->get_heritated_authorizations($row['id_category'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
                $data->add_item($item);
            }
            $results->dispose();
            return $data;
        }
    }
 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());
 }
 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());
 }