public function execute(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id) && AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) { try { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id = :id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } if ($this->downloadfile !== null && $this->downloadfile->is_visible()) { if (!PersistenceContext::get_querier()->row_exists(PREFIX . 'events', 'WHERE id_in_module=:id_in_module AND module=\'download\' AND current_status = 0', array('id_in_module' => $this->downloadfile->get_id()))) { $contribution = new Contribution(); $contribution->set_id_in_module($this->downloadfile->get_id()); $contribution->set_entitled(StringVars::replace_vars(LangLoader::get_message('contribution.deadlink', 'common'), array('link_name' => $this->downloadfile->get_name()))); $contribution->set_fixing_url(DownloadUrlBuilder::edit($this->downloadfile->get_id())->relative()); $contribution->set_description(LangLoader::get_message('contribution.deadlink_explain', 'common')); $contribution->set_poster_id(AppContext::get_current_user()->get_id()); $contribution->set_module('download'); $contribution->set_type('alert'); $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(DownloadService::get_categories_manager()->get_heritated_authorizations($this->downloadfile->get_id_category(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT)); ContributionService::save_contribution($contribution); } DispatchManager::redirect(new UserContributionSuccessController()); } else { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } }
private function build_table() { $table_model = new SQLHTMLTableModel(DownloadSetup::$download_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['download.management']); $results = array(); $result = $table_model->get_sql_results('download 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 = ' . AppContext::get_current_user()->get_id() . ' LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = download.author_user_id', array('*', 'download.id')); foreach ($result as $row) { $downloadfile = new DownloadFile(); $downloadfile->set_properties($row); $category = $downloadfile->get_category(); $user = $downloadfile->get_author_user(); $edit_link = new LinkHTMLElement(DownloadUrlBuilder::edit($downloadfile->get_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit'); $delete_link = new LinkHTMLElement(DownloadUrlBuilder::delete($downloadfile->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(DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $downloadfile->get_id(), $downloadfile->get_rewrited_name()), $downloadfile->get_name()), 'left'), new HTMLTableRowCell(new LinkHTMLElement(DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()), $category->get_name())), new HTMLTableRowCell($author), new HTMLTableRowCell($downloadfile->get_creation_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($downloadfile->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) { $downloadfile = $this->get_downloadfile(); $response = new SiteDisplayResponse($tpl); $graphical_environment = $response->get_graphical_environment(); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['module_title'], DownloadUrlBuilder::home()); if ($downloadfile->get_id() === null) { $graphical_environment->set_page_title($this->lang['download.add'], $this->lang['module_title']); $breadcrumb->add($this->lang['download.add'], DownloadUrlBuilder::add($downloadfile->get_id_category())); $graphical_environment->get_seo_meta_data()->set_description($this->lang['download.add']); $graphical_environment->get_seo_meta_data()->set_canonical_url(DownloadUrlBuilder::add($downloadfile->get_id_category())); } else { $graphical_environment->set_page_title($this->lang['download.edit'], $this->lang['module_title']); $graphical_environment->get_seo_meta_data()->set_description($this->lang['download.edit']); $graphical_environment->get_seo_meta_data()->set_canonical_url(DownloadUrlBuilder::edit($downloadfile->get_id())); $categories = array_reverse(DownloadService::get_categories_manager()->get_parents($downloadfile->get_id_category(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } $category = $downloadfile->get_category(); $breadcrumb->add($downloadfile->get_name(), DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $downloadfile->get_id(), $downloadfile->get_rewrited_name())); $breadcrumb->add($this->lang['download.edit'], DownloadUrlBuilder::edit($downloadfile->get_id())); } return $response; }
public function get_array_tpl_vars() { $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('download', $this->id); return array('C_VISIBLE' => $this->is_visible(), 'C_EDIT' => $this->is_authorized_to_edit(), 'C_DELETE' => $this->is_authorized_to_delete(), 'C_READ_MORE' => !$this->is_short_contents_enabled() && $description != $contents && strlen($description) >= DownloadConfig::NUMBER_CARACTERS_BEFORE_CUT, 'C_SIZE' => !empty($this->size), 'C_PICTURE' => $this->has_picture(), 'C_CUSTOM_AUTHOR_DISPLAY_NAME' => $this->is_author_display_name_enabled(), 'C_USER_GROUP_COLOR' => !empty($user_group_color), 'C_UPDATED_DATE' => $this->has_updated_date(), 'ID' => $this->id, 'NAME' => $this->name, 'SIZE' => $this->formated_size, 'CONTENTS' => $contents, 'DESCRIPTION' => $description, 'DATE' => $this->creation_date->format(Date::FORMAT_DAY_MONTH_YEAR), 'DATE_DAY' => $this->creation_date->get_day(), 'DATE_MONTH' => $this->creation_date->get_month(), 'DATE_YEAR' => $this->creation_date->get_year(), 'DATE_DAY_MONTH' => $this->creation_date->format(Date::FORMAT_DAY_MONTH), 'DATE_ISO8601' => $this->creation_date->format(Date::FORMAT_ISO8601), 'UPDATED_DATE' => $this->updated_date !== null ? $this->updated_date->format(Date::FORMAT_DAY_MONTH_YEAR) : '', 'UPDATED_DATE_ISO8601' => $this->updated_date !== null ? $this->updated_date->format(Date::FORMAT_ISO8601) : '', 'STATUS' => $this->get_status(), 'CUSTOM_AUTHOR_DISPLAY_NAME' => $this->author_display_name, '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, 'NUMBER_DOWNLOADS' => $this->number_downloads, 'L_DOWNLOADED_TIMES' => StringVars::replace_vars(LangLoader::get_message('downloaded_times', 'common', 'download'), array('number_downloads' => $this->number_downloads)), 'STATIC_NOTATION' => NotationService::display_static_image($this->get_notation()), 'NOTATION' => NotationService::display_active_image($this->get_notation()), 'C_COMMENTS' => !empty($number_comments), 'L_COMMENTS' => CommentsService::get_lang_comments('download', $this->id), 'NUMBER_COMMENTS' => CommentsService::get_number_comments('download', $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 ? DownloadUrlBuilder::configuration()->rel() : DownloadUrlBuilder::edit_category($category->get_id())->rel(), 'U_SYNDICATION' => SyndicationUrlBuilder::rss('download', $this->id_category)->rel(), 'U_AUTHOR_PROFILE' => UserUrlBuilder::profile($this->get_author_user()->get_id())->rel(), 'U_LINK' => DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel(), 'U_DOWNLOAD' => DownloadUrlBuilder::download($this->id)->rel(), 'U_DEADLINK' => DownloadUrlBuilder::dead_link($this->id)->rel(), 'U_CATEGORY' => DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())->rel(), 'U_EDIT' => DownloadUrlBuilder::edit($this->id)->rel(), 'U_DELETE' => DownloadUrlBuilder::delete($this->id)->rel(), 'U_PICTURE' => $this->get_picture()->rel(), 'U_COMMENTS' => DownloadUrlBuilder::display_comments($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel()); }