Beispiel #1
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();
 }
Beispiel #2
0
 /**
  * Generates databrowser for listing available users for managing.
  *
  * @param string $formName name of control to use (e.g. as class name)
  * @param browseable $list list of users
  * @param object $urls URLs to use in properties edit, add and delete (containing %s to be replaced by a user's ID)
  * @return databrowser
  */
 protected function createBrowser($formName, browseable $list, $urls)
 {
     $this->setPanelControl('add', markup::link($urls->add, \de\toxa\txf\_L('add user')));
     return databrowser::create($list, \de\toxa\txf\_L('There is no user to be listed here.'), $formName)->addColumn('loginname', \de\toxa\txf\_L('login name'), true)->addColumn('name', \de\toxa\txf\_L('name'), true)->addColumn('email', \de\toxa\txf\_L('email'), true)->setRowCommander(function ($id, $record) use($urls) {
         return implode(' ', array_filter(array(markup::link(sprintf($urls->edit, $id), \de\toxa\txf\_L('edit')), $record['uuid'] !== user::current()->getUuid() ? markup::link(sprintf($urls->delete, $id), \de\toxa\txf\_L('delete')) : '')));
     })->setPagerVolatility('none');
 }