示例#1
0
 /**
  * @param string $name
  * @param Selection $selection
  * @return Grid
  * @throws GridNotExistsException
  */
 public function create($name, Selection $selection)
 {
     $className = '\\App\\AdminModule\\Grid\\' . $name;
     if (!class_exists($className)) {
         throw new GridNotExistsException("Grid class {$className} does not exist!");
     }
     if ($this->presenter === NULL) {
         throw new InvalidArgumentException('Presenter must be set!');
     }
     /** @var Grid $grid */
     $grid = new $className($this->db, $selection);
     $grid->setDefaultPerPage(100);
     $grid->setModel($selection)->setTranslator(new FileTranslator('cs'));
     $grid->addActionHref('edit', '')->setIcon('pencil');
     $grid->addActionHref('hide', 'Skrýt')->setCustomRender(function ($row) {
         $icon = Html::el('i');
         $button = Html::el('a')->href($this->presenter->link('hide!', $row->id))->title('Skrýt');
         if (isset($row->visible)) {
             $icon->class('fa fa-eye');
             if ($row->visible) {
                 $button->class('btn btn-default btn-xs btn-mini');
             } else {
                 $button->class('btn btn-danger btn-xs btn-mini');
             }
             $button->setHtml($icon);
         } else {
             $button->style('display: none');
         }
         return $button;
     });
     $grid->addActionHref('delete', '', 'delete!')->setIcon('times')->setConfirm('Opravdu smazat?');
     return $grid;
 }
示例#2
0
 public function addLinkAttr(&$button, $attr_name, Link $link)
 {
     $href = $link->create($this->data);
     if (!$link->hasUseNetteLink()) {
         $button->addAttributes(array($attr_name => reset($href)));
     } else {
         if ($href === FALSE) {
             return FALSE;
         }
         list($to_href, $params) = $href;
         $used_component = $link->getUsedComponent();
         if (!is_null($used_component)) {
             if (is_string($used_component)) {
                 $href_attribute = $this->presenter[$used_component]->link($to_href, $params);
             } elseif (is_array($used_component)) {
                 $component = $this->presenter;
                 foreach ($used_component as $component_name) {
                     $component = $component[$component_name];
                 }
                 $href_attribute = $component->link($to_href, $params);
             } else {
                 throw new Grid_Exception('Link::COMPONENT must be string or array, ' . gettype($used_component) . ' given.');
             }
             $button->addAttributes(array($attr_name => $href_attribute));
         } else {
             $button->addAttributes(array($attr_name => $this->presenter->link($to_href, $params)));
         }
     }
     return TRUE;
 }
示例#3
0
 public function create($data)
 {
     if ($this->option[self::DISABLED] === TRUE) {
         return FALSE;
     }
     if (is_null($this->presenter)) {
         throw new Grid_Exception('Presenter is not set for DropDownLink.');
     }
     $link = $this->option[self::LINK]->create($data);
     if (!$link) {
         return FALSE;
     }
     list($to_href, $params, $name) = $link;
     if ($this->option[self::LINK]->hasUseNetteLink()) {
         $used_component = $this->option[self::LINK]->getUsedComponent();
         if (!is_null($used_component)) {
             if (is_string($used_component)) {
                 $href_param = $this->presenter[$used_component]->link($to_href, $params);
             } elseif (is_array($used_component)) {
                 $component = $this->presenter;
                 foreach ($used_component as $component_name) {
                     $component = $component[$component_name];
                 }
                 $href_param = $component->link($to_href, $params);
             } else {
                 throw new Grid_Exception('Link::COMPONENT must be string or array, ' . gettype($used_component) . ' given.');
             }
         } else {
             $href_param = $this->presenter->link($to_href, $params);
         }
     } else {
         $href_param = $to_href;
     }
     $a = Html::el('a', array('role' => 'menuitem', 'tabindex' => '-1', 'href' => $href_param));
     $a->setText($this->getTranslator() ? $this->getTranslator()->translate($name) : $name);
     if (!isset($this->option[self::ATTRIBUTES]['role'])) {
         $this->option[self::ATTRIBUTES]['role'] = 'presentation';
     }
     $li = Html::el('li', $this->option[self::ATTRIBUTES]);
     $li->add($a);
     return $li;
 }
示例#4
0
 /**
  * Create resource link representation object
  * @param string $destination
  * @param array $args
  * @param string $rel
  * @return Link
  */
 public function link($destination, $args = array(), $rel = Link::SELF)
 {
     $href = parent::link($destination, $args);
     return new Link($href, $rel);
 }
 /**
  * Generates link. If links points to @secure annotated signal handler method, additonal
  * parameter preventing changing parameters will be added.
  *
  * @param string
  * @param array|mixed $args
  * @return string
  */
 public function link($destination, $args = array())
 {
     if (!is_array($args)) {
         $args = func_get_args();
         array_shift($args);
     }
     $link = parent::link($destination, $args);
     $lastRequest = $this->getPresenter()->getLastCreatedRequest();
     // bad link
     if ($lastRequest === NULL) {
         return $link;
     }
     // not a signal
     if (substr($destination, -1) !== '!') {
         return $link;
     }
     // signal must lead to this presenter
     if ($this->getPresenter()->getName() !== $lastRequest->getPresenterName()) {
         return $link;
     }
     $destination = str_replace(':', '-', $destination);
     if (strpos($destination, '-') !== FALSE) {
         $pos = strrpos($destination, '-');
         $signal = substr($destination, $pos + 1, -1);
         $component = substr($destination, 0, $pos);
         $component = $this->getComponent($component);
     } else {
         $signal = substr($destination, 0, -1);
         $component = $this;
     }
     // only components
     if (!$component instanceof PresenterComponent) {
         return $link;
     }
     $method = $component->formatSignalMethod($signal);
     $reflection = Method::from($component, $method);
     // does not have annotation
     if (!$reflection->hasAnnotation('secured')) {
         return $link;
     }
     $origParams = $lastRequest->getParameters();
     $protectedParams = array();
     foreach ($reflection->getParameters() as $param) {
         if ($param->isOptional()) {
             continue;
         }
         $protectedParams[$param->name] = $origParams[$component->getParameterId($param->name)];
     }
     $uniqueId = $this->getUniqueId();
     if (empty($uniqueId)) {
         $paramName = $component->getParameterId('__sec');
     } else {
         $paramName = substr($component->getParameterId('__sec'), strlen($uniqueId) + 1);
     }
     $args[$paramName] = $this->createSecureHash($protectedParams);
     return parent::link($destination, $args);
 }