Пример #1
0
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param  Nette\ComponentModel\IComponent
  * @return void
  */
 protected function attached($presenter)
 {
     parent::attached($presenter);
     if ($presenter instanceof IPresenter) {
         if ($presenter->isAjax()) {
             if ($this->type !== null) {
                 $logEvents = $this->logFacade->findEventsByType($this->type);
                 $this->logQuery->byLogEvent(array_keys($logEvents));
             }
         } else {
             $logTypesNames = $this->logFacade->findTypesNames();
             $this['filter-type']->setItems($logTypesNames);
             if ($this->type !== null) {
                 if (!array_key_exists($this->type, $logTypesNames)) {
                     $this->redirect('this', ['type' => null]);
                 }
                 $this['filter-type']->setDefaultValue($this->type);
                 $logEvents = $this->logFacade->findEventsByType($this->type);
                 $this['filter-event']->setItems($logEvents);
                 if ($this->event !== null) {
                     if (!array_key_exists($this->event, $logEvents)) {
                         $this->redirect('this', ['type' => $this->type, 'event' => null]);
                     }
                     $this['filter-event']->setDefaultValue($this->event);
                     $this->logQuery->byLogEvent($this->event);
                 } else {
                     $this->logQuery->byLogEvent(array_keys($logEvents));
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * @return ITemplate
  */
 protected function createTemplate()
 {
     $template = parent::createTemplate();
     $template->addFilter('formatSizeUnits', function ($size) {
         if ($size >= 1024) {
             return floor($size / 1024) . 'KB';
         }
         return $size . 'B';
     });
     return $template;
 }