Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function registerComponents(Nette\Application\UI\Presenter $presenter)
 {
     if (!$this->getConfigurations()['labels']['enable']) {
         return;
     }
     $presenter->addComponent($this->labels->create(), $this->getConfigurations()['labels']['componentName']);
 }
 public function formatTemplateFiles(Presenter $presenter)
 {
     $name = $presenter->getName();
     $view = $presenter->view;
     $_presenter = substr($name, strrpos(':' . $name, ':'));
     $dir = dirname($presenter->getReflection()->getFileName());
     $dir = is_dir("{$dir}/templates") ? $dir : dirname($dir);
     return array("{$dir}/templates/{$_presenter}/{$view}.latte", "{$dir}/templates/{$_presenter}.{$view}.latte", "{$dir}/templates/{$_presenter}/{$view}.phtml", "{$dir}/templates/{$_presenter}.{$view}.phtml");
 }
Ejemplo n.º 4
0
 /**
  * @param $action
  * @param string $method
  * @param array $params
  * @param array $post
  * @return Nette\Application\IResponse
  */
 protected function runPresenterAction($action, $method = 'GET', $params = [], $post = [])
 {
     /** @var IntegrationTestCase|PresenterRunner $this */
     if (!$this->presenter) {
         throw new \LogicException("You have to open the presenter using \$this->openPresenter(\$name); before calling actions");
     }
     $request = new Nette\Application\Request($this->presenter->getName(), $method, ['action' => $action] + $params, $post);
     return $this->presenter->run($request);
 }
Ejemplo n.º 5
0
 /**
  * @param Presenter $presenter
  */
 public function updateModal(Presenter $presenter)
 {
     $presenter->getTemplate()->modal = $activeModal = Modal::getActiveModal();
     if ($presenter->isAjax()) {
         // close the previous modal
         if (Modal::isCloseRequired()) {
             $presenter->getPayload()->closeModal = TRUE;
         }
         $redrawModal = $activeModal && $activeModal->isOpenRequired() || Modal::isCloseRequired();
         $presenter->redrawControl('modal', $redrawModal);
     }
 }
 public static function tryJsonResponse(Presenter $presenter)
 {
     if (empty(self::$jsonResoponseItems)) {
         return;
     }
     $payload = array("type" => "JsonDependentSelectBoxResponse", "items" => array());
     foreach (self::$jsonResoponseItems as $item) {
         $payload["items"][$item->getHtmlId()] = array("selected" => $item->getValue(), "items" => $item->getItems());
     }
     $response = new JsonResponse($payload);
     $presenter->sendResponse($response);
 }
 public function formatTemplateFiles(Presenter $presenter)
 {
     $name = $presenter->getName();
     $view = $presenter->view;
     $_presenter = substr($name, strrpos(':' . $name, ':'));
     $directories = $this->getAdjustedDirectories($presenter);
     $list = array();
     foreach ($directories as $dir) {
         $list[] = $this->getTemplateFiles("{$dir}/presenters", $_presenter, $view);
         $list[] = $this->getTemplateFiles($dir, $_presenter, $view);
     }
     return Arrays::flatten($list);
 }
Ejemplo n.º 8
0
 public function handleSave()
 {
     $this->presenter = $this->getPresenter();
     if ($this->presenter->isAjax()) {
         $request = $this->presenter->getRequest();
         $result = $request->getPost();
         foreach ($this->onSave as $call) {
             $call($result);
         }
         $this->presenter->payload->neco = $result;
         $this->presenter->sendPayload();
     }
 }
 public function formatTemplateFiles(Presenter $presenter)
 {
     if (NULL === $this->filesCache[$name = $presenter->getName()]) {
         $templateLocator = $this->templateLocator;
         $onlyExistingFiles = $this->onlyExistingFiles;
         return $this->filesCache->save($name, function () use($presenter, $templateLocator, $onlyExistingFiles) {
             $list = $templateLocator->formatTemplateFiles($presenter);
             if ($onlyExistingFiles) {
                 $list = array_filter($list, 'is_file');
             }
             return $list;
         });
     }
     return $this->filesCache[$name];
 }
Ejemplo n.º 10
0
 public function startup()
 {
     parent::startup();
     $this->template->max_rating = $this->global_settings->getMaxRating();
     $this->template->image_dir = __DIR__ . '/../../www/images/games/';
     $this->template->title = '';
 }
Ejemplo n.º 11
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;
 }
 public function startup()
 {
     parent::startup();
     if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
         $this->error();
     }
 }
Ejemplo n.º 13
0
 protected function beforeRender()
 {
     parent::beforeRender();
     if ($this->isAjax() && $this->hasFlashSession()) {
         $this->redrawControl('flash');
     }
 }
Ejemplo n.º 14
0
 /**
  * @return \Nette\Bridges\ApplicationLatte\Template
  */
 protected function createTemplate()
 {
     /** @var \Nette\Bridges\ApplicationLatte\Template $template */
     $template = parent::createTemplate();
     $this->latteFilters->install($template->getLatte());
     return $template;
 }
Ejemplo n.º 15
0
 /**
  * Common template method
  */
 protected function beforeRender()
 {
     parent::beforeRender();
     $this->template->portal = $this->portal;
     $this->template->rev = $this->portal->expand('build.rev');
     $this->template->debug = $this->portal->isDebug();
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function isAllowed($role, $resource, $privilege)
 {
     if ($role instanceof IRole) {
         $role = $role->getRoleId();
     }
     if (!$resource instanceof PresenterResource) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Resource must be instance of %s, %s given.', PresenterResource::class, gettype($resource)));
     }
     $request = $resource->getRequest();
     $presenterName = $request->getPresenterName();
     list($signal, $signalReceiver) = $this->getSignal($request);
     if (!$signal) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('No signal sent.'));
     }
     $refClass = new PresenterComponentReflection($class = $this->presenterFactory->getPresenterClass($presenterName));
     while ($name = array_shift($signalReceiver)) {
         $name = 'createComponent' . ucfirst($name);
         if (!$refClass->hasMethod($name)) {
             throw new \Nette\InvalidStateException(sprintf('Method %s::%s is not implemented.', $refClass->getName(), $name));
         }
         $refMethod = $refClass->getMethod($name);
         if (!$refMethod->hasAnnotation('return')) {
             throw new \Nette\InvalidStateException(sprintf('Method %s::%s must have fully qualified return annotation.', $refClass->getName(), $name));
         }
         $refClass = new ClassType($refMethod->getAnnotation('return'));
     }
     if (!$refClass->hasMethod($name = Presenter::formatSignalMethod($signal))) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s is not implemented.', $refClass->getName(), $name));
     }
     $refMethod = $refClass->getMethod($name);
     if (!$refMethod->hasAnnotation($privilege)) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s does not have annotation %s.', $refClass->getName(), $name, $privilege));
     }
     return in_array($role, preg_split('#\\s+#', trim((string) $refMethod->getAnnotation($privilege))));
 }
Ejemplo n.º 17
0
 protected function startup()
 {
     parent::startup();
     if (!$this->user->isLoggedIn() && $this->name != "Sign") {
         $this->redirect("Sign:in");
     }
 }
Ejemplo n.º 18
0
 /**
  * Generates URL to presenter.
  * @param  string   destination in format "[[[module:]presenter:]action] [#fragment]"
  * @return string
  * @throws UI\InvalidLinkException
  */
 public function link($dest, array $params = array())
 {
     if (!preg_match('~^([\\w:]+):(\\w*+)(#.*)?()\\z~', $dest, $m)) {
         throw new UI\InvalidLinkException("Invalid link destination '{$dest}'.");
     }
     list(, $presenter, $action, $frag) = $m;
     try {
         $class = $this->presenterFactory ? $this->presenterFactory->getPresenterClass($presenter) : NULL;
     } catch (InvalidPresenterException $e) {
         throw new UI\InvalidLinkException($e->getMessage(), NULL, $e);
     }
     if (is_subclass_of($class, 'Nette\\Application\\UI\\Presenter')) {
         if ($action === '') {
             $action = UI\Presenter::DEFAULT_ACTION;
         }
         if (method_exists($class, $method = $class::formatActionMethod($action)) || method_exists($class, $method = $class::formatRenderMethod($action))) {
             UI\Presenter::argsToParams($class, $method, $params);
         }
     }
     if ($action !== '') {
         $params[UI\Presenter::ACTION_KEY] = $action;
     }
     $url = $this->router->constructUrl(new Request($presenter, NULL, $params), $this->refUrl);
     if ($url === NULL) {
         unset($params[UI\Presenter::ACTION_KEY]);
         $params = urldecode(http_build_query($params, NULL, ', '));
         throw new UI\InvalidLinkException("No route for {$dest}({$params})");
     }
     return $url . $frag;
 }
Ejemplo n.º 19
0
 public function beforeRender()
 {
     parent::beforeRender();
     $parameters = $this->context->parameters;
     $this->template->version = $parameters['version'];
     $this->template->debugMode = $parameters['debugMode'];
 }
Ejemplo n.º 20
0
 public function getText($params, \Nette\Application\UI\Presenter $presenter, $default_text = null)
 {
     if (!isset($params[0])) {
         throw new \Exception("gettext macro must define 1 parameter {getText 'textName'}");
     }
     $name = $params[0];
     $default_text = htmlspecialchars_decode($default_text);
     $text = $this->textManager->getText($name);
     $texy = new \Texy\Texy();
     if (!$text) {
         $this->textManager->addText($name, $presenter->name . ':' . $presenter->getAction(), $default_text);
         return $texy->process($default_text);
     } else {
         return $texy->process($text->text);
     }
 }
Ejemplo n.º 21
0
 protected function beforeRender()
 {
     parent::beforeRender();
     // TODO add excaption when paramets[site] not exists
     $this->template->production = !$this->context->parameters['site']['develMode'];
     $this->template->version = $this->context->parameters['site']['version'];
 }
Ejemplo n.º 22
0
 protected function startup()
 {
     parent::startup();
     if (!$this->user->isLoggedIn()) {
         $this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
     }
 }
Ejemplo n.º 23
0
 public function beforeRender()
 {
     parent::beforeRender();
     if (!$this->getUser()->isLoggedIn()) {
         $this->redirectUrl('/');
     }
 }
Ejemplo n.º 24
0
 public function startup()
 {
     parent::startup();
     if (!$this->user->isLoggedIn() && !$this->presenter instanceof SignPresenter) {
         $this->redirect('Sign:in');
     }
 }
Ejemplo n.º 25
0
 public function beforeRender()
 {
     parent::beforeRender();
     $this->template->locale = $this->locale;
     $this->template->production = !$this->siteLayout->develMode;
     $this->template->version = $this->siteLayout->versionName;
 }
Ejemplo n.º 26
0
 function startup()
 {
     parent::startup();
     if (isset($this->module)) {
         Options::extend($this->module, $this->moduleparams);
         Options::read($this->params);
     }
     if (array_key_exists("conffile", $this->params)) {
         Options::read(array("conffile" => $this->params["conffile"]));
     } else {
         if (getenv("MONDARC")) {
             Options::readFile(getenv("MONDARC"));
         }
     }
     Options::readEnv();
     Options::read($this->params);
     if (Options::get("configinfo")) {
         foreach (Options::get() as $key => $val) {
             $arr = Options::info($key);
             if ($arr["default"]) {
                 CliLogger::log(sprintf("Option %s => Value:'%s', set from:defaults\n", $key, $arr["value"]), Debugger::ERROR);
             } else {
                 CliLogger::log(sprintf("Option %s => Value:'%s', set from:%s\n", $key, $arr["value"], $arr["setfrom"]), Debugger::ERROR);
             }
         }
         self::mexit();
     }
     if ($this->name == $this->action) {
         $this->Help(Options::get("xhelp"));
     }
 }
Ejemplo n.º 27
0
 /**
  * @param null $class
  * @return \Nette\Templating\ITemplate
  */
 protected function createTemplate($class = NULL)
 {
     $template = parent::createTemplate($class);
     $template->setTranslator($this->translator);
     $template->registerHelperLoader(callback($this->helpers, 'loader'));
     return $template;
 }
Ejemplo n.º 28
0
 public function sendResponse(IResponse $response)
 {
     if ($this->tidy->isEnabled() && $response instanceof TextResponse && $response->getSource() instanceof ITemplate) {
         $response = new TidyResponse($response, $this->tidy);
     }
     parent::sendResponse($response);
 }
Ejemplo n.º 29
0
 protected function beforeRender()
 {
     parent::beforeRender();
     if ($this->isAjax) {
         $this->redrawControl('flashMessages');
     }
 }
Ejemplo n.º 30
0
 /**
  * @todo Language switch
  */
 public function beforeRender()
 {
     parent::beforeRender();
     if (file_exists(APP_DIR . '/data/en/cv.json')) {
         $this->data = json_decode(file_get_contents(APP_DIR . '/data/en/cv.json'), true);
     }
 }