Ejemplo n.º 1
0
 protected static function mapper(array $row, $alias = 'gadget')
 {
     $model = new \Rebond\Cms\Gadget\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'PageId'])) {
         $model->setPageId($row[$alias . 'PageId']);
         $model->setPage(\Rebond\Cms\Page\Data::join($row, $alias . '_page'));
     }
     if (isset($row[$alias . 'ComponentId'])) {
         $model->setComponentId($row[$alias . 'ComponentId']);
         $model->setComponent(\Rebond\Cms\Component\Data::join($row, $alias . '_component'));
     }
     if (isset($row[$alias . 'Col'])) {
         $model->setCol($row[$alias . 'Col']);
     }
     if (isset($row[$alias . 'FilterId'])) {
         $model->setFilterId($row[$alias . 'FilterId']);
         $model->setFilter(\Rebond\Cms\Filter\Data::join($row, $alias . '_filter'));
     }
     if (isset($row[$alias . 'CustomFilter'])) {
         $model->setCustomFilter($row[$alias . 'CustomFilter']);
     }
     if (isset($row[$alias . 'DisplayOrder'])) {
         $model->setDisplayOrder($row[$alias . 'DisplayOrder']);
     }
     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;
 }
Ejemplo n.º 2
0
 public function buildFullComponent()
 {
     $items = \Rebond\Cms\Component\Data::loadFullComponents();
     return Util\Form::buildDropdownList('componentId' . $this->unique, $items, 'id', 'title', $this->getModel()->getComponentId(), true);
 }
Ejemplo n.º 3
0
 public function component_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component', true, '/cms/component');
     // check
     $id = Converter::int('id');
     $component = \Rebond\Cms\Component\Data::loadById($id, true);
     $form = new \Rebond\Cms\Component\Form($component);
     // action
     if (isset($_POST['save'])) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component.edit', true, '/cms/component?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $component->save();
             Session::adminSuccess('saved', '/cms/component');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['cms', 'component']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor'));
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'cmsComponentEdit');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 4
0
 public function getComponent($createIfNotExist = false)
 {
     if (!isset($this->component)) {
         $this->component = \Rebond\Cms\Component\Data::loadById($this->componentId, $createIfNotExist);
     }
     return $this->component;
 }
Ejemplo n.º 5
0
 public function buildComponent()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Rebond\Cms\Component\Data::getList(['id', 'title']);
     $models = \Rebond\Cms\Component\Data::loadAll($options);
     return Util\Form::buildDropdownList('componentId' . $this->unique, $models, 'id', 'title', $this->getModel()->getComponentId(), $this->componentValidator['foreignKey']);
 }
Ejemplo n.º 6
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>';
     }
 }
Ejemplo n.º 7
0
 public function updateStatus()
 {
     if (!$this->hasPrivilege(null)) {
         return $this->noPrivilege('admin');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $package = Converter::string('package', 'post');
     $entity = Converter::string('entity', 'post');
     $id = Converter::int('id', 'post');
     $id2 = Converter::int('id2', 'post');
     $status = Converter::int('status', 'post');
     if (!isset($package) || !isset($entity) || !isset($id) || !isset($status)) {
         $json['message'] = Lang::lang('errorInvalidParameters');
         return json_encode($json);
     }
     $update = 'saved';
     // check item
     $genericData = '\\Rebond\\' . $package . '\\' . $entity . '\\Data';
     $newStatus = StatusType::INACTIVE;
     // active
     if ($status == StatusType::INACTIVE) {
         $newStatus = StatusType::ACTIVE;
         // inactive
     } else {
         if ($status == StatusType::ACTIVE) {
             $newStatus = StatusType::INACTIVE;
             // undelete
         } else {
             if ($status == StatusType::DELETED) {
                 $newStatus = StatusType::INACTIVE;
                 // delete
             } else {
                 if ($status === 3) {
                     $newStatus = StatusType::DELETED;
                 }
             }
         }
     }
     // update status
     // single id table
     if ($id2 == 0) {
         // update
         if ($newStatus == StatusType::INACTIVE || $newStatus == StatusType::ACTIVE) {
             if (!$this->hasPrivilege('admin.status')) {
                 return $this->noPrivilege('admin.status');
             }
             $genericData::updateStatus($id, $newStatus);
         } else {
             if ($newStatus == StatusType::DELETED) {
                 $update = 'deleted';
                 switch ($entity) {
                     case 'Component':
                         if (!$this->hasPrivilege('admin.cms.component.edit')) {
                             return $this->noPrivilege('admin.cms.component.edit');
                         }
                         \Rebond\Cms\Gadget\Data::deleteByComponentId($id);
                         $genericData::updateStatus($id, $newStatus);
                         break;
                     case 'Feedback':
                         if (!$this->hasPrivilege('admin.dev')) {
                             return $this->noPrivilege('admin.dev');
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'Filter':
                         if (!$this->hasPrivilege('admin.cms.filter.edit')) {
                             return $this->noPrivilege('admin.cms.filter.edit');
                         }
                         \Rebond\Cms\Content\Data::clearFilter($id);
                         $genericData::deleteById($id);
                         break;
                     case 'Gadget':
                         if (!$this->hasPrivilege('admin.page.gadget.edit')) {
                             return $this->noPrivilege('admin.page.gadget.edit');
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'Layout':
                         if (!$this->hasPrivilege('admin.cms.layout.edit')) {
                             return $this->noPrivilege('admin.cms.layout.edit');
                         }
                         $options = [];
                         $options['clearSelect'] = true;
                         $options['select'][] = \Rebond\Cms\Page\Data::getList(['id']);
                         $options['join'][] = 'cms_layout layout ON layout.id = page.layout_id';
                         $options['where'][] = ['layout.id = ?', $id];
                         $pages = \Rebond\Cms\Page\Data::loadAll($options);
                         if (isset($pages) && count($pages) > 0) {
                             $json['result'] = ResultType::ERROR;
                             $json['message'] = 'The layout could not be deleted because ' . count($pages) . ' pages still use it';
                             return json_encode($json);
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'Log':
                         if (!$this->hasPrivilege('admin.tools.log.edit')) {
                             return $this->noPrivilege('admin.tools.log.edit');
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'Module':
                         if (!$this->hasPrivilege('admin.cms.module.edit')) {
                             return $this->noPrivilege('admin.cms.module.edit');
                         }
                         $options = [];
                         $options['clearSelect'] = true;
                         $options['select'][] = \Rebond\Cms\Component\Data::getList(['id']);
                         $options['where'][] = ['component.module_id = ?', $id];
                         $components = \Rebond\Cms\Component\Data::loadAll($options);
                         if (count($components) > 0) {
                             foreach ($components as $component) {
                                 \Rebond\Cms\Component\Data::updateStatus($component->getComponentId(), $newStatus);
                                 \Rebond\Cms\Gadget\Data::deleteByComponentId($component->getComponentId());
                             }
                         }
                         $genericData::updateStatus($id, $newStatus);
                         break;
                     case 'ModuleMedia':
                         if (!$this->hasPrivilege('admin.cms.media-link.edit')) {
                             return $this->noPrivilege('admin.cms.media-link.edit');
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'Permission':
                         if (!$this->hasPrivilege('admin.user.permission.edit')) {
                             return $this->noPrivilege('admin.user.permission.edit');
                         }
                         \Rebond\Core\RolePermission\Data::deleteByPermissionId($id);
                         $genericData::deleteById($id);
                         break;
                     case 'Role':
                         if (!$this->hasPrivilege('admin.user.role.edit')) {
                             return $this->noPrivilege('admin.user.role.edit');
                         }
                         $userRoles = \Rebond\Core\UserRole\Data::loadAllByRoleId($id);
                         if (isset($userRoles) && count($userRoles) > 0) {
                             $json['result'] = ResultType::ERROR;
                             $json['message'] = 'The role could not be deleted because ' . count($userRoles) . ' users still use it';
                             return json_encode($json);
                         }
                         \Rebond\Core\UserRole\Data::deleteByRoleId($id);
                         \Rebond\Core\RolePermission\Data::deleteByRoleId($id);
                         $genericData::deleteById($id);
                         break;
                     case 'Template':
                         if (!$this->hasPrivilege('admin.cms.template.edit')) {
                             return $this->noPrivilege('admin.cms.template.edit');
                         }
                         $options = [];
                         $options['clearSelect'] = true;
                         $options['select'][] = \Rebond\Cms\Page\Data::getList(['id']);
                         $options['join'][] = 'cms_template template ON template.id = page.template_id';
                         $options['where'][] = ['template.id = ?', $id];
                         $pages = \Rebond\Cms\Page\Data::loadAll($options);
                         if (isset($pages) && count($pages) > 0) {
                             $json['result'] = ResultType::ERROR;
                             $json['message'] = 'The template could not be deleted because ' . count($pages) . ' pages still use it';
                             return json_encode($json);
                         }
                         $genericData::deleteById($id);
                         break;
                     case 'User':
                         if (!$this->hasPrivilege('admin.user.edit')) {
                             return $this->noPrivilege('admin.user.edit');
                         }
                         $genericData::updateStatus($id, $newStatus);
                         break;
                     default:
                         Log::log(Error::ITEM_NOT_FOUND, 'entity: ' . $entity, __FILE__, __LINE__);
                         if (!$this->hasPrivilege('admin.status')) {
                             return $this->noPrivilege('admin.status');
                         }
                         $genericData::deleteById($id);
                         break;
                 }
             }
         }
         // double id table
     } else {
         if ($newStatus == StatusType::DELETED) {
             if (!$this->hasPrivilege('admin.status.relation')) {
                 return $this->noPrivilege('admin.status.relation');
             }
             $genericData::deleteByIds($id, $id2);
             $update = 'deleted';
         } else {
             if (!$this->hasPrivilege('admin.status')) {
                 return $this->noPrivilege('admin.status');
             }
             $genericData::updateStatus($id, $id2, $newStatus);
         }
     }
     // result
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = Lang::lang($update);
     return json_encode($json);
 }