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

  • AdminDecorator
  • AdminIndexController
  • BlockController
  • BlockDecorator
  • ConfigBlock
  • ConfigController
  • ConfigOperation
  • Core
  • DeleteBlock
  • DeleteController
  • Document
  • DocumentDecorator
  • EditBlock
  • EditController
  • FormBlock
  • Hooks
  • InterlockBlock
  • Kses
  • ManageBlock
  • Module
  • Modules
  • StatsDecorator

Constants

  • OPERATION_SAVE_MODE
  • OPERATION_SAVE_MODE_CONTINUE
  • OPERATION_SAVE_MODE_DISPLAY
  • OPERATION_SAVE_MODE_LIST
  • OPERATION_SAVE_MODE_NEW

Functions

  • slugize
  • start
  • strip_stopwords
  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;
 13 
 14 use ICanBoogie\ActiveRecord;
 15 use ICanBoogie\I18n;
 16 use ICanBoogie\Operation;
 17 use ICanBoogie\Route;
 18 
 19 use Brickrouge\Button;
 20 use Brickrouge\Element;
 21 use Brickrouge\Form;
 22 
 23 /**
 24  * A block to delete a record.
 25  *
 26  * @property string $title The localized title of the block. {@link get_title()}
 27  * @property ActiveRecord $record The record to delete. {@link get_record()}
 28  * @property string $record_name The name of the record to delete. {@link get_record_name()}
 29  */
 30 class DeleteBlock extends Form
 31 {
 32     static protected function add_assets(\Brickrouge\Document $document)
 33     {
 34         parent::add_assets($document);
 35 
 36         $document->css->add('delete.css');
 37     }
 38 
 39     /**
 40      * Module associated with this block.
 41      *
 42      * @var Module
 43      */
 44     protected $module;
 45 
 46     /**
 47      * Key of the record to delete.
 48      *
 49      * @var int
 50      */
 51     protected $key;
 52 
 53     /**
 54      * Constructor.
 55      *
 56      * @param Module $module
 57      * @param array $attributes
 58      * @param array $params Index 0 hold the key of the record to delete.
 59      */
 60     public function __construct(Module $module, array $attributes=array(), array $params=array())
 61     {
 62         $this->module = $module;
 63         $this->key = current($params);
 64 
 65         parent::__construct
 66         (
 67             $attributes + array
 68             (
 69                 Form::HIDDENS => array
 70                 (
 71                     Operation::DESTINATION => $module->id,
 72                     Operation::NAME => Module::OPERATION_DELETE,
 73                     Operation::KEY => $this->key,
 74 
 75                     'redirect_to' => \ICanBoogie\Routing\contextualize("/admin/{$module->id}")
 76                 ),
 77 
 78                 self::ACTIONS => array
 79                 (
 80                     new Button
 81                     (
 82                         'Delete', array
 83                         (
 84                             'class' => 'btn-primary btn-danger',
 85                             'type' => 'submit'
 86                         )
 87                     )
 88                 ),
 89 
 90                 self::CHILDREN => array
 91                 (
 92                     $this->title_element,
 93                     $this->question_element,
 94                     $this->preview_element,
 95                     $this->dependencies_element
 96                 )
 97             )
 98         );
 99     }
100 
101     public function __toString()
102     {
103         try
104         {
105             $record = $this->record;
106         }
107         catch (\Exception $e)
108         {
109             try
110             {
111                 $message = I18n\t('Unknown record id: %key', array('%key' => $this->key));
112 
113                 return <<<EOT
114 <div class="block-alert block--delete">
115 $this->title_element
116 <div class="alert alert-error">$message</div>
117 </div>
118 EOT;
119             }
120             catch (\Exception $e)
121             {
122                 return \ICanBoogie\Debug::format_alert($e);
123             }
124         }
125 
126         return parent::__toString();
127     }
128 
129     /**
130      * Returns the localized title.
131      *
132      * @return string
133      */
134     protected function get_title()
135     {
136         return I18n\t('Delete a record');
137     }
138 
139     /**
140      * Returns the title element.
141      *
142      * @return \Brickrouge\Element
143      */
144     protected function get_title_element()
145     {
146         return new Element('h1', array(Element::INNER_HTML => \Brickrouge\escape($this->title), 'class' => 'block-title'));
147     }
148 
149     /**
150      * Returns the record to delete.
151      *
152      * @return ActiveRecord
153      */
154     protected function lazy_get_record()
155     {
156         return $this->module->model[$this->key];
157     }
158 
159     /**
160      * Returns the record name.
161      *
162      * @return string
163      */
164     protected function get_record_name()
165     {
166 
167     }
168 
169     /**
170      * Returns the localized confirmation question.
171      *
172      * @return string
173      */
174     protected function get_question()
175     {
176         $record_name = $this->record_name;
177 
178         if ($record_name)
179         {
180             $record_name = '<q>' . $record_name . '</q>';
181         }
182         else
183         {
184             $record_name = I18n\t('record_name', array(), array('default' => 'this record'));
185         }
186 
187         return I18n\t('Are you sure you want to delete :name?', array('name' => $record_name));
188     }
189 
190     /**
191      * Returns the confirmation question element.
192      *
193      * @return \Brickrouge\Element
194      */
195     protected function get_question_element()
196     {
197         return new Element('p', array(Element::INNER_HTML => $this->question));
198     }
199 
200     /**
201      * Renders a preview of the record.
202      *
203      * @param \ICanBoogie\ActiveRecord $record
204      *
205      * @return string
206      */
207     protected function render_preview(\ICanBoogie\ActiveRecord $record)
208     {
209 
210     }
211 
212     /**
213      * Returns a preview of the record.
214      *
215      * @return string
216      */
217     protected function get_preview()
218     {
219         return $this->render_preview($this->record);
220     }
221 
222     /**
223      * Returns the preview element.
224      *
225      * @return \Brickrouge\Element
226      */
227     protected function get_preview_element()
228     {
229         return $this->preview ? new Element('div', array(Element::INNER_HTML => $this->preview, 'class' => 'preview')) : null;
230     }
231 
232     /**
233      * Renders the dependencies of the record.
234      *
235      * @param array $dependencies
236      *
237      * @return string
238      */
239     protected function render_dependencies(array $dependencies)
240     {
241         $html = null;
242 
243         foreach ($dependencies as $module_id => $by_module)
244         {
245             $flat_id = strtr($module_id, '.', '_');
246 
247             $html .= '<li>';
248             $html .= '<strong>' . I18n\t(count($by_module) == 1 ? 'one' : 'other', array(), array('scope' => "$flat_id.name")) . '</strong>';
249             $html .= '<ul>';
250 
251             foreach ($by_module as $key => $dependency)
252             {
253                 $html .= '<li><a href="' . $dependency['edit_url'] . '">' . $dependency['title'] . '</a></li>';
254             }
255 
256             $html .= '</ul>';
257             $html .= '</li>';
258         }
259 
260         if (!$html)
261         {
262             return null;
263         }
264 
265         $p = I18n\t('The following dependencies were found, they will also be deleted:');
266 
267         return <<<EOT
268 <p>$p</p>
269 <ul>$html</ul>
270 EOT;
271     }
272 
273     /**
274      * Returns the dependencies of the record.
275      *
276      * @return string
277      */
278     protected function get_dependencies()
279     {
280         $record = $this->record;
281         $dependencies = array();
282 
283         new \ICanBoogie\ActiveRecord\CollectDependenciesEvent($record, $dependencies);
284 
285         return $this->render_dependencies($dependencies);
286     }
287 
288     /**
289      * Returns the dependencies element.
290      *
291      * @return \Brickrouge\Element
292      */
293     protected function get_dependencies_element()
294     {
295         return $this->dependencies ? new Element('div', array(Element::INNER_HTML => $this->dependencies, 'class' => 'dependencies')) : null;
296     }
297 
298     /**
299      * Decorate the form as a block with a title, question and possible preview.
300      *
301      * Because at this level the method has no way of knowing the name of the record, it uses
302      * the localized string "record_name" which defaults to "this record".
303      */
304     protected function decorate($html)
305     {
306         return $html;
307     }
308 }
309 
310 /*
311  * Events
312  */
313 
314 namespace ICanBoogie\ActiveRecord;
315 
316 use ICanBoogie\Route;
317 
318 /**
319  * Event class for the `ICanBoogie\ActiveRecord::collect_dependencies` event.
320  */
321 class CollectDependenciesEvent extends \ICanBoogie\Event
322 {
323     /**
324      * Reference to the dependencies.
325      *
326      * @var array[string]\ICanBoogie\ActiveRecord
327      */
328     public $dependencies;
329 
330     /**
331      * The event is constructed with the type 'collect_dependencies'.
332      *
333      * @param \ICanBoogie\ActiveRecord $target
334      * @param array $dependencies
335      */
336     public function __construct(\ICanBoogie\ActiveRecord $target, array &$dependencies)
337     {
338         $this->dependencies = &$dependencies;
339 
340         parent::__construct($target, 'collect_dependencies');
341     }
342 
343     /**
344      * Adds a dependency.
345      *
346      * @param string $module_id Identifier of the module managin the dependency.
347      * @param int $key Identifier of the dependency.
348      * @param string $title Title of the dependency.
349      * @param string|true|null $edit_url The URL where the dependency can be edited. If `true`
350      * the URL if automatically generated using the following pattern:
351      * `/admin/:module_id/:key/edit`.
352      * @param string|null $view_url The URL on the website where the dependency can be viewed.
353      */
354     public function add($module_id, $key, $title, $edit_url=null, $view_url=null)
355     {
356         if ($edit_url === true)
357         {
358             $edit_url = \ICanBoogie\Routing\contextualize("/admin/$module_id/$key/edit");
359         }
360 
361         $this->dependencies[$module_id][$key] = array('title' => $title, 'edit_url' => $edit_url, 'view_url' => $view_url);
362     }
363 }
Autodoc API documentation generated by ApiGen 2.8.0