public function performIndex() { $this->prepareControl(); if ($this->isListing) { /* * Provide default action on set of selected model's items. */ $this->browser->setPagerVolatility("none"); if (is_callable($this->browserCustomizer)) { call_user_func($this->browserCustomizer, $this, $this->browser); } else { // try generate some commonly useful databrowser $controller = $this; $this->browser->addColumn('label', \de\toxa\txf\_L('Label'), false, function ($value, $propName, $record, $id) use($controller) { return $controller->getModel()->getMethod('select')->invoke(null, $controller->source, $id)->describe(); })->setRowCommander(function ($id, $data) use($controller) { $items = array('view' => markup::link(sprintf($controller->getUrls()->view, $id), \de\toxa\txf\_L('view item'), 'controller-list-action-view'), 'edit' => markup::link(sprintf($controller->getUrls()->edit, $id), \de\toxa\txf\_L('edit item'), 'controller-list-action-edit'), 'delete' => markup::link(sprintf($controller->getUrls()->delete, $id), \de\toxa\txf\_L('delete item'), 'controller-list-action-delete')); if (!user::current()->isAuthenticated()) { unset($items['edit'], $items['delete']); } return implode(' ', array_filter($items)); }); if (user::current()->isAuthenticated()) { $controller->setPanelControl('add', markup::link($controller->getUrls()->add, \de\toxa\txf\_L('add item'), 'controller-list-action-add')); } } if (user::current()->isAuthenticated()) { if (!$this->hasPanelControl('add')) { $this->setPanelControl('add', markup::link(context::selfURL(false, array_merge(array_pad(array(), $this->modelClass->getMethod('idSize')->invoke(null), 0), array('edit'))), \de\toxa\txf\_L('Add'))); } } $this->browser->processInput(); return $this->browser->getCode(); } /** * Provide default action on single instance of selected model. */ $this->editor->mayEdit(false)->mayDelete(false); if (is_callable($this->viewCustomizer)) { call_user_func($this->viewCustomizer, $this, false); } else { $data = $this->editor->item()->published(); // reduce relations foreach ($data as $key => $value) { if (is_array($value)) { $data[$key] = implode(', ', $value); } } return html::arrayToCard($data); } if (user::current()->isAuthenticated()) { if (!$this->hasPanelControl('edit')) { $this->setPanelControl('edit', markup::link(context::selfURL(false, array_merge($this->item->id(), array('edit'))), \de\toxa\txf\_L('Edit'))); } } if ($this->editor->processInput($this->editorValidator)) { txf::redirectTo($this->getUrls()->list); } return $this->editor->render(); }
/** * Renders editor with fields providing controls for editing properties of * item in editor. * * @return string * @throws \LogicException on trying to render editable view of editor unless editing has been enabled */ public function renderEditable() { if (!$this->isEditable()) { throw new \LogicException(\de\toxa\txf\_L('Model editor is not enabled.')); } $form = $this->form(); if ($this->item) { $form->setHidden('id', $this->item->getReflection()->getMethod("serializeId")->invoke(null, $this->item->id())); } if (!array_key_exists('_referrer', $this->fields)) { $form->setHidden('_referrer', input::vget('_referrer')); } $fixed = array(); foreach ($this->fields as $property => $field) { /** @var model_editor_field $field */ if (!count($this->enabled) || !@$this->enabled[$property]) { $label = $field->label(); $type = $field->type(); $name = $this->propertyToField($property); $input = $field->isCustom() ? null : $this->getValue($property, false, $type); if ($this->isFixedValue($property)) { $fixed[$property] = $input; $type->renderStatic($form, $name, $input, $label, $this, $field); } else { $type->render($form, $name, $input, $label, $this, $field); if (array_key_exists($property, $this->errors)) { $form->setRowError($name, $this->errors[$property]); } } } } if (count($fixed)) { $form->setHidden('_fix', $fixed); } // compile buttons to show at end of editor if (!$this->item || $this->may['edit']) { $form->setButtonRow('_cmd', $this->item ? \de\toxa\txf\_L('Save') : \de\toxa\txf\_L('Create'), 'save'); } $form->setButtonRow('_cmd', \de\toxa\txf\_L('Cancel'), 'cancel'); if ($this->item && $this->may['delete']) { $form->setButtonRow('_cmd', \de\toxa\txf\_L('Delete'), 'delete'); } if ($this->sortingOrder) { $form->setSortingOrder($this->sortingOrder); } // return HTML code of editor return $form->getCode(); }