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 namespace Icybee\ManageBlock;
  4 
  5 /**
  6  * Display options of the manager element.
  7  *
  8  * The metas of the current user are used to persist the options.
  9  */
 10 class Options
 11 {
 12     public $start = 1;
 13     public $limit = 10;
 14     public $order_by = null;
 15     public $order_direction = null;
 16     public $search = null;
 17     public $filters = array();
 18 
 19     private $name;
 20 
 21     public function __construct($name)
 22     {
 23         $this->name = $name;
 24     }
 25 
 26     public function __set($property, $value)
 27     {
 28         if ($property == 'order')
 29         {
 30             throw new \InvalidArgumentException("The <q>order</q> property is deprecated. Please use <q>order_by</q> and <q>order_direction</q>.");
 31         }
 32 
 33         $this->$property = $value;
 34     }
 35 
 36     /**
 37      * Reset the options.
 38      */
 39     public function reset()
 40     {
 41         $this->start = 1;
 42         $this->limit = 10;
 43         $this->order_by = null;
 44         $this->order_direction = null;
 45         $this->search = null;
 46         $this->filters = array();
 47 
 48         return $this;
 49     }
 50 
 51     /**
 52      * Returns an array representation of the object.
 53      *
 54      * @return array[string]mixed
 55      */
 56     public function to_array()
 57     {
 58         $array = get_object_vars($this);
 59 
 60         unset($array['name']);
 61 
 62         return $array;
 63     }
 64 
 65     /**
 66      * Retrieves previously used options.
 67      *
 68      * @param string $name Storage name for the options, usualy the module's id.
 69      *
 70      * @return array Previously used options, or brand new ones is none were defined.
 71      */
 72     public function retrieve()
 73     {
 74         global $core;
 75 
 76         $this->reset();
 77 
 78         $name = $this->name;
 79         $serialized = $core->user->metas["block.manager.{$this->name}:{$core->site_id}"];
 80 
 81         if ($serialized)
 82         {
 83             $options = json_decode($serialized, true);
 84 
 85             foreach ($options as $option => $value)
 86             {
 87                 $this->$option = $value;
 88             }
 89         }
 90 
 91         return $this;
 92     }
 93 
 94     /**
 95      * Store options for later use.
 96      *
 97      * @param array $options The options to store.
 98      * @param string $name Storage name for the options, usualy the module's id.
 99      */
100     public function store()
101     {
102         global $core;
103 
104         $serialized = json_encode($this->to_array());
105 
106         $core->user->metas["block.manager.{$this->name}:{$core->site_id}"] = $serialized;
107 
108         return $this;
109     }
110 
111     /**
112      * Update the options according to the specified modifiers.
113      *
114      * @param array $modifiers
115      *
116      * @return \Icybee\ManageBlock\Options
117      */
118     public function update(array $modifiers)
119     {
120         if (isset($modifiers['limit']))
121         {
122             $this->limit = max(filter_var($modifiers['limit'], FILTER_VALIDATE_INT), 10);
123         }
124 
125         if (isset($modifiers['start']))
126         {
127             $start = $modifiers['start'];
128 
129             if ($start === 'next')
130             {
131                 $this->start += $this->limit;
132             }
133             else if ($start === 'previous')
134             {
135                 $this->start -= $this->limit;
136             }
137             else
138             {
139                 $this->start = max(filter_var($start, FILTER_VALIDATE_INT), 1);
140             }
141         }
142 
143         if (isset($modifiers['q']))
144         {
145             $this->search = $modifiers['q'];
146             $this->start = 1;
147         }
148 
149         if (isset($modifiers['order']))
150         {
151             list($order_by, $order_direction) = explode(':', $modifiers['order']) + array(1 => null);
152 
153             $order_direction = (strtolower($order_direction) == 'desc' ? -1 : 1);
154 
155             if ($order_by != $this->order_by  || $order_direction != $this->order_direction)
156             {
157                 $this->start = 1;
158             }
159 
160             $this->order_by = $order_by;
161             $this->order_direction = $order_direction;
162         }
163 
164         if (isset($modifiers['filters']))
165         {
166             $filters = $modifiers['filters'];
167 
168             if ($this->filters != $filters)
169             {
170                 $this->filters = $filters;
171                 $this->start = 1;
172             }
173         }
174 
175         return $this;
176     }
177 
178     /**
179      * Checks if the view is filtered.
180      *
181      * @param string $column_id This optional parameter can be used to check if the filter
182      * is applied to a specific column.
183      *
184      * @return boolean
185      */
186     public function is_filtering($column_id=null)
187     {
188         if ($column_id === null)
189         {
190             return !empty($this->filters);
191         }
192 
193         return isset($this->filters[$column_id]);
194     }
195 }
Autodoc API documentation generated by ApiGen 2.8.0