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

  • LanguageColumn
  • StatusColumn
  • TimezoneColumn
  • TitleColumn
  • URLColumn
  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\Sites;
 13 
 14 /**
 15  * An element to manage websites.
 16  */
 17 class ManageBlock extends \Icybee\ManageBlock
 18 {
 19     static public function add_assets(\Brickrouge\Document $document)
 20     {
 21         parent::add_assets($document);
 22 
 23         $document->css->add(DIR . 'public/admin.css');
 24         $document->js->add(DIR . 'public/admin.js');
 25     }
 26 
 27     public function __construct($module, array $attributes=array())
 28     {
 29         global $core;
 30 
 31         parent::__construct
 32         (
 33             $module, $attributes + array
 34             (
 35                 self::T_ORDER_BY => array('updated_at', 'desc'),
 36                 self::T_COLUMNS_ORDER => array('title', 'url', 'language', 'timezone', 'updated_at', 'status')
 37             )
 38         );
 39     }
 40 
 41     /**
 42      * Adds the following columns:
 43      *
 44      * - `title`: An instance of {@link ManageBlock\TitleColumn}.
 45      * - `url`: An instance of {@link ManageBlock\URLColumn}.
 46      * - `language`: An instance of {@link ManageBlock\LanguageColumn}.
 47      * - `status`: An instance of {@link ManageBlock\StatusColumn}.
 48      * - `timezone`: An instance of {@link ManageBlock\TimezoneColumn}.
 49      * - `update_at`: An instance of {@link \Icybee\ManageBlock\DateTimeColumn}.
 50      */
 51     protected function get_available_columns()
 52     {
 53         return array_merge(parent::get_available_columns(), array
 54         (
 55             'title' => __CLASS__ . '\TitleColumn',
 56             'url' => __CLASS__ . '\URLColumn',
 57             'language' => __CLASS__ . '\LanguageColumn',
 58             'status' => __CLASS__ . '\StatusColumn',
 59             'timezone' => __CLASS__ . '\TimezoneColumn',
 60             'updated_at' => 'Icybee\ManageBlock\DateTimeColumn'
 61         ));
 62     }
 63 }
 64 
 65 namespace Icybee\Modules\Sites\ManageBlock;
 66 
 67 use Brickrouge\DropdownMenu;
 68 
 69 use Icybee\ManageBlock\Column;
 70 use Icybee\Modules\Sites\Site;
 71 use Icybee\ManageBlock\FilterDecorator;
 72 use Icybee\ManageBlock\EditDecorator;
 73 
 74 /* @var $record \Icybee\Modules\Sites\Site */
 75 
 76 class TitleColumn extends Column
 77 {
 78     public function render_cell($record)
 79     {
 80         return new EditDecorator($record->title, $record);
 81     }
 82 }
 83 
 84 /**
 85  * Representation of the `status` column.
 86  */
 87 class StatusColumn extends Column
 88 {
 89     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
 90     {
 91         parent::__construct
 92         (
 93             $manager, $id, $options + array
 94             (
 95                 'title' => 'Status'
 96             )
 97         );
 98     }
 99 
100     public function render_cell($record)
101     {
102         static $labels = array
103         (
104             Site::STATUS_OK => 'Ok (online)',
105             Site::STATUS_UNAUTHORIZED => 'Unauthorized',
106             Site::STATUS_NOT_FOUND => 'Not found (offline)',
107             Site::STATUS_UNAVAILABLE => 'Unavailable'
108         );
109 
110         static $classes = array
111         (
112             Site::STATUS_OK => 'btn-success',
113             Site::STATUS_UNAUTHORIZED => 'btn-warning',
114             Site::STATUS_NOT_FOUND => 'btn-danger',
115             Site::STATUS_UNAVAILABLE => 'btn-warning'
116         );
117 
118         $status = $record->status;
119         $status_label = isset($labels[$status]) ? $labels[$status] : "<em>Invalid status code: $status</em>";
120         $status_class = isset($classes[$status]) ? $classes[$status] : 'btn-danger';
121         $site_id = $record->siteid;
122 
123         $menu = new DropdownMenu
124         (
125             array
126             (
127                 DropdownMenu::OPTIONS => $labels,
128 
129                 'value' => $status
130             )
131         );
132 
133         $classes_json = \Brickrouge\escape(json_encode($classes));
134 
135         return <<<EOT
136 <div class="btn-group" data-property="status" data-site-id="$site_id" data-classes="$classes_json">
137     <span class="btn $status_class dropdown-toggle" data-toggle="dropdown"><span class="text">$status_label</span> <span class="caret"></span></span>
138     $menu
139 </div>
140 EOT;
141     }
142 }
143 
144 /**
145  * Representation of the `url` column.
146  */
147 class URLColumn extends Column
148 {
149     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
150     {
151         parent::__construct
152         (
153             $manager, $id, $options + array
154             (
155                 'orderable' => false
156             )
157         );
158     }
159 
160     public function render_cell($record)
161     {
162         $parts = explode('.', $_SERVER['SERVER_NAME']);
163         $parts = array_reverse($parts);
164 
165         if ($record->tld)
166         {
167             $parts[0] = '<strong>' . $record->tld . '</strong>';
168         }
169 
170         if ($record->domain)
171         {
172             $parts[1] = '<strong>' . $record->domain . '</strong>';
173         }
174 
175         if ($record->subdomain)
176         {
177             $parts[2] = '<strong>' . $record->subdomain . '</strong>';
178         }
179         else if (empty($parts[2]))
180         {
181             unset($parts[2]);
182         }
183 
184         $label = 'http://' . implode('.', array_reverse($parts)) . ($record->path ? '<strong>' . $record->path . '</strong>' : '');
185 
186         return '<a href="' . $record->url . '">' . $label . '</a>';
187     }
188 }
189 
190 /**
191  * Representation of the `timezone` column.
192  */
193 class TimezoneColumn extends Column
194 {
195     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
196     {
197         parent::__construct
198         (
199             $manager, $id, $options + array
200             (
201                 'discreet' => true
202             )
203         );
204     }
205 
206     public function render_cell($record)
207     {
208         $timezone = $record->timezone;
209 
210         if (!$timezone)
211         {
212             return '<em title="Inherited from the server\'s configuration" class="light">' . date_default_timezone_get() . '</em>';
213         }
214 
215         return new FilterDecorator($record, $this->id, $this->manager->is_filtering($this->id));
216     }
217 }
218 
219 /**
220  * Representation of the `language` column.
221  */
222 class LanguageColumn extends Column
223 {
224     public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
225     {
226         parent::__construct
227         (
228             $manager, $id, $options + array
229             (
230                 'discreet' => true
231             )
232         );
233     }
234 
235     public function render_cell($record)
236     {
237         global $core;
238 
239         $property = $this->id;
240 
241         return new FilterDecorator
242         (
243             $record,
244             $property,
245             $this->manager->is_filtering($property),
246             \ICanBoogie\capitalize($core->locale['languages'][$record->$property])
247         );
248     }
249 }
Autodoc API documentation generated by ApiGen 2.8.0