Exemple #1
0
 /**
  * Retrieves named set of URLs to use for addressing actions of current
  * widget.
  *
  * Every URL might contain %s to be replaced by single user's ID. This
  * replacement is required if %s is contained in URL.
  *
  * @return object object with URLs in properties add, edit, delete, view, list
  */
 protected function getUrls()
 {
     return (object) array('add' => context::selfUrl(false, 'add'), 'edit' => context::selfUrl(false, '%s', 'edit'), 'delete' => context::selfUrl(false, '%s', 'delete'), 'view' => context::selfUrl(false, '%s'), 'list' => context::selfUrl(false, false));
 }
Exemple #2
0
 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();
 }