Example #1
0
 private function produceGadget()
 {
     // Base class
     $gadgetTpl = new Template(Template::SITE, ['generator', 'gadget']);
     $gadgetTpl->set('entity', $this->entity);
     $gadgetTpl->set('hasContent', $this->hasContent);
     $viewList = [];
     $detail = false;
     foreach ($this->xmlViews as $xmlView) {
         $view = $xmlView->getAttribute('name');
         if ($view == '') {
             continue;
         }
         if ($view == 'list') {
             $view = 'full-list';
         }
         $viewList[] = $view;
         if (!$detail && in_array($view, ['full-list', 'filtered-list'])) {
             $detail = true;
             $viewList[] = 'detail';
         }
     }
     // add component
     $component = new \Rebond\Cms\Component\Model();
     $component->setModuleId($this->id);
     $component->setStatus(0);
     foreach ($viewList as $view) {
         $component->setId(0);
         switch ($view) {
             case 'full-list':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::LISTING];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(1);
                     $component->setTitle('full listing');
                     $component->setSummary('full listing');
                     $component->setMethod('fullList');
                     $component->save();
                 }
                 break;
             case 'filtered-list':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::FILTERED_LISTING];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(2);
                     $component->setTitle('filtered listing');
                     $component->setSummary('filtered listing');
                     $component->setMethod('filteredList');
                     $component->save();
                 }
                 break;
             case 'single':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::SINGLE_ITEM];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(0);
                     $component->setTitle('single item');
                     $component->setSummary('single item');
                     $component->setMethod('single');
                     $component->save();
                 }
                 break;
             case 'form':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::GENERIC];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 $options['where'][] = 'component.method = \'form\'';
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(4);
                     $component->setTitle('form');
                     $component->setSummary('form');
                     $component->setMethod('form');
                     $component->save();
                 }
                 break;
         }
     }
     $gadgetTpl->set('viewList', $viewList);
     $gadgetPath = \Rebond\Config::getPath('rebond') . 'App/' . $this->entity . '/Gadget.php';
     if (!file_exists($gadgetPath)) {
         $render = str_replace('<#php', '<?php', $gadgetTpl->render('gadget'));
         \Rebond\Util\File::save($gadgetPath, 'w', $render);
         $this->info[] = '<div>Gadget created.</div>';
     } else {
         $this->info[] = '<div class="exist">Gadget already exists.</div>';
     }
 }
Example #2
0
 public function listComponent()
 {
     if (!$this->hasPrivilege('admin.cms.component')) {
         return $this->noPrivilege('admin.cms.component');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $hashParam = Converter::string('hash', 'post', 'no');
     $hash = explode('/', $hashParam);
     $status = isset($hash[0]) && $hash[0] != '' ? $hash[0] : 'active';
     $page = isset($hash[1]) && $hash[1] != '' ? (int) $hash[1] : 1;
     $options = [];
     if ($status == 'active') {
         $options['where'][] = 'component.status IN (0,1)';
     } else {
         $options['where'][] = 'component.status = 2';
     }
     $componentCount = \Rebond\Cms\Component\Data::count($options);
     // get user settings
     $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($this->signedUser->getId());
     $listCount = 10;
     if (isset($userSettings)) {
         $listCount = (int) $userSettings->getPagingValue();
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > ceil($componentCount / $listCount) && $componentCount > 0) {
         $page = ceil($componentCount / $listCount);
     }
     // add select, join, order and limit
     $options['select'][] = \Rebond\Cms\Module\Data::getList([], 'component_module');
     $options['join'][] = 'cms_module component_module ON component_module.id = component.module_id';
     $options['order'][] = 'component_module.title, component.title';
     $options['limit'][] = ($page - 1) * $listCount . ', ' . $listCount;
     $components = \Rebond\Cms\Component\Data::loadAll($options);
     $tpl = new Template(Template::MODULE, ['cms', 'component']);
     $tpl->set('items', $components);
     $tplFilter = new Template(Template::MODULE, ['cms', 'component']);
     $tplFilter->set('current', $page);
     $tplFilter->set('maxByPage', $listCount);
     $tplFilter->set('count', $componentCount);
     $tplFilter->set('status', $status);
     $tplFilter->set('url', '#!/' . $status . '/');
     $tplLayout = new Template(Template::SITE, ['admin']);
     $tplLayout->set('column1', $tplFilter->render('filter'));
     $tplLayout->set('column2', $tpl->render('listing'));
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = Lang::lang('listUpdated') . ' (' . count($components) . ')';
     $json['html'] = $tplLayout->render('layout-2-row');
     return json_encode($json);
 }