Esempio n. 1
0
 protected function saveEntity()
 {
     $app = \Rebond\App::instance();
     $userId = $app->userId();
     $this->setId(0);
     $this->setAuthorId($userId);
     $workflow = $this->getModule()->getWorkflow();
     // new content
     if ($this->getContentGroup() == 0) {
         $contentGroup = Data::getNextContentGroup($this->getModuleId());
         $this->setContentGroup($contentGroup);
         if ($workflow == 1) {
             $this->setVersion(VersionType::PENDING);
         } else {
             $this->setPublisherId($userId);
             $this->setPublishedDate('now');
             $this->setVersion(VersionType::PUBLISHED);
         }
         // updating content
     } else {
         // use workflow
         if ($workflow == 1) {
             if ($this->getVersion() == VersionType::PUBLISHED) {
                 Data::updateContentGroupVersion($this, VersionType::PUBLISHED, VersionType::UPDATING);
                 $this->setVersion(VersionType::PUBLISHING);
             } else {
                 if ($this->getVersion() == VersionType::PENDING) {
                     Data::updateContentGroupVersion($this, VersionType::PENDING, VersionType::OLD);
                     $this->setVersion(VersionType::PENDING);
                 } else {
                     if (in_array($this->getVersion(), [VersionType::PUBLISHING, VersionType::UPDATING])) {
                         Data::updateContentGroupVersion($this, VersionType::PUBLISHING, VersionType::OLD);
                         $this->setVersion(VersionType::PUBLISHING);
                     }
                 }
             }
         } else {
             if ($workflow == 0) {
                 Data::updateContentGroupVersionAll($this);
                 $this->setPublisherId($userId);
                 $this->setPublishedDate('now');
                 $this->setVersion(VersionType::PUBLISHED);
             }
         }
     }
     return parent::save();
 }
Esempio n. 2
0
 protected static function autoJoin(Util\Data $db, $moduleName, $select = true)
 {
     $module = \Rebond\Cms\Module\Data::loadByTitle($moduleName);
     if (!isset($module)) {
         Util\Error::kill(Util\Error::ITEM_NOT_FOUND, 'module ' . $module . ' not found', __FILE__, __LINE__);
     }
     if ($select) {
         $db->buildQuery('select', \Rebond\Cms\Content\Data::getList());
         $db->buildQuery('select', \Rebond\Cms\Module\Data::getList([], 'content_module'));
         if ($module->getHasFilter()) {
             $db->buildQuery('select', \Rebond\Cms\Filter\Data::getList([], 'content_filter'));
         }
     }
     $db->buildQuery('join', 'cms_content content ON x.app_id = content.app_id');
     $db->buildQuery('join', 'cms_module content_module ON content_module.id = content.module_id');
     if ($module->getHasFilter()) {
         $db->buildQuery('leftJoin', 'cms_filter content_filter ON content_filter.id = content.filter_id');
     }
     $db->buildQuery('where', ['content.module_id = ?', $module->getId()]);
 }
Esempio n. 3
0
 protected static function mapper(array $row, $alias = 'x')
 {
     $model = new \Rebond\App\Standard\Model(false);
     if (isset($row[$alias . 'AppId'])) {
         $model->setAppId($row[$alias . 'AppId']);
     }
     if (isset($row[$alias . 'MediaId'])) {
         $model->setMediaId($row[$alias . 'MediaId']);
         $model->setMedia(\Rebond\Core\Media\Data::join($row, $alias . '_media'));
     }
     if (isset($row[$alias . 'Description'])) {
         $model->setDescription($row[$alias . 'Description']);
     }
     return parent::mapEntity($model, $row);
 }
Esempio n. 4
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);
 }