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

  • MoveEvent
  • RenderRegionEvent
  • RenderTitleEvent
  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\Pages;
 13 
 14 use ICanBoogie\Event;
 15 use ICanBoogie\Routing\Pattern;
 16 
 17 class SaveOperation extends \Icybee\Modules\Nodes\SaveOperation
 18 {
 19     /**
 20      * For new records, the values for the {@link Page::SITEID} and {@link Page::LANGUAGE}
 21      * properties are obtained from the current site. If the weight of the page is not defined
 22      * it is computed according to the page having the same parent.
 23      */
 24     protected function lazy_get_properties()
 25     {
 26         global $core;
 27 
 28         $properties = parent::lazy_get_properties() + array
 29         (
 30             Page::PARENTID => 0
 31         );
 32 
 33         if (!$this->key)
 34         {
 35             /* @var $site \Icybee\Modules\Sites\Site */
 36 
 37             $site = $core->site;
 38             $siteid = $site->siteid;
 39             $properties[Page::SITEID] = $siteid;
 40             $properties[Page::LANGUAGE] = $site->language;
 41 
 42             if (empty($properties[Page::WEIGHT]))
 43             {
 44                 $model = $this->module->model;
 45 
 46                 if ($model->count())
 47                 {
 48                     $weight = $model
 49                     ->where('siteid = ? AND parentid = ?', $siteid, $properties[Page::PARENTID])
 50                     ->maximum('weight');
 51 
 52                     $properties[Page::WEIGHT] = ($weight === null) ? 0 : $weight + 1;
 53                 }
 54                 else
 55                 {
 56                     $properties[Page::WEIGHT] = 0;
 57                 }
 58             }
 59         }
 60 
 61         return $properties;
 62     }
 63 
 64     /**
 65      * For each defined content we check that the corresponding editor is also defined.
 66      */
 67     protected function validate(\ICanBoogie\Errors $errors)
 68     {
 69         $contents = $this->request['contents'];
 70         $editors = $this->request['editors'];
 71 
 72         if ($contents)
 73         {
 74             foreach (array_keys($contents) as $name)
 75             {
 76                 if (!array_key_exists($name, $editors))
 77                 {
 78                     $errors['content'][] = $errors->format('The editor is missing for the content %name.', array('name' => $name));
 79                 }
 80             }
 81         }
 82 
 83         return parent::validate($errors);
 84     }
 85 
 86     protected function process()
 87     {
 88         global $core;
 89 
 90         $record = null;
 91         $oldurl = null;
 92 
 93         if ($this->record)
 94         {
 95             $record = $this->record;
 96             $pattern = $record->url_pattern;
 97 
 98             if (!Pattern::is_pattern($pattern))
 99             {
100                 $oldurl = $pattern;
101             }
102         }
103 
104         $rc = parent::process();
105         $nid = $rc['key'];
106 
107         #
108         # update contents
109         #
110 
111         /* var $contents_model ContentModel */
112 
113         $preserve = array();
114         $contents_model = $this->module->model('contents');
115 
116         $contents = $this->request['contents'];
117         $editor_ids = $this->request['editors'];
118 
119         if ($contents && $editor_ids)
120         {
121             foreach ($contents as $content_id => $unserialized_content)
122             {
123                 if (!$unserialized_content)
124                 {
125                     continue;
126                 }
127 
128                 $editor_id = $editor_ids[$content_id];
129                 $editor = $core->editors[$editor_id];
130                 $content = $editor->serialize($unserialized_content);
131 
132                 if (!$content)
133                 {
134                     continue;
135                 }
136 
137                 $preserve[$content_id] = $content_id;
138 
139                 $values = array
140                 (
141                     'content' => $content,
142                     'editor' => $editor_id
143                 );
144 
145                 $contents_model->insert
146                 (
147                     array
148                     (
149                         'pageid' => $nid,
150                         'contentid' => $content_id
151                     )
152 
153                     + $values,
154 
155                     array
156                     (
157                         'on duplicate' => $values
158                     )
159                 );
160             }
161         }
162 
163         #
164         # we delete possible remaining content for the page
165         #
166 
167         $arr = $contents_model->filter_by_pageid($nid);
168 
169         if ($preserve)
170         {
171             $arr->where(array('!contentid' => $preserve));
172         }
173 
174         $arr->delete();
175 
176         if ($record && $oldurl)
177         {
178             $record = $this->module->model[$nid];
179             $newurl = $record->url;
180 
181             if ($newurl && $newurl != $oldurl)
182             {
183                 new Page\MoveEvent($record, $oldurl, $newurl);
184             }
185         }
186 
187         return $rc;
188     }
189 }
190 
191 namespace Icybee\Modules\Pages\Page;
192 
193 /**
194  * Event class for the `Icybee\Modules\Pages\Page::move` event.
195  */
196 class MoveEvent extends \ICanBoogie\Event
197 {
198     /**
199      * Previous path.
200      *
201      * @var string
202      */
203     public $from;
204 
205     /**
206      * New path.
207      *
208      * @var string
209      */
210     public $to;
211 
212     /**
213      * The event is constructed with the type `move`.
214      *
215      * @param \Icybee\Modules\Pages\Page $target
216      * @param string $from Previous path.
217      * @param string $to New path.
218      */
219     public function __construct(\Icybee\Modules\Pages\Page $target, $from, $to)
220     {
221         $this->from = $from;
222         $this->to = $to;
223 
224         parent::__construct($target, 'move');
225     }
226 }
Autodoc API documentation generated by ApiGen 2.8.0