public function build_view(HTTPRequestCustom $request)
    {
        $authorized_categories = FaqService::get_authorized_categories(Category::ROOT_CATEGORY);
        $mode = $request->get_getstring('sort', FaqUrlBuilder::DEFAULT_SORT_MODE);
        $field = $request->get_getstring('field', FaqUrlBuilder::DEFAULT_SORT_FIELD);
        $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC';
        switch ($field) {
            case 'question':
                $sort_field = FaqQuestion::SORT_ALPHABETIC;
                break;
            default:
                $sort_field = FaqQuestion::SORT_DATE;
                break;
        }
        $result = PersistenceContext::get_querier()->select('SELECT *
		FROM ' . FaqSetup::$faq_table . ' faq
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = faq.author_user_id
		WHERE approved = 0
		AND faq.id_category IN :authorized_categories
		' . (!FaqAuthorizationsService::check_authorizations()->moderation() ? ' AND faq.author_user_id = :user_id' : '') . '
		ORDER BY ' . $sort_field . ' ' . $sort_mode, array('authorized_categories' => $authorized_categories, 'user_id' => AppContext::get_current_user()->get_id()));
        $this->tpl->put_all(array('C_QUESTIONS' => $result->get_rows_count() > 0, 'C_PENDING' => true, 'C_MORE_THAN_ONE_QUESTION' => $result->get_rows_count() > 1, 'C_DISPLAY_TYPE_ANSWERS_HIDDEN' => FaqConfig::load()->is_display_type_answers_hidden(), 'QUESTIONS_NUMBER' => $result->get_rows_count()));
        while ($row = $result->fetch()) {
            $faq_question = new FaqQuestion();
            $faq_question->set_properties($row);
            $this->tpl->assign_block_vars('questions', $faq_question->get_array_tpl_vars());
        }
        $result->dispose();
        $this->build_sorting_form($field, $mode);
    }
 public function execute(HTTPRequestCustom $request)
 {
     $module_id = $request->get_getstring('module_id', '');
     if (empty($module_id)) {
         AppContext::get_response()->redirect(Environment::get_home_page());
     }
     $this->init();
     $module_category_id = $request->get_getint('module_category_id', 0);
     $feed_name = $request->get_getstring('feed_name', Feed::DEFAULT_FEED_NAME);
     $feed = new ATOM($module_id, $feed_name, $module_category_id);
     if ($feed !== null && $feed->is_in_cache()) {
         $this->tpl->put('SYNDICATION', $feed->read());
     } else {
         $eps = AppContext::get_extension_provider_service();
         if ($eps->provider_exists($module_id, FeedProvider::EXTENSION_POINT)) {
             $provider = $eps->get_provider($module_id);
             $feeds = $provider->feeds();
             $data = $feeds->get_feed_data_struct($module_category_id, $feed_name);
             if ($data === null) {
                 AppContext::get_response()->set_header('content-type', 'text/html');
                 DispatchManager::redirect(PHPBoostErrors::unexisting_element());
             } else {
                 $feed->load_data($data);
                 $feed->cache();
                 $this->tpl->put('SYNDICATION', $feed->export());
             }
         } else {
             DispatchManager::redirect(PHPBoostErrors::module_not_installed());
         }
     }
     return $this->build_response($this->tpl);
 }
    public function build_view(HTTPRequestCustom $request)
    {
        $now = new Date();
        $config = WebConfig::load();
        $authorized_categories = WebService::get_authorized_categories(Category::ROOT_CATEGORY);
        $mode = $request->get_getstring('sort', WebUrlBuilder::DEFAULT_SORT_MODE);
        $field = $request->get_getstring('field', WebUrlBuilder::DEFAULT_SORT_FIELD);
        $condition = 'WHERE relation.id_keyword = :id_keyword
		AND id_category IN :authorized_categories
		AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))';
        $parameters = array('id_keyword' => $this->get_keyword()->get_id(), 'authorized_categories' => $authorized_categories, 'timestamp_now' => $now->get_timestamp());
        $page = AppContext::get_request()->get_getint('page', 1);
        $pagination = $this->get_pagination($condition, $parameters, $field, $mode, $page);
        $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC';
        switch ($field) {
            case 'name':
                $sort_field = WebLink::SORT_ALPHABETIC;
                break;
            case 'visits':
                $sort_field = WebLink::SORT_NUMBER_VISITS;
                break;
            case 'com':
                $sort_field = WebLink::SORT_NUMBER_COMMENTS;
                break;
            case 'note':
                $sort_field = WebLink::SORT_NOTATION;
                break;
            default:
                $sort_field = WebLink::SORT_DATE;
                break;
        }
        $result = PersistenceContext::get_querier()->select('SELECT web.*, member.*, com.number_comments, notes.average_notes, notes.number_notes, note.note
		FROM ' . WebSetup::$web_table . ' web
		LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'web\' AND relation.id_in_module = web.id 
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = web.author_user_id
		LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' com ON com.id_in_module = web.id AND com.module_id = \'web\'
		LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = web.id AND notes.module_name = \'web\'
		LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = web.id AND note.module_name = \'web\' AND note.user_id = :user_id
		' . $condition . '
		ORDER BY web.privileged_partner DESC, ' . $sort_field . ' ' . $sort_mode . '
		LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('user_id' => AppContext::get_current_user()->get_id(), 'number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())));
        $this->tpl->put_all(array('C_WEBLINKS' => $result->get_rows_count() > 0, 'C_MORE_THAN_ONE_WEBLINK' => $result->get_rows_count() > 1, 'C_CATEGORY_DISPLAYED_SUMMARY' => $config->is_category_displayed_summary(), 'C_CATEGORY_DISPLAYED_TABLE' => $config->is_category_displayed_table(), 'C_COMMENTS_ENABLED' => $config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $config->is_notation_enabled(), 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'TABLE_COLSPAN' => 3 + (int) $config->are_comments_enabled() + (int) $config->is_notation_enabled(), 'CATEGORY_NAME' => $this->get_keyword()->get_name()));
        while ($row = $result->fetch()) {
            $weblink = new WebLink();
            $weblink->set_properties($row);
            $keywords = $weblink->get_keywords();
            $has_keywords = count($keywords) > 0;
            $this->tpl->assign_block_vars('weblinks', array_merge($weblink->get_array_tpl_vars(), array('C_KEYWORDS' => $has_keywords)));
            if ($has_keywords) {
                $this->build_keywords_view($keywords);
            }
        }
        $result->dispose();
        $this->build_sorting_form($field, $mode);
    }
    public function build_view(HTTPRequestCustom $request)
    {
        $now = new Date();
        $config = DownloadConfig::load();
        $authorized_categories = DownloadService::get_authorized_categories(Category::ROOT_CATEGORY);
        $mode = $request->get_getstring('sort', DownloadUrlBuilder::DEFAULT_SORT_MODE);
        $field = $request->get_getstring('field', DownloadUrlBuilder::DEFAULT_SORT_FIELD);
        $condition = 'WHERE id_category IN :authorized_categories
		' . (!DownloadAuthorizationsService::check_authorizations()->moderation() ? ' AND author_user_id = :user_id' : '') . '
		AND (approbation_type = 0 OR (approbation_type = 2 AND (start_date > :timestamp_now OR (end_date != 0 AND end_date < :timestamp_now))))';
        $parameters = array('user_id' => AppContext::get_current_user()->get_id(), 'authorized_categories' => $authorized_categories, 'timestamp_now' => $now->get_timestamp());
        $page = AppContext::get_request()->get_getint('page', 1);
        $pagination = $this->get_pagination($condition, $parameters, $field, $mode, $page);
        $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC';
        switch ($field) {
            case 'name':
                $sort_field = DownloadFile::SORT_ALPHABETIC;
                break;
            case 'author':
                $sort_field = DownloadFile::SORT_AUTHOR;
                break;
            default:
                $sort_field = DownloadFile::SORT_DATE;
                break;
        }
        $result = PersistenceContext::get_querier()->select('SELECT download.*, member.*, com.number_comments, notes.average_notes, notes.number_notes, note.note
		FROM ' . DownloadSetup::$download_table . ' download
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = download.author_user_id
		LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' com ON com.id_in_module = download.id AND com.module_id = \'download\'
		LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = download.id AND notes.module_name = \'download\'
		LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = download.id AND note.module_name = \'download\' AND note.user_id = :user_id
		' . $condition . '
		ORDER BY ' . $sort_field . ' ' . $sort_mode . '
		LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())));
        $this->tpl->put_all(array('C_FILES' => $result->get_rows_count() > 0, 'C_MORE_THAN_ONE_FILE' => $result->get_rows_count() > 1, 'C_PENDING' => true, 'C_CATEGORY_DISPLAYED_SUMMARY' => $config->is_category_displayed_summary(), 'C_CATEGORY_DISPLAYED_TABLE' => $config->is_category_displayed_table(), 'C_COMMENTS_ENABLED' => $config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $config->is_notation_enabled(), 'C_AUTHOR_DISPLAYED' => $config->is_author_displayed(), 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'TABLE_COLSPAN' => 4 + (int) $config->are_comments_enabled() + (int) $config->is_notation_enabled()));
        while ($row = $result->fetch()) {
            $downloadfile = new DownloadFile();
            $downloadfile->set_properties($row);
            $keywords = $downloadfile->get_keywords();
            $has_keywords = count($keywords) > 0;
            $this->tpl->assign_block_vars('downloadfiles', array_merge($downloadfile->get_array_tpl_vars(), array('C_KEYWORDS' => $has_keywords)));
            if ($has_keywords) {
                $this->build_keywords_view($keywords);
            }
        }
        $result->dispose();
        $this->build_sorting_form($field, $mode);
    }
 public function execute(HTTPRequestCustom $request)
 {
     $this->init();
     $change_password_pass = $request->get_getstring('key', '');
     $user_id = PHPBoostAuthenticationMethod::change_password_pass_exists($change_password_pass);
     if (!$user_id) {
         AppContext::get_response()->redirect(Environment::get_home_page());
     }
     $this->build_form();
     if ($this->submit_button->has_been_submited() && $this->form->validate()) {
         $this->change_password($user_id, $change_password_pass, $this->form->get_value('password'));
     }
     $this->tpl->put('FORM', $this->form->display());
     return $this->build_response($this->tpl, $change_password_pass);
 }
 public function execute(HTTPRequestCustom $request)
 {
     $module_id = $request->get_getstring('module_id', '');
     $user_id = $request->get_getint('user_id', 0);
     if (!empty($user_id)) {
         try {
             $this->user = UserService::get_user($user_id);
         } catch (Exception $e) {
             $error_controller = PHPBoostErrors::unexisting_element();
             DispatchManager::redirect($error_controller);
         }
     }
     if (!empty($module_id)) {
         $this->module = ModulesManager::get_module($module_id);
     }
     $this->init($request);
     return $this->build_response();
 }
    private function build_form(HTTPRequestCustom $request)
    {
        $form = new HTMLForm(__CLASS__);
        $fieldset = new FormFieldsetHTML('articles', $this->lang['articles']);
        $form->add_fieldset($fieldset);
        $fieldset->add_field(new FormFieldTextEditor('title', $this->common_lang['form.title'], $this->get_article()->get_title(), array('required' => true)));
        if (!$this->is_contributor_member()) {
            $fieldset->add_field(new FormFieldCheckbox('personalize_rewrited_title', $this->common_lang['form.rewrited_name.personalize'], $this->get_article()->rewrited_title_is_personalized(), array('events' => array('click' => '
					if (HTMLForms.getField("personalize_rewrited_title").getValue()) {
						HTMLForms.getField("rewrited_title").enable();
					} else { 
						HTMLForms.getField("rewrited_title").disable();
					}'))));
            $fieldset->add_field(new FormFieldTextEditor('rewrited_title', $this->common_lang['form.rewrited_name'], $this->get_article()->get_rewrited_title(), array('description' => $this->common_lang['form.rewrited_name.description'], 'hidden' => !$this->get_article()->rewrited_title_is_personalized()), array(new FormFieldConstraintRegex('`^[a-z0-9\\-]+$`i'))));
        }
        $search_category_children_options = new SearchCategoryChildrensOptions();
        $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS);
        $search_category_children_options->add_authorizations_bits(Category::CONTRIBUTION_AUTHORIZATIONS);
        $fieldset->add_field(ArticlesService::get_categories_manager()->get_select_categories_form_field('id_category', $this->common_lang['form.category'], $this->get_article()->get_id_category(), $search_category_children_options));
        $fieldset->add_field(new FormFieldCheckbox('enable_description', $this->lang['articles.form.description_enabled'], $this->get_article()->get_description_enabled(), array('description' => StringVars::replace_vars($this->lang['articles.form.description_enabled.description'], array('number' => ArticlesConfig::load()->get_number_character_to_cut())), 'events' => array('click' => '
					if (HTMLForms.getField("enable_description").getValue()) {
						HTMLForms.getField("description").enable();
					} else { 
						HTMLForms.getField("description").disable();
					}'))));
        $fieldset->add_field(new FormFieldRichTextEditor('description', StringVars::replace_vars($this->lang['articles.form.description'], array('number' => ArticlesConfig::load()->get_number_character_to_cut())), $this->get_article()->get_description(), array('rows' => 3, 'hidden' => !$this->get_article()->get_description_enabled())));
        $fieldset->add_field(new FormFieldRichTextEditor('contents', $this->common_lang['form.contents'], $this->get_article()->get_contents(), array('rows' => 15, 'required' => true)));
        $onclick_action = 'javascript:bbcode_page();';
        $fieldset->add_field(new FormFieldActionLink('add_page', $this->lang['articles.form.add_page'], $onclick_action, PATH_TO_ROOT . '/articles/templates/images/pagebreak.png'));
        $other_fieldset = new FormFieldsetHTML('other', $this->common_lang['form.other']);
        $form->add_fieldset($other_fieldset);
        $other_fieldset->add_field(new FormFieldCheckbox('author_name_displayed', LangLoader::get_message('config.author_displayed', 'admin-common'), $this->get_article()->get_author_name_displayed()));
        $other_fieldset->add_field(new FormFieldCheckbox('notation_enabled', LangLoader::get_message('config.notation_enabled', 'admin-common'), $this->get_article()->get_notation_enabled()));
        $other_fieldset->add_field(new FormFieldUploadPictureFile('picture', $this->common_lang['form.picture'], $this->get_article()->get_picture()->relative()));
        $other_fieldset->add_field(ArticlesService::get_keywords_manager()->get_form_field($this->get_article()->get_id(), 'keywords', $this->common_lang['form.keywords'], array('description' => $this->common_lang['form.keywords.description'])));
        $other_fieldset->add_field(new ArticlesFormFieldSelectSources('sources', $this->common_lang['form.sources'], $this->get_article()->get_sources()));
        if (!$this->is_contributor_member()) {
            $publication_fieldset = new FormFieldsetHTML('publication', $this->common_lang['form.approbation']);
            $form->add_fieldset($publication_fieldset);
            $publication_fieldset->add_field(new FormFieldDateTime('date_created', $this->common_lang['form.date.creation'], $this->get_article()->get_date_created(), array('required' => true)));
            $publication_fieldset->add_field(new FormFieldSimpleSelectChoice('publishing_state', $this->common_lang['form.approbation'], $this->get_article()->get_publishing_state(), array(new FormFieldSelectChoiceOption($this->common_lang['form.approbation.not'], Article::NOT_PUBLISHED), new FormFieldSelectChoiceOption($this->common_lang['form.approbation.now'], Article::PUBLISHED_NOW), new FormFieldSelectChoiceOption($this->common_lang['status.approved.date'], Article::PUBLISHED_DATE)), array('events' => array('change' => '
				if (HTMLForms.getField("publishing_state").getValue() == 2) {
					jQuery("#' . __CLASS__ . '_publishing_start_date_field").show();
					HTMLForms.getField("end_date_enable").enable();
				} else { 
					jQuery("#' . __CLASS__ . '_publishing_start_date_field").hide();
					HTMLForms.getField("end_date_enable").disable();
				}'))));
            $publication_fieldset->add_field(new FormFieldDateTime('publishing_start_date', $this->common_lang['form.date.start'], $this->get_article()->get_publishing_start_date() === null ? new Date() : $this->get_article()->get_publishing_start_date(), array('hidden' => $this->get_article()->get_publishing_state() != Article::PUBLISHED_DATE)));
            $publication_fieldset->add_field(new FormFieldCheckbox('end_date_enable', $this->common_lang['form.date.end.enable'], $this->get_article()->end_date_enabled(), array('hidden' => $this->get_article()->get_publishing_state() != Article::PUBLISHED_DATE, 'events' => array('click' => '
						if (HTMLForms.getField("end_date_enable").getValue()) {
							HTMLForms.getField("publishing_end_date").enable();
						} else { 
							HTMLForms.getField("publishing_end_date").disable();
						}'))));
            $publication_fieldset->add_field(new FormFieldDateTime('publishing_end_date', $this->common_lang['form.date.end'], $this->get_article()->get_publishing_end_date() === null ? new date() : $this->get_article()->get_publishing_end_date(), array('hidden' => !$this->get_article()->end_date_enabled())));
        }
        $this->build_contribution_fieldset($form);
        $fieldset->add_field(new FormFieldHidden('referrer', $request->get_url_referrer()));
        $this->submit_button = new FormButtonDefaultSubmit();
        $form->add_button($this->submit_button);
        $form->add_button(new FormButtonReset());
        $this->form = $form;
        // Positionnement à la bonne page quand on édite un article avec plusieurs pages
        if ($this->get_article()->get_id() !== null) {
            $current_page = $request->get_getstring('page', '');
            $this->tpl->put('C_PAGE', !empty($current_page));
            if (!empty($current_page)) {
                $article_contents = $this->article->get_contents();
                //If article doesn't begin with a page, we insert one
                if (substr(trim($article_contents), 0, 6) != '[page]') {
                    $article_contents = '[page]&nbsp;[/page]' . $article_contents;
                }
                //Removing [page] bbcode
                $article_contents_clean = preg_split('`\\[page\\].+\\[/page\\](.*)`Us', $article_contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
                //Retrieving pages
                preg_match_all('`\\[page\\]([^[]+)\\[/page\\]`U', $article_contents, $array_page);
                $page_name = isset($array_page[1][$current_page - 1]) && $array_page[1][$current_page - 1] != '&nbsp;' ? $array_page[1][$current_page - 1] : '';
                $this->tpl->put('PAGE', TextHelper::to_js_string($page_name));
            }
        }
    }
    private function build_view(HTTPRequestCustom $request)
    {
        $now = new Date();
        $authorized_categories = DownloadService::get_authorized_categories($this->get_category()->get_id());
        $mode = $request->get_getstring('sort', DownloadUrlBuilder::DEFAULT_SORT_MODE);
        $field = $request->get_getstring('field', DownloadUrlBuilder::DEFAULT_SORT_FIELD);
        $page = AppContext::get_request()->get_getint('page', 1);
        $subcategories_page = AppContext::get_request()->get_getint('subcategories_page', 1);
        $subcategories_number = count(DownloadService::get_categories_manager()->get_categories_cache()->get_childrens($this->get_category()->get_id()));
        $subcategories_pagination = $this->get_subcategories_pagination($subcategories_number, $this->config->get_categories_number_per_page(), $field, $mode, $page, $subcategories_page);
        //Children categories
        $result = PersistenceContext::get_querier()->select('SELECT @id_cat:= download_cats.id, download_cats.*,
		(SELECT COUNT(*) FROM ' . DownloadSetup::$download_table . '
			WHERE id_category IN (
				@id_cat,
				(SELECT GROUP_CONCAT(id SEPARATOR \',\') FROM ' . DownloadSetup::$download_cats_table . ' WHERE id_parent = @id_cat), 
				(SELECT GROUP_CONCAT(childs.id SEPARATOR \',\') FROM ' . DownloadSetup::$download_cats_table . ' parents
				INNER JOIN ' . DownloadSetup::$download_cats_table . ' childs ON parents.id = childs.id_parent
				WHERE parents.id_parent = @id_cat)
			)
			AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))
		) AS downloadfiles_number
		FROM ' . DownloadSetup::$download_cats_table . ' download_cats
		WHERE id_parent = :id_category
		AND id IN :authorized_categories
		ORDER BY id_parent, c_order
		LIMIT :number_items_per_page OFFSET :display_from', array('timestamp_now' => $now->get_timestamp(), 'id_category' => $this->category->get_id(), 'authorized_categories' => $authorized_categories, 'number_items_per_page' => $subcategories_pagination->get_number_items_per_page(), 'display_from' => $subcategories_pagination->get_display_from()));
        $nbr_cat_displayed = 0;
        while ($row = $result->fetch()) {
            $category_image = new Url($row['image']);
            $this->tpl->assign_block_vars('sub_categories_list', array('C_CATEGORY_IMAGE' => !empty($row['image']), 'C_MORE_THAN_ONE_DOWNLOADFILE' => $row['downloadfiles_number'] > 1, 'CATEGORY_NAME' => $row['name'], 'CATEGORY_IMAGE' => $category_image->rel(), 'DOWNLOADFILES_NUMBER' => $row['downloadfiles_number'], 'U_CATEGORY' => DownloadUrlBuilder::display_category($row['id'], $row['rewrited_name'])->rel()));
            $nbr_cat_displayed++;
        }
        $result->dispose();
        $nbr_column_cats = $nbr_cat_displayed > $this->config->get_columns_number_per_line() ? $this->config->get_columns_number_per_line() : $nbr_cat_displayed;
        $nbr_column_cats = !empty($nbr_column_cats) ? $nbr_column_cats : 1;
        $cats_columns_width = floor(100 / $nbr_column_cats);
        $condition = 'WHERE id_category = :id_category
		AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))';
        $parameters = array('id_category' => $this->get_category()->get_id(), 'timestamp_now' => $now->get_timestamp());
        $pagination = $this->get_pagination($condition, $parameters, $field, $mode, $page, $subcategories_page);
        $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC';
        switch ($field) {
            case 'name':
                $sort_field = DownloadFile::SORT_ALPHABETIC;
                break;
            case 'download':
                $sort_field = DownloadFile::SORT_NUMBER_DOWNLOADS;
                break;
            case 'com':
                $sort_field = DownloadFile::SORT_NUMBER_COMMENTS;
                break;
            case 'note':
                $sort_field = DownloadFile::SORT_NOTATION;
                break;
            case 'author':
                $sort_field = DownloadFile::SORT_AUTHOR;
                break;
            case 'date':
                $sort_field = DownloadFile::SORT_DATE;
                break;
            default:
                $sort_field = DownloadFile::SORT_UPDATED_DATE;
                break;
        }
        $result = PersistenceContext::get_querier()->select('SELECT download.*, member.*, com.number_comments, notes.average_notes, notes.number_notes, note.note
		FROM ' . DownloadSetup::$download_table . ' download
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = download.author_user_id
		LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' com ON com.id_in_module = download.id AND com.module_id = \'download\'
		LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = download.id AND notes.module_name = \'download\'
		LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = download.id AND note.module_name = \'download\' AND note.user_id = :user_id
		' . $condition . '
		ORDER BY ' . $sort_field . ' ' . $sort_mode . '
		LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('user_id' => AppContext::get_current_user()->get_id(), 'number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())));
        $category_description = FormatingHelper::second_parse($this->get_category()->get_description());
        $this->tpl->put_all(array('C_FILES' => $result->get_rows_count() > 0, 'C_MORE_THAN_ONE_FILE' => $result->get_rows_count() > 1, 'C_CATEGORY_DISPLAYED_SUMMARY' => $this->config->is_category_displayed_summary(), 'C_CATEGORY_DISPLAYED_TABLE' => $this->config->is_category_displayed_table(), 'C_CATEGORY_DESCRIPTION' => !empty($category_description), 'C_AUTHOR_DISPLAYED' => $this->config->is_author_displayed(), 'C_COMMENTS_ENABLED' => $this->config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $this->config->is_notation_enabled(), 'C_MODERATION' => DownloadAuthorizationsService::check_authorizations($this->get_category()->get_id())->moderation(), 'C_PAGINATION' => $pagination->has_several_pages(), 'C_CATEGORY' => true, 'C_ROOT_CATEGORY' => $this->get_category()->get_id() == Category::ROOT_CATEGORY, 'C_HIDE_NO_ITEM_MESSAGE' => $this->get_category()->get_id() == Category::ROOT_CATEGORY && ($nbr_cat_displayed != 0 || !empty($category_description)), 'C_SUB_CATEGORIES' => $nbr_cat_displayed > 0, 'C_SUBCATEGORIES_PAGINATION' => $subcategories_pagination->has_several_pages(), 'SUBCATEGORIES_PAGINATION' => $subcategories_pagination->display(), 'CATS_COLUMNS_WIDTH' => $cats_columns_width, 'PAGINATION' => $pagination->display(), 'TABLE_COLSPAN' => 4 + (int) $this->config->are_comments_enabled() + (int) $this->config->is_notation_enabled(), 'ID_CAT' => $this->get_category()->get_id(), 'CATEGORY_NAME' => $this->get_category()->get_name(), 'CATEGORY_IMAGE' => $this->get_category()->get_image()->rel(), 'CATEGORY_DESCRIPTION' => $category_description, 'U_EDIT_CATEGORY' => $this->get_category()->get_id() == Category::ROOT_CATEGORY ? DownloadUrlBuilder::configuration()->rel() : DownloadUrlBuilder::edit_category($this->get_category()->get_id())->rel()));
        while ($row = $result->fetch()) {
            $downloadfile = new DownloadFile();
            $downloadfile->set_properties($row);
            $keywords = $downloadfile->get_keywords();
            $has_keywords = count($keywords) > 0;
            $this->tpl->assign_block_vars('downloadfiles', array_merge($downloadfile->get_array_tpl_vars(), array('C_KEYWORDS' => $has_keywords)));
            if ($has_keywords) {
                $this->build_keywords_view($keywords);
            }
        }
        $result->dispose();
        $this->build_sorting_form($field, $mode);
    }