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

  • PopularityColumn
  • TermColumn
  • VidColumn
  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\Taxonomy\Terms;
 13 
 14 class ManageBlock extends \Icybee\ManageBlock
 15 {
 16     public function __construct(Module $module, array $attributes=array())
 17     {
 18         parent::__construct
 19         (
 20             $module, $attributes += array
 21             (
 22                 self::T_ORDER_BY => array('term', 'asc')
 23             )
 24         );
 25     }
 26 
 27     /**
 28      * Adds the following columns:
 29      *
 30      * - `term`: An instance of {@link ManageBlock\TermColumn}.
 31      * - `vid`: An instance of {@link ManageBlock\VidColumn}.
 32      * - `popularity`: An instance of {@link ManageBlock\PopularityColumn}.
 33      */
 34     protected function get_available_columns()
 35     {
 36         return array_merge(parent::get_available_columns(), array
 37         (
 38             'term' => __CLASS__ . '\TermColumn',
 39             'vid' => __CLASS__ . '\VidColumn',
 40             'popularity' => __CLASS__ . '\PopularityColumn'
 41         ));
 42     }
 43 }
 44 
 45 namespace Icybee\Modules\Taxonomy\Terms\ManageBlock;
 46 
 47 use ICanBoogie\ActiveRecord\Query;
 48 
 49 use Icybee\ManageBlock\Column;
 50 use Icybee\ManageBlock\FilterDecorator;
 51 use Icybee\ManageBlock\EditDecorator;
 52 
 53 class TermColumn extends Column
 54 {
 55     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
 56     {
 57         parent::__construct
 58         (
 59             $manager, $id, $options + array
 60             (
 61                 'title' => 'Term'
 62             )
 63         );
 64     }
 65 
 66     public function render_cell($record)
 67     {
 68         return new EditDecorator($record->term, $record);
 69     }
 70 }
 71 
 72 /**
 73  * Representation of the `vid` column.
 74  */
 75 class VidColumn extends Column
 76 {
 77     public function __construct(\Icybee\Modules\Taxonomy\Terms\ManageBlock $manager, $id, array $options=array())
 78     {
 79         global $core;
 80 
 81         parent::__construct
 82         (
 83             $manager, $id, $options + array
 84             (
 85                 'title' => 'Vocabulary',
 86                 'orderable' => true
 87             )
 88         );
 89     }
 90 
 91     /**
 92      * Extends the "vid" column by providing vocabulary filters.
 93      *
 94      * @param array $column
 95      * @param string $id
 96      */
 97     protected function get_options()
 98     {
 99         global $core;
100 
101         // Move this to render_header() when it's actually used
102 
103         $keys = $this->manager->module->model->select('DISTINCT vid')->all(\PDO::FETCH_COLUMN);
104 
105         if (count($keys) < 2)
106         {
107             $this->orderable = false;
108 
109             return;
110         }
111 
112         // /
113 
114         return $core->models['taxonomy.vocabulary']
115         ->select('CONCAT("?vid=", vid), vocabulary')
116         ->where(array('vid' => $keys))
117         ->order('vocabulary')
118         ->pairs;
119     }
120 
121     /**
122      * Alters the query with the 'vid' filter.
123      */
124     public function alter_query_with_filter(Query $query, $filter_value)
125     {
126         if ($filter_value)
127         {
128             $query->filter_by_vid($filter_value);
129         }
130 
131         return $query;
132     }
133 
134     /**
135      * Orders the records according to vocabulary name.
136      */
137     public function alter_query_with_order(Query $query, $order_direction)
138     {
139         global $core;
140 
141         $names = $core->models['taxonomy.vocabulary']->select('vid, vocabulary')->order("vocabulary " . ($order_direction < 0 ? 'DESC' : 'ASC'))->pairs;
142 
143         return $query->order('vid', array_keys($names));
144     }
145 
146     public function render_cell($record)
147     {
148         return new FilterDecorator($record, $this->id, $this->manager->is_filtering($this->id), $record->vocabulary);
149     }
150 }
151 
152 /**
153  * Representation of the `popularity` column.
154  *
155  * The column displays the times a term is associated to a node.
156  */
157 class PopularityColumn extends Column
158 {
159     /**
160      * Popularity values for the displayed rows.
161      *
162      * @var array[int]int
163      */
164     private $values;
165 
166     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
167     {
168         parent::__construct
169         (
170             $manager, $id, array
171             (
172                 'title' => 'Popularity',
173                 'class' => 'pull-right',
174                 'orderable' => true
175             )
176         );
177     }
178 
179     /**
180      * Computes the popularity of the specified records.
181      *
182      * Note: The popularity values are stored in the {@link $values} property.
183      */
184     public function alter_records(array $records)
185     {
186         $keys = array();
187 
188         foreach ($records as $record)
189         {
190             $keys[] = $record->vtid;
191         }
192 
193         if ($keys)
194         {
195             $this->values = $this->manager->module->model('nodes')->filter_by_vtid($keys)->count('vtid');
196         }
197 
198         return $records;
199     }
200 
201     /**
202      * Orders the records according to their popularity.
203      */
204     public function alter_query_with_order(Query $query, $order_direction)
205     {
206         return $query->order("(SELECT COUNT(vtid) FROM {self}__nodes WHERE vtid = term.vtid) " . ($order_direction < 0 ? 'DESC' : 'ASC'));
207     }
208 
209     public function render_cell($record)
210     {
211         return isset($this->values[$record->vtid]) ? $this->values[$record->vtid] : 0;
212     }
213 }
Autodoc API documentation generated by ApiGen 2.8.0