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);
 }
Example #3
0
 /**
  * layout sub-level of tree hierarchy
  * with a recursive search
  * 
  * @param object $entity an containning anchor (section or category)
  */
 private function get_sub_level($entity, $no_folders = false)
 {
     // we return a string
     $sub = '';
     // data of subelements of this entity
     $data = array();
     // html formated sub elements
     $details = array();
     if (!$no_folders) {
         $sub .= "\n" . '<ul class="tm-sub_elems">' . "\n";
     }
     $class = $this->listed_type;
     if (!$no_folders) {
         // look for sub-containers, should be either categories or sections
         $data = $entity->get_childs($class, 0, TM_MAX_ITEM, 'raw');
         // layout hierarchy
         if (isset($data[$class])) {
             foreach ($data[$class] as $elem) {
                 // transform data to obj interface
                 $elem = new $class($elem);
                 // go deeper in tree hierarchy with a recursive call
                 $deeper = $this->get_sub_level($elem);
                 // build commands menu
                 $cmd = $this->get_interactive_menu();
                 // layout sub container
                 $details[] = '<li class="tm-drag tm-drop" data-ref="' . $elem->get_reference() . '"><a class="tm-zoom" href="' . $elem->get_permalink() . '">' . '<span class="tm-folder">' . $elem->get_title() . '</span></a>' . "\n" . $cmd . $deeper . '</li>';
             }
         }
     }
     // look for section as pages, but only for categories browsing
     if ($this->listed_type == 'category' && !$this->tree_only) {
         $data = $entity->get_childs('section', 0, TM_MAX_ITEM, 'raw');
         // layout sections
         if (isset($data['section'])) {
             foreach ($data['section'] as $sec) {
                 // transform data to obj interface
                 $sec = new Section($sec);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $sec->get_reference() . '"><a href="' . $sec->get_permalink() . '" class="tm-page details">' . $sec->get_title() . '</a>' . $cmd . '</li>';
             }
         }
     }
     // look for articles and users of this level
     if (!$this->tree_only) {
         $data = $entity->get_childs('article, user', 0, TM_MAX_ITEM, 'raw');
         // layout articles
         if (isset($data['article'])) {
             foreach ($data['article'] as $art) {
                 // transform data to obj interface
                 $art = new Article($art);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $art->get_reference() . '"><a href="' . $art->get_permalink() . '" class="tm-page details">' . $art->get_title() . '</a>' . $cmd . '</li>';
             }
         }
         // layout users
         if (isset($data['user'])) {
             foreach ($data['user'] as $usr) {
                 // transform data to obj interface
                 $usr = new User($usr);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $usr->get_reference() . '"><a href="' . $usr->get_permalink() . '"class ="tm-user details">' . $usr->get_title() . '</a>' . $cmd . '</li>';
             }
         }
     }
     // combine all sub elements
     if (count($details)) {
         $sub .= implode("\n", $details);
     }
     if (!$no_folders) {
         $sub .= '</ul>' . "\n";
     }
     return $sub;
 }
Example #4
0
<?php

require_once 'init/config.php';
if (!empty($_GET['id'])) {
    $article = new Article($_GET['id']);
    $comments = $article->get_comments();
    ?>

<a href="main.php">Home Page</a>

<section>
	<article>
		<h1><?php 
    echo $article->get_title();
    ?>
</h1>
		<p><?php 
    echo $article->get_content();
    ?>
</p>
	</article>
	<hr>
</section>

<section>
	<h3>Comment</h3>

	<?php 
    if (!empty($_POST)) {
        $article->add_comment($_POST['visitor_name'], $_POST['content']);
        echo 'Your comment has been sucessfully added';