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

  • AlterColumnsEvent
  • AlterQueryEvent
  • AlterRenderedCellsEvent
  • BooleanCellRenderer
  • BooleanColumn
  • CellRenderer
  • Column
  • DateColumn
  • DateTimeColumn
  • EditColumn
  • EditDecorator
  • FilterDecorator
  • HeaderRenderer
  • KeyColumn
  • Options
  • RegisterColumnsEvent
  • SizeColumn
  • Translator
  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\ManageBlock;
 13 
 14 use ICanBoogie\ActiveRecord\Query;
 15 use ICanBoogie\DateTime;
 16 use Icybee\ManageBlock;
 17 
 18 /**
 19  * Representation of a _datetime_ column.
 20  */
 21 class DateTimeColumn extends Column
 22 {
 23     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
 24     {
 25         parent::__construct
 26         (
 27             $manager, $id, $options + array
 28             (
 29                 'class' => 'date',
 30                 'default_order' => -1,
 31                 'discreet' => true
 32             )
 33         );
 34     }
 35 
 36     public function alter_query_with_filter(Query $query, $filter_value)
 37     {
 38         if ($filter_value)
 39         {
 40             $field = $this->id;
 41 
 42             list($year, $month, $day) = explode('-', $filter_value) + array(0, 0, 0);
 43 
 44             if ($year)
 45             {
 46                 $query->where("YEAR(`$field`) = ?", (int) $year);
 47             }
 48 
 49             if ($month)
 50             {
 51                 $query->where("MONTH(`$field`) = ?", (int) $month);
 52             }
 53 
 54             if ($day)
 55             {
 56                 $query->where("DAY(`$field`) = ?", (int) $day);
 57             }
 58         }
 59 
 60         return $query;
 61     }
 62 
 63     private $discreet_value;
 64 
 65     /**
 66      * Renders the datetime.
 67      *
 68      * If the column is discreet, the repeating dates are replaced by the discreet placeholder
 69      * while the time is still displayed.
 70      */
 71     public function render_cell($record)
 72     {
 73         $date = $record->{ $this->id };
 74 
 75         if (!$date)
 76         {
 77             return;
 78         }
 79 
 80         if (!($date instanceof DateTime))
 81         {
 82             $date = new DateTime($date, 'utc');
 83         }
 84 
 85         if ($date->is_empty)
 86         {
 87             return;
 88         }
 89 
 90         if ($this->discreet && $this->discreet_value == $date->as_date)
 91         {
 92             $rendered_date = ManageBlock::DISCREET_PLACEHOLDER;
 93         }
 94         else
 95         {
 96             $rendered_date = $this->render_cell_date($date, $this->id);
 97 
 98             $this->discreet_value = $date->as_date;
 99         }
100 
101         $rendered_time = $this->render_cell_time($date, $this->id);
102 
103         return $rendered_date . ($rendered_time ? '&nbsp;<span class="small light">' . $rendered_time . '</span>' : '');
104     }
105 
106     /**
107      * Renders cell value as time.
108      *
109      * @param \ICanBoogie\ActiveRecord $record
110      * @param string $property
111      *
112      * @return string
113      */
114     protected function render_cell_time($date, $property)
115     {
116         return $date->local->format('H:i');
117     }
118 
119     /**
120      * Renders cell value as date.
121      *
122      * @param \ICanBoogie\ActiveRecord $record
123      * @param string $property
124      *
125      * @return string
126      */
127     protected function render_cell_date($date, $property)
128     {
129         $tag = $property;
130 
131         $year = $date->year;
132         $month = $date->month;
133         $day = $date->day;
134 
135         $filtering = false;
136         $filter = null;
137 
138         if ($this->manager->is_filtering($property))
139         {
140             $filtering = true;
141             $filter = $this->manager->options->filters[$property]; // TODO-20130621: provide a get_filter_value() method
142         }
143 
144         $parts = array
145         (
146             array($year, $year),
147             array($date->format('m'), $date->format('Y-m')),
148             array($date->format('d'), $date->as_date)
149         );
150 
151         $today = new DateTime('now', 'utc');
152         $today_year = $today->year;
153         $today_month = $today->month;
154         $today_day = $today->day;
155         $today_formatted = $today->as_date;
156 
157         $select = $parts[2][1];
158         $diff_days = $day - $today_day;
159 
160         if ($year == $today_year && $month == $today_month && $day <= $today_day && $day > $today_day - 6)
161         {
162             $label = \ICanBoogie\I18n\date_period($date);
163             $label = ucfirst($label);
164 
165             if ($filtering && $filter == $today_formatted)
166             {
167                 $rc = $label;
168             }
169             else
170             {
171                 $ttl = $this->manager->t('Display only: :identifier', array(':identifier' => $label));
172 
173                 $rc = <<<EOT
174 <a href="?$property=$select" title="$ttl" class="filter">$label</a>
175 EOT;
176             }
177         }
178         else
179         {
180             $rc = '';
181 
182             foreach ($parts as $i => $part)
183             {
184                 list($value, $select) = $part;
185 
186                 if ($filtering && $filter == $select)
187                 {
188                     $rc .= $value;
189                 }
190                 else
191                 {
192                     $ttl = $this->manager->t('Display only: :identifier', array(':identifier' => $select));
193 
194                     $rc .= <<<EOT
195 <a class="filter" href="?$property=$select" title="$ttl">$value</a>
196 EOT;
197                 }
198 
199                 if ($i < 2)
200                 {
201                     $rc .= '–';
202                 }
203             }
204         }
205 
206         return $rc;
207     }
208 }
209 
210 /**
211  * Representation of a _date_ column.
212  */
213 class DateColumn extends DateTimeColumn
214 {
215     protected function render_cell_time($date, $property)
216     {
217         return;
218     }
219 }
Autodoc API documentation generated by ApiGen 2.8.0