CMS  Version 3.9
forum_view.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::usingFile("framework/data_view.inc");
40 
42 {
43  var $fora;
44  var $id;
45  var $table;
48  var $reorder;
49 
50  function ForumListView($fora, $forumLink, $messageLink, $id = "forum_list", $reorder = false)
51  {
52  $this->fora = $fora;
53  $this->id = $id;
54 
55  $this->forumLink = $forumLink;
56  $this->messageLink = $messageLink;
57 
58  $this->table = new DataListView($fora, $id);
59 
60 
61  $this->table->column("Title", array($this, formatTitle), true, "width: 40%")
62  ->column("Last Post", array($this, formatLastPost), true, "width: 40%")
63  ->column("Topics", "{topics}", true, "width: 10%;text-align: center")
64  ->column("Posts", "{posts}", true, "width: 10%;text-align: center");
65 
66  if (checkRole("admin") && $reorder)
67  {
68  $this->table->enableDragReorder("/action/forum/reorder_forums");
69  }
70  else
71  {
72  $this->table->pageSize = Settings::getValue("forum", "forum_list_items_per_page");
73  $this->table->filter = true;
74  }
75 
76  $this->table->emptyMessage = "No fora have been created";
77  }
78 
79  function formatTitle($item)
80  {
81  $text = $item->format("<a href='{$this->forumLink}?forum_id={forum_id}'>{title|No Title}</a>");
82  if ($item->teaser)
83  {
84  $text .= "<br/><span class='small'>{$item->teaser}</span>";
85  }
86  return $text;
87  }
88 
89  function formatLastPost($item)
90  {
91  $lastPost = $item->LastPost();
92  if (!$lastPost) return "<em>No posts</em>";
93  $user = $lastPost->Author();
94  $userProfile = ForumManager::formatUserProfile($user);
95 
96  $title = $lastPost->title ? $lastPost->title : "No Title";
97 
98  return "<a href='{$this->messageLink}?forum_id={$lastPost->forum_id}&topic_id={$lastPost->topic_id}'>{$title}</a><br/>".
99  "<span class='small'>by ".$userProfile." ({$lastPost->date_posted})</span>";
100 
101  }
102 
103  function writeScript()
104  {
105  return $this->table->writeScript();
106  }
107 
108  function drawView()
109  {
110  $this->table->drawView();
111  }
112 }
113 
114 
116 {
117  var $forum;
118  var $topics;
120  var $table;
122  var $width;
124 
126  {
127  $this->forum = $forum;
128  $this->topicLink = $topicLink;
129 
130  $msgTable = new ForumMessage();
131  $this->topics = $this->forum->Topics("WHERE message_id not in (select message_id from {$msgTable->table} where deleted=true)");
132  $this->messages = indexedQuery(ForumMessage, "WHERE forum_id={$forum->forum_id} AND deleted=false AND parent_id=0", "topic_id");
133 
134  $this->table = new DataListView($this->topics, "topic_list");
135  $this->table->column("Title", array($this, formatTitle), true, "width: 40%")
136  ->column("Last Post", array($this, formatLastPost), true, "width: 40%")
137  ->column("Views", "{views}", true, "width: 10%; text-align: center")
138  ->column("Replies", "{countReplies()}", true, "width: 10%; text-align: center");
139  $this->table->emptyMessage = "No topics have been started in this discussion forum";
140  $this->table->filter = true;
141  $this->table->pageSize = Settings::getValue("forum", "forum_topics_per_page");
142 
143  $this->subscriptionView = new ForumSubscriptionHelper($this->forum);
144 
145  }
146 
147  function formatTitle($topic)
148  {
149  if (!array_key_exists($topic->topic_id, $this->messages)) return "";
150 
151  $message = $this->messages[$topic->topic_id];
152  $user = $message->Author();
153  $userProfile = ForumManager::formatUserProfile($user);
154 
155  $title = $message->title ? $message->title : "No Title";
156 
157  return "<a href='{$this->topicLink}?forum_id={$topic->forum_id}&topic_id={$topic->topic_id}'>{$title}</a><br/><span class='small'>(Created by ".$userProfile.")</span>";
158  }
159 
161  {
162  $lastPost = $topic->LastPost();
163  if (!$lastPost) return "<em>No posts</em>";
164  $user = $lastPost->Author();
165 
166  $userProfile = ForumManager::formatUserProfile($user);
167 
168  $title = $lastPost->title ? $lastPost->title : "No Title";
169 
170  return "<a href='{$this->topicLink}?forum_id={$lastPost->forum_id}&topic_id={$lastPost->topic_id}'>{$title}</a><br/>".
171  "<span class='small'>by ".$userProfile." ({$lastPost->date_posted})</span>";
172  }
173 
174  function writeScript()
175  {
176  $script = $this->table->writeScript();
177  $script .= $this->subscriptionView->writeScript();
178 
179  return $script;
180  }
181 
182  function drawView()
183  {
184  echo "<div style='width: {$this->width}'>";
185 ?>
186  <form method="get" action="forum_search_by_author">
187  <input type="hidden" name="forum_id" value="<?echo $this->forum->forum_id?>"/>
188  <label for="author">Search by Author</label> <input type="text" name="author" style="width: 200px"> <input class='button' type='submit' value="Search"/>
189  </form>
190 <?
191  $this->subscriptionView->drawLink();
192  $this->table->drawView();
193  echo "</div>";
194  }
195 
196 } // end class Forumview?>
$helpTree style
Definition: tree.inc:46
$form action
Definition: edit.inc:67
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
formatTitle($topic)
Definition: forum_view.inc:147
formatLastPost($topic)
Definition: forum_view.inc:160
ForumDetailsView($forum, $topicLink)
Definition: forum_view.inc:125
ForumListView($fora, $forumLink, $messageLink, $id="forum_list", $reorder=false)
Definition: forum_view.inc:50
formatLastPost($item)
Definition: forum_view.inc:89
formatTitle($item)
Definition: forum_view.inc:79
static formatUserProfile($u)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $user
$message
Definition: mail_to.inc:49
$topic
Definition: topic_form.inc:42