public function get_root_category() { $root = new RichRootCategory(); $root->set_authorizations(DownloadConfig::load()->get_authorizations()); $root->set_description(DownloadConfig::load()->get_root_category_description()); return $root; }
/** * {@inheritdoc} */ public function synchronize() { $this->downloadfiles = array(); $now = new Date(); $config = DownloadConfig::load(); $result = PersistenceContext::get_querier()->select(' SELECT download.*, notes.average_notes, notes.number_notes FROM ' . DownloadSetup::$download_table . ' download LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = download.id AND notes.module_name = \'download\' WHERE (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0))) ORDER BY ' . $config->get_sort_type() . ' DESC LIMIT :files_number_in_menu OFFSET 0', array('timestamp_now' => $now->get_timestamp(), 'files_number_in_menu' => (int) $config->get_files_number_in_menu())); while ($row = $result->fetch()) { $this->downloadfiles[$row['id']] = $row; } $result->dispose(); }
private function build_view() { $config = DownloadConfig::load(); $downloadfile = $this->get_downloadfile(); $category = $downloadfile->get_category(); $keywords = $downloadfile->get_keywords(); $has_keywords = count($keywords) > 0; $this->tpl->put_all(array_merge($downloadfile->get_array_tpl_vars(), array('C_AUTHOR_DISPLAYED' => $config->is_author_displayed(), 'C_COMMENTS_ENABLED' => $config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $config->is_notation_enabled(), 'C_KEYWORDS' => $has_keywords, 'NOT_VISIBLE_MESSAGE' => MessageHelper::display(LangLoader::get_message('element.not_visible', 'status-messages-common'), MessageHelper::WARNING)))); if ($config->are_comments_enabled()) { $comments_topic = new DownloadCommentsTopic($downloadfile); $comments_topic->set_id_in_module($downloadfile->get_id()); $comments_topic->set_url(DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $downloadfile->get_id(), $downloadfile->get_rewrited_name())); $this->tpl->put('COMMENTS', $comments_topic->display()); } if ($has_keywords) { $this->build_keywords_view($keywords); } }
private function save() { $this->config->set_items_number_per_page($this->form->get_value('items_number_per_page')); $this->config->set_categories_number_per_page($this->form->get_value('categories_number_per_page')); $this->config->set_columns_number_per_line($this->form->get_value('columns_number_per_line')); $this->config->set_category_display_type($this->form->get_value('category_display_type')->get_raw_value()); if ($this->config->get_category_display_type() != DownloadConfig::DISPLAY_ALL_CONTENT) { if ($this->form->get_value('display_descriptions_to_guests')) { $this->config->display_descriptions_to_guests(); } else { $this->config->hide_descriptions_to_guests(); } } if ($this->form->get_value('author_displayed')) { $this->config->display_author(); } else { $this->config->hide_author(); } if ($this->form->get_value('comments_enabled')) { $this->config->enable_comments(); } else { $this->config->disable_comments(); } if ($this->form->get_value('notation_enabled')) { $this->config->enable_notation(); $this->config->set_notation_scale($this->form->get_value('notation_scale')); if ($this->form->get_value('notation_scale') != $this->config->get_notation_scale()) { NotationService::update_notation_scale('download', $this->config->get_notation_scale(), $this->form->get_value('notation_scale')); } } else { $this->config->disable_notation(); } $this->config->set_root_category_description($this->form->get_value('root_category_description')); $this->config->set_sort_type($this->form->get_value('sort_type')->get_raw_value()); $this->config->set_files_number_in_menu($this->form->get_value('files_number_in_menu')); $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array()); DownloadConfig::save(); DownloadService::get_categories_manager()->regenerate_cache(); DownloadCache::invalidate(); }
public function get_menu_content() { //Create file template $tpl = new FileTemplate('download/DownloadModuleMiniMenu.tpl'); //Assign the lang file to the tpl $tpl->add_lang(LangLoader::get('common', 'download')); //Load module config $config = DownloadConfig::load(); //Load module cache $download_cache = DownloadCache::load(); //Load categories cache $categories_cache = DownloadService::get_categories_manager()->get_categories_cache(); $downloadfiles = $download_cache->get_downloadfiles(); $tpl->put_all(array('C_FILES' => !empty($downloadfiles), 'C_SORT_BY_DATE' => $config->is_sort_type_date(), 'C_SORT_BY_NOTATION' => $config->is_sort_type_notation(), 'C_SORT_BY_NUMBER_DOWNLOADS' => $config->is_sort_type_number_downloads())); $displayed_position = 1; foreach ($downloadfiles as $file) { $downloadfile = new DownloadFile(); $downloadfile->set_properties($file); $tpl->assign_block_vars('downloadfiles', array_merge($downloadfile->get_array_tpl_vars(), array('DISPLAYED_POSITION' => $displayed_position))); $displayed_position++; } return $tpl->render(); }
private function init() { $this->config = DownloadConfig::load(); $this->lang = LangLoader::get('common', 'download'); $this->common_lang = LangLoader::get('common'); }
public function set_properties(array $properties) { $this->id = $properties['id']; $this->id_category = $properties['id_category']; $this->name = $properties['name']; $this->rewrited_name = $properties['rewrited_name']; $this->url = new Url($properties['url']); $this->size = $properties['size']; $this->contents = $properties['contents']; $this->short_contents = $properties['short_contents']; $this->approbation_type = $properties['approbation_type']; $this->start_date = !empty($properties['start_date']) ? new Date($properties['start_date'], Timezone::SERVER_TIMEZONE) : null; $this->end_date = !empty($properties['end_date']) ? new Date($properties['end_date'], Timezone::SERVER_TIMEZONE) : null; $this->end_date_enabled = !empty($properties['end_date']); $this->creation_date = new Date($properties['creation_date'], Timezone::SERVER_TIMEZONE); $this->updated_date = !empty($properties['updated_date']) ? new Date($properties['updated_date'], Timezone::SERVER_TIMEZONE) : null; $this->number_downloads = $properties['number_downloads']; $this->picture_url = new Url($properties['picture_url']); $user = new User(); if (!empty($properties['user_id'])) { $user->set_properties($properties); } else { $user->init_visitor_user(); } $this->set_author_user($user); $notation = new Notation(); $notation->set_module_name('download'); $notation->set_notation_scale(DownloadConfig::load()->get_notation_scale()); $notation->set_id_in_module($properties['id']); $notation->set_number_notes($properties['number_notes']); $notation->set_average_notes($properties['average_notes']); $notation->set_user_already_noted(!empty($properties['note'])); $this->notation = $notation; $this->author_display_name = !empty($properties['author_display_name']) ? $properties['author_display_name'] : $this->author_user->get_display_name(); $this->author_display_name_enabled = !empty($properties['author_display_name']); $units = array(LangLoader::get_message('unit.bytes', 'common'), LangLoader::get_message('unit.kilobytes', 'common'), LangLoader::get_message('unit.megabytes', 'common'), LangLoader::get_message('unit.gigabytes', 'common')); $power = $this->size > 0 ? floor(log($this->size, 1024)) : 0; $this->formated_size = (double) number_format($this->size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power]; }
private function get_pagination($condition, $parameters, $field, $mode, $page, $subcategories_page) { $downloadfiles_number = DownloadService::count($condition, $parameters); $pagination = new ModulePagination($page, $downloadfiles_number, (int) DownloadConfig::load()->get_items_number_per_page()); $pagination->set_url(DownloadUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), $field, $mode, '%d', $subcategories_page)); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
/** * @desc Return the authorized categories. */ public static function get_authorized_categories($current_id_category) { $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); if (AppContext::get_current_user()->is_guest()) { $search_category_children_options->set_allow_only_member_level_authorizations(DownloadConfig::load()->are_descriptions_displayed_to_guests()); } $categories = self::get_categories_manager()->get_childrens($current_id_category, $search_category_children_options, true); return array_keys($categories); }
private function get_pagination($condition, $parameters, $field, $mode, $page) { $result = PersistenceContext::get_querier()->select_single_row_query('SELECT COUNT(*) AS downloadfiles_number FROM ' . DownloadSetup::$download_table . ' download LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'download\' AND relation.id_in_module = download.id ' . $condition, $parameters); $pagination = new ModulePagination($page, $result['downloadfiles_number'], (int) DownloadConfig::load()->get_items_number_per_page()); $pagination->set_url(DownloadUrlBuilder::display_tag($this->get_keyword()->get_rewrited_name(), $field, $mode, '%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }