Exemplo n.º 1
0
 /**
  * Checks if $key exists.
  * @param  mixed  key or index
  * @return bool
  */
 public function offsetExists($key)
 {
     if (is_int($key)) {
         return (bool) current(array_slice((array) $this, $key, 1));
     }
     return parent::offsetExists($key);
 }
Exemplo n.º 2
0
 public function createThumbnail()
 {
     $args = array_merge($this->defaults, func_get_args()[0]);
     $args = ArrayHash::from($args);
     $storage = $this->media->getStorage($args->storage);
     if (isset($args->namespace)) {
         $storage->setNamespace($args->namespace);
     }
     $image = $storage->load($args->file);
     $width = $args->width;
     $height = $args->height;
     if ($image !== NULL) {
         if ($width && $width != $image->width) {
             $name = $this->createThumbnailName($image, $width, $height);
             $thumb = $storage->absolutePath . '/' . $name;
             $src = NULL;
             if (!file_exists($thumb)) {
                 $image = Image::fromFile($image->absolutePath);
                 if (empty($height)) {
                     $height = $width;
                 }
                 $image->resize($width, $height, constant('Nette\\Image::' . strtoupper($args->flag)));
                 $image->save($thumb);
             }
             $image = $storage->load($name);
         }
         $src = $storage->getBaseUrl() . '/' . $image->filename;
         return $src;
     }
 }
Exemplo n.º 3
0
 protected function normalizeData($data)
 {
     if ($data === NULL || is_array($data)) {
         return ArrayHash::from((array) $data);
     }
     return $data;
 }
Exemplo n.º 4
0
 public function offsetExists($key)
 {
     if (is_int($key)) {
         $arr = array_values((array) $this);
         return isset($arr[$key]);
     }
     return parent::offsetExists($key);
 }
Exemplo n.º 5
0
 /**
  * @return array
  */
 protected function generateBreadCrumb()
 {
     $parts = array(array('link' => $this->link('Dashboard:'), 'name' => 'Admin'), array('link' => $this->link(':' . $this->name . ':'), 'name' => Strings::getLastPiece($this->name, ':')), array('link' => $this->link(':' . $this->name . ':' . $this->view), 'name' => $this->view));
     if ($parameter = $this->getParameter('id')) {
         $parts[] = array('link' => $this->link(':' . $this->name . ':' . $this->view, array('id' => $parameter)), 'name' => $parameter);
     }
     return \Nette\ArrayHash::from($parts);
 }
Exemplo n.º 6
0
 public function __construct($data)
 {
     if (is_array($data)) {
         $data = \Nette\ArrayHash::from($data);
     }
     if (!$data instanceof \Traversable || !$data instanceof \Countable) {
         throw new \Nette\InvalidArgumentException('Parameter $data must be an array or implement \\Traversable and \\Countable');
     }
     $this->data = $data;
 }
Exemplo n.º 7
0
 public function getData($key = NULL, $default = NULL)
 {
     if (func_num_args() === 0) {
         return ArrayHash::from($this->query);
     }
     if ($this->has($key)) {
         return $this->query[$key];
     }
     return $default;
 }
Exemplo n.º 8
0
 /**
  * Performs an authentication
  * @param  array
  * @return IIdentity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $email = $credentials[self::USERNAME];
     $userEntity = $this->entityManager->getRepository('User')->findOneBy(array('email' => $email));
     //if(!is_object($userEntity) or !($credentials[self::PASSWORD] == $userEntity->password))
     if (!is_object($userEntity) or !$this->hasher->checkPassword($credentials[self::PASSWORD], $userEntity->password)) {
         throw new AuthenticationException('Email and password mismatch');
     }
     $userData = array('id' => $userEntity->id, 'name' => $userEntity->name, 'email' => $userEntity->email);
     $userData = \Nette\ArrayHash::from($userData, true);
     return new \Nette\Security\Identity($userEntity->id, $userEntity->getRole()->getName(), $userData);
 }
Exemplo n.º 9
0
 public function createLink()
 {
     $args = array_merge($this->defaults, func_get_args()[0]);
     $args = ArrayHash::from($args);
     $storage = $this->media->getStorage($args->storage);
     if (isset($args->namespace)) {
         $storage->setNamespace($args->namespace);
     }
     $image = $storage->load($args->file);
     if ($image !== NULL) {
         return $storage->getBaseUrl() . '/' . $image->filename;
     }
 }
Exemplo n.º 10
0
 public function createComponentCalendar()
 {
     $cal = new EventCalendar();
     $cal->setEvents(new \Agility\EventModel($this->calendarRepository, $this->itemRepository, \Nette\ArrayHash::from(array('pageUrl' => $this->pageUrl, 'conditions' => $this->conditions))));
     $cal->setTemplateVar(\Nette\ArrayHash::from(array('filters' => $this->filters, 'isAdmin' => $this->isAdmin())));
     $cal->setLanguage(EventCalendar::CZECH);
     // české názvy měsíců a dnů
     $cal->setMode(EventCalendar::FIRST_MONDAY);
     // týden začne pondělkem
     $cal->setOptions(array("showBottomNav" => FALSE));
     $cal->setOptions(array("topNavPrev" => "Předchozí měsíc", "topNavNext" => "Následující měsíc"));
     return $cal;
 }
Exemplo n.º 11
0
 public function hydrate(Statement $statement)
 {
     $res = $statement->fetchAll(PDO::FETCH_ASSOC);
     if (false !== $res) {
         if ($this->normalize) {
             foreach ($res as $key => $row) {
                 $res[$key] = ArrayHash::from($statement->normalizeRow($row));
             }
         } else {
             foreach ($res as $key => $row) {
                 $res[$key] = ArrayHash::from($row);
             }
         }
     }
     return $res;
 }
Exemplo n.º 12
0
 protected function generateConfig()
 {
     $config = $this->configBuilder;
     $languages = array();
     $i = 0;
     if (!isset($config['cms']['website'])) {
         $config['cms']['website'] = \Nette\ArrayHash::from(array());
     }
     foreach ($this->findAll() as $entity) {
         if ($i++ == 0) {
             $config['cms']['website']['defaultLanguage'] = $entity->alias;
         }
         $languages[] = $entity->alias;
     }
     $config['cms']['website']['languages'] = $languages;
     $config->save();
 }
Exemplo n.º 13
0
 /**
  * @param array $data
  * @param null $files
  */
 function __construct(array $data, $files = null)
 {
     $defaults = array('id' => '', 'action' => '', 'format' => '', 'associations' => array(), 'data' => array(), 'query' => array());
     $this->data = ArrayHash::from(array_merge($defaults, $data));
     $this->filesContainer = new Files($files);
 }
Exemplo n.º 14
0
 public function getItems()
 {
     $results = array_slice($this->results, $this->getOffset(), $this->getLimit(), true);
     return \Nette\ArrayHash::from($results);
 }
Exemplo n.º 15
0
 /**
  * Replaces or appends a item.
  *
  * @param  mixed
  * @param  mixed
  * @return void
  */
 public function offsetSet($index, $value)
 {
     if ($index === NULL) {
         $this->data[] = is_array($value) ? \Nette\ArrayHash::from($value, true) : $value;
     } else {
         $this->data[$index] = is_array($value) ? \Nette\ArrayHash::from($value, true) : $value;
     }
 }
Exemplo n.º 16
0
 /** this create component ItemList */
 protected function createComponentItemList()
 {
     if ($this->items === NULL) {
         $this->error('Wrong action');
     }
     /** pageUrl can't be something else than is in layout.neon, 
      * this is tested in defaultAction()
      */
     $shade = isset($this->pageConfig['settings']['shadePast']) ? $this->pageConfig['settings']['shadePast'] : FALSE;
     return new Agility\ItemListControl($this->items, \Nette\ArrayHash::from(array('page' => $this->pageUrl, 'filters' => $this->filters, 'isAdmin' => $this->isAdmin(), 'shadePast' => $shade)));
 }
Exemplo n.º 17
0
 /**
  * Adds new rule.
  * @param  mixed
  * @param  KeyParser
  * @return void
  */
 public function offsetSet($index, $rule)
 {
     if (!$rule instanceof KeyParser) {
         throw new Nette\InvalidArgumentException('Argument must be ' . __NAMESPACE__ . 'ArrayParser\\KeyParser descendant.');
     }
     parent::offsetSet($index, $rule);
 }
Exemplo n.º 18
0
 /**
  * @param array $params
  * @return NULL|ArrayHash
  */
 public function getPermissions(array $params = array())
 {
     $params = array_merge($params, array('access_token' => $this->facebook->getAccessToken()));
     try {
         $response = $this->facebook->api("/{$this->profileId}/permissions", 'GET', $params);
         if ($response && !empty($response->data[0])) {
             return ArrayHash::from($response->data[0]);
         }
     } catch (FacebookApiException $e) {
         return NULL;
     }
 }
    /**
     * Parses phpDoc comment.
     * @param  string
     * @return array
     */
    private static function parseComment($comment)
    {
        static $tokens = array('true' => TRUE, 'false' => FALSE, 'null' => NULL, '' => TRUE);
        $res = array();
        $comment = preg_replace('#^\\s*\\*\\s?#ms', '', trim($comment, '/*'));
        $parts = preg_split('#^\\s*(?=@' . self::RE_IDENTIFIER . ')#m', $comment, 2);
        $description = trim($parts[0]);
        if ($description !== '') {
            $res['description'] = array($description);
        }
        $matches = Strings::matchAll(isset($parts[1]) ? $parts[1] : '', '~
				(?<=\\s|^)@(' . self::RE_IDENTIFIER . ')[ \\t]*      ##  annotation
				(
					\\((?>' . self::RE_STRING . '|[^\'")@]+)+\\)|  ##  (value)
					[^(@\\r\\n][^@\\r\\n]*|)                     ##  value
			~xi');
        foreach ($matches as $match) {
            list(, $name, $value) = $match;
            if (substr($value, 0, 1) === '(') {
                $items = array();
                $key = '';
                $val = TRUE;
                $value[0] = ',';
                while ($m = Strings::match($value, '#\\s*,\\s*(?>(' . self::RE_IDENTIFIER . ')\\s*=\\s*)?(' . self::RE_STRING . '|[^\'"),\\s][^\'"),]*)#A')) {
                    $value = substr($value, strlen($m[0]));
                    list(, $key, $val) = $m;
                    $val = rtrim($val);
                    if ($val[0] === "'" || $val[0] === '"') {
                        $val = substr($val, 1, -1);
                    } elseif (is_numeric($val)) {
                        $val = 1 * $val;
                    } else {
                        $lval = strtolower($val);
                        $val = array_key_exists($lval, $tokens) ? $tokens[$lval] : $val;
                    }
                    if ($key === '') {
                        $items[] = $val;
                    } else {
                        $items[$key] = $val;
                    }
                }
                $value = count($items) < 2 && $key === '' ? $val : $items;
            } else {
                $value = trim($value);
                if (is_numeric($value)) {
                    $value = 1 * $value;
                } else {
                    $lval = strtolower($value);
                    $value = array_key_exists($lval, $tokens) ? $tokens[$lval] : $value;
                }
            }
            $class = $name . 'Annotation';
            if (self::$useAnnotationClasses && class_exists($class)) {
                $res[$name][] = new $class(is_array($value) ? $value : array('value' => $value));
            } else {
                $res[$name][] = is_array($value) ? Nette\ArrayHash::from($value) : $value;
            }
        }
        return $res;
    }
Exemplo n.º 20
0
 /**
  * Returns the global configuration.
  * @param  string key
  * @param  mixed  default value
  * @return mixed
  */
 public static function getConfig($key = NULL, $default = NULL)
 {
     $params = Nette\ArrayHash::from(self::getContext()->parameters);
     if (func_num_args()) {
         return isset($params[$key]) ? $params[$key] : $default;
     } else {
         return $params;
     }
 }
Exemplo n.º 21
0
 public function __construct($presenter, $name)
 {
     parent::__construct($presenter, $name);
     $this->atr = \Nette\ArrayHash::from(array());
 }
Exemplo n.º 22
0
 public function beforeRender()
 {
     parent::beforeRender();
     $this->viewControl->addAtr(\Nette\ArrayHash::from(array('canAdd' => $this->canAdd)));
     if ($this->isAjax()) {
         // because we want to reset the jqueryui modal window
         $this->invalidateControl('editForm');
     }
 }
Exemplo n.º 23
0
 public function processForm(Form $form)
 {
     if ($form['filter']['filter']->isSubmittedBy()) {
         $filter = $form->values->filter;
         foreach ($filter as $column => $value) {
             if (empty($value)) {
                 unset($filter[$column]);
             }
         }
         $this->filter = $filter;
     } else {
         $values = ArrayHash::from($form->getHttpData());
         if (!isset($values->item)) {
             $this->flashMessage('Nezvolili ste záznamy', 'alert-error');
             return false;
         }
         $items = $values->item;
         $action = $form->submitted->name;
         if (!isset($this->actions[$action])) {
             throw new InvalidArgumentException("Action '{$action}' not found");
         }
         if (count($items) > 0) {
             $data = $this->getRows();
             $rows = [];
             foreach ($items as $item => $checked) {
                 if ($item == 'all') {
                     continue;
                 }
                 if ($checked !== 'on') {
                     continue;
                 }
                 $rows[] = $data[$item];
             }
             $this->actions[$action]->invoke($rows);
             $this->flashMessage('Akcia bola vykonaná.', 'alert-success');
             $this->invalidateControl();
         }
     }
 }
Exemplo n.º 24
0
 /**
  * Returns collections of data from data source at one page.
  *
  * @return ArrayHash
  */
 public function getNextPage()
 {
     $this->load();
     return $this->lastResult ? $this->lastResult->data : ArrayHash::from(array());
 }
Exemplo n.º 25
0
 private function value($key, \Nette\ArrayHash $arr)
 {
     return $arr->offsetExists($key) ? $arr->offsetGet($key) : '';
 }
Exemplo n.º 26
0
 /**
  * Make an API call.
  *
  * @param string|array $pathOrParams
  * @param string $method
  * @param array $params
  * @throws \Kdyby\Facebook\FacebookApiException
  * @return \Nette\ArrayHash|bool|NULL The decoded response
  */
 public function api($pathOrParams, $method = NULL, array $params = array())
 {
     if (is_array($pathOrParams) && empty($this->config->graphVersion)) {
         $response = $this->apiClient->restServer($pathOrParams);
         // params
     } else {
         $response = $this->apiClient->graph($pathOrParams, $method, $params);
     }
     return !is_scalar($response) ? Nette\ArrayHash::from($response) : $response;
 }
Exemplo n.º 27
0
 /**
  * vrátí pole událostí pro daný den
  * @return array
  */
 public function getForDate($year, $month, $day)
 {
     // get events for this day
     $found = $this->calendarRepository->findByDay($year, $month, $day, isset($this->atr->pageUrl) ? $this->atr->pageUrl : NULL);
     // load data for all events - cached
     $this->dataLoad($this->calendarRepository->getIdList());
     $items = array();
     // remove order conditions
     /** test if it is array with allowed content */
     if (!empty($this->atr->conditions)) {
         foreach ($this->atr->conditions as $column => $setting) {
             if (gettype($setting) == 'array' || gettype($setting) == 'object' && get_class($setting) == 'Nette\\ArrayHash') {
                 /** if order is set */
                 if (!empty($setting['order']) && count($setting['order']) && count($column)) {
                     unset($this->atr->conditions[$column]);
                 }
                 continue;
             } else {
                 if (gettype($setting) == 'string') {
                     $where[$column] = $setting;
                 } else {
                     throw new \Exception('Bad parameter conditions!.');
                 }
             }
         }
     }
     $oneDayEvents = array();
     $multiDaysEvents = array();
     //while($item = $found->fetch()){
     foreach ($found as $item) {
         $itemData = $this->monthData[$item->item_id];
         // check for conditions, if they are valid
         $valid = true;
         foreach ($this->atr->conditions as $column => $setting) {
             if (!empty($setting['value'])) {
                 if (isset($itemData->{$column}) && $itemData->{$column} != $setting['value']) {
                     $valid = false;
                     continue;
                 }
             }
         }
         if (!$valid) {
             continue;
         }
         // ---------------------------
         //dump($this->monthData[$item->item_id]);
         $event = \Nette\ArrayHash::from(array('item' => $item, 'id' => $item->item_id, 'page' => $itemData->page, 'data' => json_decode($itemData->content)));
         // sort one and more days events
         if ($item->to != NULL && $item->to != $item->from) {
             $multiDaysEvents[] = $event;
         } else {
             $oneDayEvents[] = $event;
         }
         //dump($item->item_id);
     }
     return array_merge($multiDaysEvents, $oneDayEvents);
 }