private function build_table()
    {
        $table_model = new SQLHTMLTableModel(ArticlesSetup::$articles_table, 'table', array(new HTMLTableColumn(LangLoader::get_message('form.title', 'common'), 'title'), 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'), 'date_created'), new HTMLTableColumn(LangLoader::get_message('status', 'common'), 'published'), new HTMLTableColumn('')), new HTMLTableSortingRule('date_created', HTMLTableSortingRule::DESC));
        $table = new HTMLTable($table_model);
        $table_model->set_caption($this->lang['articles_management']);
        $results = array();
        $result = $table_model->get_sql_results('articles
			LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = articles.id AND notes.module_name = \'articles\'
			LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = articles.id AND note.module_name = \'articles\' AND note.user_id = ' . AppContext::get_current_user()->get_id() . '
			LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = articles.author_user_id', array('*', 'articles.id'));
        foreach ($result as $row) {
            $article = new Article();
            $article->set_properties($row);
            $category = $article->get_category();
            $user = $article->get_author_user();
            $edit_link = new LinkHTMLElement(ArticlesUrlBuilder::edit_article($article->get_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit');
            $delete_link = new LinkHTMLElement(ArticlesUrlBuilder::delete_article($article->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();
            $br = new BrHTMLElement();
            $dates = '';
            if ($article->get_publishing_start_date() != null && $article->get_publishing_end_date() != null) {
                $dates = LangLoader::get_message('form.date.start', 'common') . ' ' . $article->get_publishing_start_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) . $br->display() . LangLoader::get_message('form.date.end', 'common') . ' ' . $article->get_publishing_end_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE);
            } else {
                if ($article->get_publishing_start_date() != null) {
                    $dates = $article->get_publishing_start_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE);
                } else {
                    if ($article->get_publishing_end_date() != null) {
                        $dates = LangLoader::get_message('until', 'main') . ' ' . $article->get_publishing_end_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE);
                    }
                }
            }
            $start_and_end_dates = new SpanHTMLElement($dates, array(), 'smaller');
            $results[] = new HTMLTableRow(array(new HTMLTableRowCell(new LinkHTMLElement(ArticlesUrlBuilder::display_article($category->get_id(), $category->get_rewrited_name(), $article->get_id(), $article->get_rewrited_title()), $article->get_title()), 'left'), new HTMLTableRowCell(new LinkHTMLElement(ArticlesUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()), $category->get_name())), new HTMLTableRowCell($author), new HTMLTableRowCell($article->get_date_created()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($article->get_status() . $br->display() . ($dates ? $start_and_end_dates->display() : '')), 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 contribution_actions(Article $article, $id_article)
 {
     if ($article->get_id() === null) {
         if ($this->is_contributor_member()) {
             $contribution = new Contribution();
             $contribution->set_id_in_module($id_article);
             $contribution->set_description(stripslashes($this->form->get_value('contribution_description')));
             $contribution->set_entitled($article->get_title());
             $contribution->set_fixing_url(ArticlesUrlBuilder::edit_article($id_article)->relative());
             $contribution->set_poster_id(AppContext::get_current_user()->get_id());
             $contribution->set_module('articles');
             $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(ArticlesService::get_categories_manager()->get_heritated_authorizations($article->get_id_category(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
             ContributionService::save_contribution($contribution);
         }
     } else {
         $corresponding_contributions = ContributionService::find_by_criteria('articles', $id_article);
         if (count($corresponding_contributions) > 0) {
             $article_contribution = $corresponding_contributions[0];
             $article_contribution->set_status(Event::EVENT_STATUS_PROCESSED);
             ContributionService::save_contribution($article_contribution);
         }
     }
     $article->set_id($id_article);
 }
 public static function update_number_view(Article $article)
 {
     self::$db_querier->update(ArticlesSetup::$articles_table, array('number_view' => $article->get_number_view()), 'WHERE id=:id', array('id' => $article->get_id()));
 }
Example #4
0
File: post.php Project: bsamel/bavn
<?php

session_start();
if (!isset($_SESSION['login'])) {
    header('location: accueil.php');
} else {
    if (!empty($_FILES['picture']) && !($_FILES['picture']['error'] > 0) || empty($_FILES['picture']['name'])) {
        include_once './class/ManagerMember.php';
        include_once './class/Article.php';
        $pseudo_receiver = $_POST['where'];
        $id_receiver = ManagerMember::get_member($pseudo_receiver)['ID'];
        $title = $_POST['article_title'];
        $content = $_POST['my_article'];
        $id_author = ManagerMember::get_member($_SESSION['login'])['ID'];
        if (!empty($_FILES['picture']['name'])) {
            echo 'ici';
            $new_article = new Article($title, $content, $id_receiver, $id_author, 1, 0, 0, 0);
            $new_article->add();
            move_uploaded_file($_FILES['picture']['tmp_name'], "./articles/pictures/" . $new_article->get_id());
        } else {
            echo 'la';
            $new_article = new Article($title, $content, $id_receiver, $id_author, 0, 0, 0, 0);
            $new_article->add();
        }
        unset($new_article);
        header('location: ./users/' . $pseudo_receiver . '.php');
        //redirection vers le mur où on a posté l'article
    }
}