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

  • SurfaceColumn
  • TitleColumn
  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\Images;
 13 
 14 class ManageBlock extends \Icybee\Modules\Files\ManageBlock
 15 {
 16     static protected function add_assets(\Brickrouge\Document $document)
 17     {
 18         parent::add_assets($document);
 19 
 20         $document->js->add(DIR . 'public/slimbox.js');
 21         $document->css->add(DIR . 'public/slimbox.css');
 22         $document->js->add('manage.js');
 23     }
 24 
 25     public function __construct(Module $module, array $attributes)
 26     {
 27         parent::__construct
 28         (
 29             $module, $attributes + array
 30             (
 31                 self::T_COLUMNS_ORDER => array
 32                 (
 33                     'title', 'size', 'download', 'is_online', 'uid', 'surface', 'updated_at'
 34                 )
 35             )
 36         );
 37     }
 38 
 39     /**
 40      * Adds the following columns:
 41      *
 42      * - `title`: An instance of {@link ManageBlock\TitleColumn}.
 43      * - `surface`: An instance of {@link ManageBlock\SurfaceColumn}.
 44      */
 45     protected function get_available_columns()
 46     {
 47         return array_merge(parent::get_available_columns(), array
 48         (
 49             'title' => __CLASS__ . '\TitleColumn',
 50             'surface' => __CLASS__ . '\SurfaceColumn'
 51         ));
 52     }
 53 }
 54 
 55 namespace Icybee\Modules\Images\ManageBlock;
 56 
 57 use ICanBoogie\ActiveRecord\Query;
 58 
 59 use Icybee\Modules\Images\ThumbnailDecorator;
 60 
 61 /**
 62  * Class for the `title` column.
 63  */
 64 class TitleColumn extends \Icybee\Modules\Nodes\ManageBlock\TitleColumn
 65 {
 66     public function render_cell($record)
 67     {
 68         return new ThumbnailDecorator(parent::render_cell($record), $record);
 69     }
 70 }
 71 
 72 /**
 73  * Class for the `surface` column.
 74  *
 75  * @todo-20130624: disable options, when count < 10
 76  */
 77 class SurfaceColumn extends \Icybee\ManageBlock\Column
 78 {
 79     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
 80     {
 81         parent::__construct
 82         (
 83             $manager, $id, $options + array
 84             (
 85                 'class' => 'pull-right measure',
 86                 'orderable' => true,
 87                 'filters' => array
 88                 (
 89                     'options' => array
 90                     (
 91                         '=l' => 'Large',
 92                         '=m' => 'Medium',
 93                         '=s' => 'Small'
 94                     )
 95                 )
 96             )
 97         );
 98     }
 99 
100     /**
101      * Adds support for the `surface` filter.
102      */
103     public function alter_filters(array $filters, array $modifiers)
104     {
105         $filters = parent::alter_filters($filters, $modifiers);
106 
107         if (isset($modifiers['surface']))
108         {
109             $value = $modifiers['surface'];
110 
111             if (in_array($value, array('l', 'm', 's')))
112             {
113                 $filters['surface'] = $value;
114             }
115             else
116             {
117                 unset($filters['surface']);
118             }
119         }
120 
121         return $filters;
122     }
123 
124     /**
125      * Adds support for the `surface` filter.
126      */
127     public function alter_query_with_filter(Query $query, $filter_value)
128     {
129         if ($filter_value)
130         {
131             list($avg, $max, $min) = $query->model->select('AVG(width * height), MAX(width * height), MIN(width * height)')->similar_site->one(\PDO::FETCH_NUM);
132 
133             $bounds = array
134             (
135                 $min,
136                 round($avg - ($avg - $min) / 3),
137                 round($avg),
138                 round($avg + ($max - $avg) / 3),
139                 $max
140             );
141 
142             switch ($filter_value)
143             {
144                 case 'l': $query->where('width * height >= ?', $bounds[3]); break;
145                 case 'm': $query->where('width * height >= ? AND width * height < ?', $bounds[2], $bounds[3]); break;
146                 case 's': $query->where('width * height < ?', $bounds[2]); break;
147             }
148         }
149 
150         return $query;
151     }
152 
153     /**
154      * Alters the order of the query with the surface of the image.
155      */
156     public function alter_query_with_order(Query $query, $order_direction)
157     {
158         return $query->order('(width * height) ' . ($order_direction < 0 ? 'DESC' : 'ASC'));
159     }
160 
161     public function render_cell($record)
162     {
163         return "{$record->width}&times;{$record->height}&nbsp;px";
164     }
165 }
Autodoc API documentation generated by ApiGen 2.8.0