Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AuthorColumn
  • CommentColumn
  • NodeColumn
  • StatusColumn
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Comments;
 13 
 14 use ICanBoogie\ActiveRecord\Query;
 15 
 16 class ManageBlock extends \Icybee\ManageBlock
 17 {
 18     static protected function add_assets(\Brickrouge\Document $document)
 19     {
 20         parent::add_assets($document);
 21 
 22         $document->css->add(DIR . 'public/admin.css');
 23         $document->js->add(DIR . 'public/admin.js');
 24     }
 25 
 26     public function __construct($module, array $attributes=array())
 27     {
 28         parent::__construct
 29         (
 30             $module, $attributes + array
 31             (
 32                 self::T_COLUMNS_ORDER => array
 33                 (
 34                     'comment', 'url', 'status', 'author', 'nid', 'created_at'
 35                 ),
 36 
 37                 self::T_ORDER_BY => array('created_at', 'desc'),
 38             )
 39         );
 40     }
 41 
 42     /**
 43      * Adds the following columns:
 44      *
 45      * - `comment`: An instance of {@link ManageBlock\CommentColumn}.
 46      * - `url`: An instance of {@link ManageBlock\URLColumn}.
 47      * - `status`: An instance of {@link ManageBlock\StatusColumn}.
 48      * - `author`: An instance of {@link ManageBlock\AuthorColumn}.
 49      * - `nid`: An instance of {@link ManageBlock\NodeColumn}.
 50      * - `created`: An instance of {@link \Icybee\ManageBlock\DateTimeColumn}.
 51      *
 52      * @return array
 53      */
 54     protected function get_available_columns()
 55     {
 56         return array_merge(parent::get_available_columns(), array
 57         (
 58             'comment'           => __CLASS__ . '\CommentColumn',
 59             'url'               => 'Icybee\Modules\Nodes\ManageBlock\URLColumn',
 60             'status'            => __CLASS__ . '\StatusColumn',
 61             Comment::AUTHOR     => __CLASS__ . '\AuthorColumn',
 62             Comment::NID        => __CLASS__ . '\NodeColumn',
 63             Comment::CREATED_AT => 'Icybee\ManageBlock\DateTimeColumn'
 64         ));
 65     }
 66 
 67     /**
 68      * Update filters with the `status` modifier.
 69      */
 70     protected function update_filters(array $filters, array $modifiers)
 71     {
 72         $filters = parent::update_filters($filters, $modifiers);
 73 
 74         if (isset($modifiers['status']))
 75         {
 76             $value = $modifiers['status'];
 77 
 78             if (in_array($value, array('approved', 'pending', 'spam')))
 79             {
 80                 $filters['status'] = $value;
 81             }
 82             else if (!$value)
 83             {
 84                 unset($filters['status']);
 85             }
 86         }
 87 
 88         return $filters;
 89     }
 90 
 91     protected function alter_query(Query $query, array $filters)
 92     {
 93         global $core;
 94 
 95         return parent::alter_query($query, $filters)
 96         ->where('(SELECT 1 FROM {prefix}nodes WHERE nid = comment.nid AND (siteid = 0 OR siteid = ?)) IS NOT NULL', $core->site_id);
 97     }
 98 }
 99 
100 /*
101  * Columns
102  */
103 
104 namespace Icybee\Modules\Comments\ManageBlock;
105 
106 use ICanBoogie\ActiveRecord\Query;
107 
108 use Brickrouge\A;
109 use Brickrouge\Element;
110 use Brickrouge\DropdownMenu;
111 
112 use Icybee\ManageBlock;
113 use Icybee\ManageBlock\Column;
114 use Icybee\ManageBlock\EditDecorator;
115 use Icybee\ManageBlock\FilterDecorator;
116 use Icybee\Modules\Comments\Comment;
117 
118 /**
119  * Representation of the `comment` column.
120  */
121 class CommentColumn extends Column
122 {
123     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
124     {
125         parent::__construct
126         (
127             $manager, $id, array
128             (
129                 'orderable' => false
130             )
131         );
132     }
133 
134     public function render_cell($record)
135     {
136         return new EditDecorator(\ICanBoogie\shorten(strip_tags($record), 48, 1), $record);
137     }
138 }
139 
140 /**
141  * Representation of the `status` column.
142  */
143 class StatusColumn extends Column
144 {
145     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
146     {
147         parent::__construct
148         (
149             $manager, $id, $options + array
150             (
151                 'class' => 'pull-right',
152                 'orderable' => false,
153                 'filters' => array
154                 (
155                     'options' => array
156                     (
157                         '=approved' => "Approved",
158                         '=pending' => "Pending",
159                         '=spam' => "Spam"
160                     )
161                 )
162             )
163         );
164     }
165 
166     public function render_cell($record)
167     {
168         static $labels = array
169         (
170             Comment::STATUS_APPROVED => 'Approved',
171             Comment::STATUS_PENDING => 'Pending',
172             Comment::STATUS_SPAM => 'Spam'
173         );
174 
175         static $classes = array
176         (
177             Comment::STATUS_APPROVED => 'btn-success',
178             Comment::STATUS_PENDING => 'btn-warning',
179             Comment::STATUS_SPAM => 'btn-danger'
180         );
181 
182         $status = $record->status;
183         $status_label = isset($labels[$status]) ? $labels[$status] : "<em>Invalid status code: $status</em>";
184         $status_class = isset($classes[$status]) ? $classes[$status] : 'btn-danger';
185         $commentid = $record->commentid;
186 
187         $menu = new DropdownMenu
188         (
189             array
190             (
191                 DropdownMenu::OPTIONS => $labels,
192 
193                 'value' => $status
194             )
195         );
196 
197         $classes_json = \Brickrouge\escape(json_encode($classes));
198 
199         return <<<EOT
200 <div class="btn-group" data-property="status" data-key="$commentid" data-classes="$classes_json">
201     <span class="btn $status_class dropdown-toggle" data-toggle="dropdown"><span class="text">$status_label</span> <span class="caret"></span></span>
202     $menu
203 </div>
204 EOT;
205     }
206 }
207 
208 /**
209  * Representation of the `author` column.
210  */
211 class AuthorColumn extends Column
212 {
213     /**
214      * Filters the records according to the `email` column.
215      */
216     public function alter_query_with_filter(Query $query, $filter_value)
217     {
218         if ($filter_value)
219         {
220             $query->filter_by_author_email($filter_value);
221         }
222 
223         return $query;
224     }
225 
226     /**
227      * Orders the records according to the `author` column.
228      */
229     public function alter_query_with_order(Query $query, $order_direction)
230     {
231         return $query->order('`author` ' . ($order_direction < 0 ? 'DESC' : 'ASC'));
232     }
233 
234     private $discreet_value;
235 
236     public function render_cell($record)
237     {
238         if ($this->discreet_value == $record->author_email)
239         {
240             return ManageBlock::DISCREET_PLACEHOLDER;
241         }
242 
243         $this->discreet_value = $record->author_email;
244 
245         $rc = '';
246 
247         if ($record->author_email)
248         {
249             $rc .= new Element
250             (
251                 'img', array
252                 (
253                     'src' => $record->author_icon . '&s=32',
254                     'alt' => $record->author,
255                     'width' => 32,
256                     'height' => 32
257                 )
258             );
259         }
260 
261         $rc .= '<div class="details">';
262 
263         $rc .= new FilterDecorator($record, $this->id, $this->is_filtering, $record->author, $record->author_email);
264 
265         $email = $record->author_email;
266 
267         if ($email)
268         {
269             $rc .= '<br /><span class="small">&lt;';
270             $rc .= new A($email, 'mailto:' . $email);
271             $rc .= '&gt;</span>';
272         }
273 
274         $url = $record->author_url;
275 
276         if ($url)
277         {
278             $rc .= '<br /><span class="small">';
279             $rc .= new A($url, $url, array('target' => '_blank'));
280             $rc .= '</span>';
281         }
282 
283         $rc .= '</div>';
284 
285         return $rc;
286     }
287 }
288 
289 /**
290  * Representation of the `nid` column.
291  */
292 class NodeColumn extends Column
293 {
294     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
295     {
296         parent::__construct
297         (
298             $manager, $id, array
299             (
300                 'orderable' => false
301             )
302         );
303     }
304 
305     /**
306      * Loads the nodes associated with the comments.
307      */
308     public function alter_records(array $records)
309     {
310         return $this->manager->model->including_node($records);
311     }
312 
313     public function render_cell($record)
314     {
315         $property = $this->id;
316         $node = $record->node;
317 
318         $rc = '';
319 
320         if ($node)
321         {
322             $title = $node->title;
323             $label = \ICanBoogie\escape(\ICanBoogie\shorten($title, 48, .75, $shortened));
324 
325             $rc .= new A
326             (
327                 "", $node->url, array
328                 (
329                     'title' => $title,
330                     'class' => 'icon-external-link'
331                 )
332             ) . ' ';
333         }
334         else
335         {
336             $label = '<em class="warn">unknown-node-' . $record->$property . '</em>';
337         }
338 
339         return $rc . new FilterDecorator($record, $property, $this->is_filtering, $label);
340     }
341 }
Autodoc API documentation generated by ApiGen 2.8.0