Example #1
0
 protected function afterDelete()
 {
     parent::afterDelete();
     $page = $this->getPage();
     if (!$page) {
         return;
     }
     $page['comments_counter'] = $page['comments_counter'] > 0 ? $page['comments_counter'] - 1 : 0;
     $page->save();
 }
Example #2
0
 public function isAvailableInSelectedBlock()
 {
     if ($this['type'] === 'floxim.main.page') {
         return true;
     }
     return parent::isAvailableInSelectedBlock();
 }
Example #3
0
 public function validate()
 {
     if ($this->isModified('email')) {
         $existing = fx::data('floxim.user.user')->where('email', $this['email'])->where('id', $this['id'], '!=')->one();
         if ($existing) {
             $this->invalid(fx::alang('This email is already used', 'system'), 'email');
         }
     }
     if ($this->isModified('password')) {
         $password = $this->getPayload('plain_password');
         if (is_null($password)) {
             $password = $this['password'];
         }
         if (!empty($password)) {
             $confirm = $this->getPayload('confirm_password');
             if (!is_null($confirm) && $confirm !== $password) {
                 $this->invalid(fx::alang('Passwords do not match', 'system'), 'confirm_password');
             }
         } elseif (!$this['id']) {
             $this->invalid('Passwords can not be empty', 'password');
         }
     }
     $pres = parent::validate();
     return $pres;
 }
Example #4
0
 protected function getScopeFields(CompInfoblock\Entity $infoblock, \Floxim\Main\Content\Entity $c_page)
 {
     $fields = array();
     // format: [page_id]-[descendants|children|this]-[|type_id]
     //$path_ids = $c_page->getParentIds();
     $path_ids = $c_page->getPath()->getValues('id');
     $path = fx::data('page', $path_ids);
     if (!$path->findOne('id', $c_page['id'])) {
         $path[] = $c_page;
     }
     $path_count = count($path);
     $c_type = $c_page['type'];
     $page_com = fx::data('component', $c_page['type']);
     $c_type_name = $page_com->getItemName('one');
     $container_infoblock = null;
     if ($infoblock['container_infoblock_id']) {
         $container_infoblock = fx::data('infoblock', $infoblock['container_infoblock_id']);
     }
     $c_scope_code = $infoblock->getScopeString();
     $vals = array();
     foreach ($path as $i => $pi) {
         //$sep = str_repeat(" -- ", $i);
         $sep = str_repeat(" ", $i * 6);
         $pn = $pi['name'];
         $pt = $pi->getComponent()->getItemName('one');
         $pt_of = $pi->getComponent()->getItemName('of');
         $is_last = $i === $path_count - 1;
         $c_page_id = $pi['id'];
         if ($i === 0) {
             $c_page_id = fx::env('site')->get('index_page_id');
             $vals[] = array($c_page_id . '-descendants-', fx::alang('All pages'));
             if ($path_count > 1) {
                 $vals[] = array($c_page_id . '-children-' . $c_type, sprintf(fx::alang('All pages of type %s'), $c_type_name));
             }
         }
         if ($i !== 0) {
             $vals[] = array($c_page_id . '-descendants-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s and children'), $pt, $pn)));
         }
         if ($is_last) {
             $vals[] = array($c_page_id . '-this-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s only'), $pt, $pn)));
         } else {
             $vals[] = array($c_page_id . '-children-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s children only'), $pt_of, $pn)));
         }
         if (!$is_last && $i !== 0) {
             $vals[] = array($c_page_id . '-children-' . $c_type, $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s children of type %s'), $pt_of, $pn, $c_type_name)));
         }
     }
     // can be set to "hidden" later
     $scope_field_type = 'select';
     if (!$infoblock['id']) {
         if ($container_infoblock) {
             $c_scope_code = $container_infoblock->getScopeString();
             if ($container_infoblock['scope']['pages'] === 'this') {
                 $scope_field_type = 'hidden';
             }
         } else {
             $ctr = $infoblock->initController();
             $cfg = $ctr->getConfig(true);
             if (isset($cfg['default_scope'])) {
                 $c_scope_code = is_callable($cfg['default_scope']) ? call_user_func($cfg['default_scope']) : $cfg['default_scope'];
                 if ($c_scope_code === 'this') {
                     $c_scope_code = fx::env('page_id') . '-this-';
                 } elseif ($c_scope_code === 'all') {
                     $c_scope_code = fx::env('site')->get('index_page_id') . '-descendants-';
                 }
             }
         }
     }
     $fields[] = array('type' => $scope_field_type, 'label' => fx::alang('Scope'), 'name' => 'complex_scope', 'values' => $vals, 'value' => $c_scope_code);
     $fields['visibility'] = array('type' => 'hidden', 'label' => 'Visibility', 'name' => 'visibility', 'value' => $infoblock['scope']['visibility']);
     return $fields;
 }