Exemple #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>';
     }
 }
Exemple #2
0
 protected static function mapper(array $row, $alias = 'component')
 {
     $model = new \Rebond\Cms\Component\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'ModuleId'])) {
         $model->setModuleId($row[$alias . 'ModuleId']);
         $model->setModule(\Rebond\Cms\Module\Data::join($row, $alias . '_module'));
     }
     if (isset($row[$alias . 'Title'])) {
         $model->setTitle($row[$alias . 'Title']);
     }
     if (isset($row[$alias . 'Summary'])) {
         $model->setSummary($row[$alias . 'Summary']);
     }
     if (isset($row[$alias . 'Method'])) {
         $model->setMethod($row[$alias . 'Method']);
     }
     if (isset($row[$alias . 'Type'])) {
         $model->setType($row[$alias . 'Type']);
     }
     if (isset($row[$alias . 'Status'])) {
         $model->setStatus($row[$alias . 'Status']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }