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

  • DownloadColumn
  • MimeColumn
  • SizeColumn
  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\Files;
 13 
 14 /**
 15  * A block to manage files.
 16  */
 17 class ManageBlock extends \Icybee\Modules\Nodes\ManageBlock
 18 {
 19     static protected function add_assets(\Brickrouge\Document $document)
 20     {
 21         parent::add_assets($document);
 22 
 23         $document->css->add(DIR . '/public/manage.css');
 24     }
 25 
 26     public function __construct(Module $module, array $attributes)
 27     {
 28         parent::__construct
 29         (
 30             $module, $attributes + array
 31             (
 32                 self::T_COLUMNS_ORDER => array('title', 'size', 'download', 'is_online', 'uid', 'mime', 'updated_at')
 33             )
 34         );
 35     }
 36 
 37     /**
 38      * Adds the following columns:
 39      *
 40      * - `mime`: An instance of {@link ManageBlock\MimeColumn}.
 41      * - `size`: An instance of {@link ManageBlock\SizeColumn}.
 42      * - `download`: An instance of {@link ManageBlock\DownloadColumn}.
 43      *
 44      * @return array
 45      */
 46     protected function get_available_columns()
 47     {
 48         return array_merge(parent::get_available_columns(), array
 49         (
 50             File::MIME => __CLASS__ . '\MimeColumn',
 51             File::SIZE => __CLASS__ . '\SizeColumn',
 52             'download' => __CLASS__ . '\DownloadColumn'
 53         ));
 54     }
 55 }
 56 
 57 namespace Icybee\Modules\Files\ManageBlock;
 58 
 59 use ICanBoogie\ActiveRecord\Query;
 60 
 61 use Brickrouge\A;
 62 
 63 use Icybee\ManageBlock\Column;
 64 use Icybee\ManageBlock\FilterDecorator;
 65 
 66 /**
 67  * Representation of the `mime` column.
 68  */
 69 class MimeColumn extends Column
 70 {
 71     public function render_cell($record)
 72     {
 73         return new FilterDecorator($record, $this->id, $this->manager->is_filtering($this->id));
 74     }
 75 }
 76 
 77 /**
 78  * Representation of the `size` column.
 79  */
 80 class SizeColumn extends \Icybee\ManageBlock\SizeColumn
 81 {
 82     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
 83     {
 84         parent::__construct
 85         (
 86             $manager, $id, $options + array
 87             (
 88                 'class' => 'cell-fitted pull-right',
 89                 'filters' => array
 90                 (
 91                     'options' => array
 92                     (
 93                         '=l' => 'Large',
 94                         '=m' => 'Medium',
 95                         '=s' => 'Small'
 96                     )
 97                 )
 98             )
 99         );
100     }
101 
102     /**
103      * Adds support for the `size` filter.
104      */
105     public function alter_filters(array $filters, array $modifiers)
106     {
107         $filters = parent::alter_filters($filters, $modifiers);
108 
109         if (isset($modifiers['size']))
110         {
111             $value = $modifiers['size'];
112 
113             if (in_array($value, array('l', 'm', 's')))
114             {
115                 $filters['size'] = $value;
116             }
117             else
118             {
119                 unset($filters['size']);
120             }
121         }
122 
123         return $filters;
124     }
125 
126     /**
127      * Adds support for the `size` filter.
128      */
129     public function alter_query_with_filter(Query $query, $filter_value)
130     {
131         if ($filter_value)
132         {
133             list($avg, $max, $min) = $query->model->similar_site->select('AVG(size), MAX(size), MIN(size)')->one(\PDO::FETCH_NUM);
134 
135             $bounds = array
136             (
137                 $min,
138                 round($avg - ($avg - $min) / 3),
139                 round($avg),
140                 round($avg + ($max - $avg) / 3),
141                 $max
142             );
143 
144             switch ($filter_value)
145             {
146                 case 'l': $query->and('size >= ?', $bounds[3]); break;
147                 case 'm': $query->and('size >= ? AND size < ?', $bounds[2], $bounds[3]); break;
148                 case 's': $query->and('size < ?', $bounds[2]); break;
149             }
150         }
151 
152         return $query;
153     }
154 }
155 
156 /**
157  * Representation of the `download` column.
158  */
159 class DownloadColumn extends \Icybee\ManageBlock\Column
160 {
161     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
162     {
163         parent::__construct
164         (
165             $manager, $id, array
166             (
167                 'orderable' => false,
168                 'title' => null
169             )
170         );
171     }
172 
173     public function render_cell($record)
174     {
175         return new A
176         (
177             '', $record->url('download'), array
178             (
179                 'class' => 'download',
180                 'title' => $this->manager->t('Download file')
181             )
182         );
183     }
184 }
Autodoc API documentation generated by ApiGen 2.8.0