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; }
public function gadget() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget', true, '/page'); // check $id = Converter::int('id'); $save = Converter::int('save', 'post'); $page = \Rebond\Cms\Page\Data::loadById($id); if (!isset($page)) { header('Location: /page'); exit; } $gadget = new \Rebond\Cms\Gadget\Model(); $gadget->setPageId($page->getId()); $form = new \Rebond\Cms\Gadget\Form($gadget); // action if (isset($save)) { Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget.edit', true, '/page/gadget?id=' . $id); if ($form->setFromPost()->validate()->isValid()) { $gadget->save(); Session::adminSuccess('saved', '/page/gadget?id=' . $id); } else { Session::set('adminError', $form->getValidation()->getMessage()); } } // view $this->setTpl(); // form $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId()); $columns = $layout->getColumns(); $columnOptions = []; for ($i = 1; $i <= $columns; $i++) { $columnOptions[$i] = Lang::lang('column') . ' ' . $i; } $tplForm = new Template(Template::MODULE, ['cms', 'gadget']); $tplForm->set('item', $form); $tplForm->set('title', Lang::lang('manageGadgetOf', [$page->getTitle()])); $tplForm->set('columnOptions', $columnOptions); $tplForm->set('selectedColumn', $gadget->getCol()); // active listing $options = []; $options['join'][] = 'cms_page page ON page.id = gadget.page_id'; $options['join'][] = 'cms_component component ON component.id = gadget.component_id'; $options['join'][] = 'cms_module module ON module.id = component.module_id'; $options['where'][] = ['page.id = ?', $page->getId()]; $options['where'][] = 'module.status = 1'; $options['where'][] = 'component.status = 1'; $options['order'][] = 'gadget.col'; $options['order'][] = 'gadget.display_order'; $gadgets = \Rebond\Cms\Gadget\Data::loadAll($options); if ($gadgets) { foreach ($gadgets as $g) { $g->prepareFilter(); } } // inactive listing $options = []; $options['join'][] = 'cms_page page ON page.id = gadget.page_id'; $options['join'][] = 'cms_component component ON component.id = gadget.component_id'; $options['join'][] = 'cms_module module ON module.id = component.module_id'; $options['where'][] = ['page.id = ?', $page->getId()]; $options['where'][] = 'module.status = 0 OR component.status = 0'; $options['order'][] = 'gadget.col'; $options['order'][] = 'gadget.display_order'; $inactiveGadgets = \Rebond\Cms\Gadget\Data::loadAll($options); if ($inactiveGadgets) { foreach ($inactiveGadgets as $g) { $g->prepareFilter(); } } $tplListing = new Template(Template::MODULE, ['cms', 'gadget']); $tplListing->set('items', $gadgets); $tplListing->set('inactiveItems', $inactiveGadgets); $tplListing->set('columnOptions', $columnOptions); // layout $this->tplLayout->add('column1', $tplForm->render('editor-selector')); $this->tplLayout->add('column2', $tplListing->render('listing')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-row')); $this->tplMaster->set('jsLauncher', 'pageGadget'); return $this->tplMaster->render('tpl-default'); }