Пример #1
0
 protected function getLabels()
 {
     $ret = array();
     foreach ($this->labelRepository->findAll() as $label) {
         $ret[] = $label->name;
     }
     return $ret;
 }
Пример #2
0
 public function createNew($arguments = array())
 {
     /** @var BaseFileEntity $entity */
     $entity = parent::createNew($arguments);
     $entity->setUser($this->container->getByType('Nette\\Security\\User'));
     return $entity;
 }
Пример #3
0
 /**
  * @return AdminGrid
  */
 protected function createComponentTable()
 {
     $_this = $this;
     $admin = new AdminGrid($this->repository);
     // columns
     $table = $admin->getTable();
     $table->setModel(new Doctrine($this->repository->createQueryBuilder('a')->addSelect('r')->innerJoin('a.route', 'r')->andWhere('a.extendedPage = :page')->setParameter('page', $this->extendedPage->id), array('name' => 'r.name', 'created' => 'r.created')));
     $table->setDefaultSort(array('created' => 'DESC'));
     $table->addColumnText('name', 'Name')->setCustomRender(function ($entity) {
         return $entity->route->name;
     })->setSortable()->getCellPrototype()->width = '70%';
     $table->getColumn('name')->setFilterText()->setSuggestion();
     $table->addColumnDate('created', 'Created')->setCustomRender(function ($entity) {
         return $entity->route->created->format('Y-m-d H:i:s');
     })->setSortable()->getCellPrototype()->width = '30%';
     // actions
     $table->addAction('publish', 'Published')->setCustomRender(function ($entity, $element) {
         if ((bool) $entity->route->published) {
             $element->class[] = 'btn-primary';
         }
         return $element;
     })->setCustomHref(function ($entity) use($_this) {
         return $_this->link('publish!', array($entity->id));
     })->getElementPrototype()->class[] = 'ajax';
     $table->addAction('preview', 'Preview')->setCustomHref(function ($entity) use($_this) {
         return $_this->link('preview!', array($entity->id));
     });
     $table->addAction('edit', 'Edit')->getElementPrototype()->class[] = 'ajax';
     return $admin;
 }
Пример #4
0
 /**
  * Setup permission by role
  *
  * @param Permission $permission
  * @param string $role
  * @return Permission
  */
 protected function setPermissionsByRole(Permission $permission, $role)
 {
     if ($role == 'admin') {
         $permission->allow('admin', Permission::ALL);
         return $permission;
     }
     if ($this->checkConnection->invoke()) {
         $roleEntity = $this->roleRepository->findOneByName($role);
         if ($roleEntity) {
             if ($roleEntity->parent) {
                 $this->setPermissionsByRole($permission, $roleEntity->parent->name);
             }
             if ($roleEntity && !$permission->hasRole($role)) {
                 $permission->addRole($role, $roleEntity->parent ? $roleEntity->parent->name : NULL);
             }
             // allow/deny
             foreach ($roleEntity->permissions as $perm) {
                 if ($permission->hasResource($perm->resource)) {
                     if ($perm->allow) {
                         $permission->allow($role, $perm->resource, $perm->privilege ? $perm->privilege : NULL);
                     } else {
                         $permission->deny($role, $perm->resource, $perm->privilege ? $perm->privilege : NULL);
                     }
                 }
             }
         }
     }
     return $permission;
 }
Пример #5
0
 public function delete($entity, $withoutFlush = self::FLUSH)
 {
     if (!$entity instanceof PageEntity && !$entity instanceof ExtendedPageEntity) {
         throw new InvalidArgumentException("Entity must be instance of 'CmsModule\\Content\\Entities\\PageEntity'. '" . get_class($entity) . "' given.");
     }
     return parent::delete($entity, $withoutFlush);
 }
Пример #6
0
 public function formSuccess(Venne\Forms\Form $form)
 {
     if ($form['_submit']->isSubmittedBy()) {
         $action = $form['_action']->getValue();
         $button = $this[$action];
         $values = $form['items']->getValues();
         foreach ($values as $key => $value) {
             if ($value) {
                 $button->onClick($button, $this->repository->find(substr($key, 5)));
             }
         }
         $button->onSuccess($this);
     } else {
         if ($form['_filters']->isSubmittedBy()) {
             $this->filters = $form['filters']->getValues();
             foreach ($this->filters as $key => $value) {
                 if (!$value) {
                     unset($this->filters[$key]);
                 }
             }
             $this['vp']->page = 1;
             if (!$this->presenter->isAjax()) {
                 $this->redirect('this');
             }
             unset($this['actionForm']);
             unset($this['vp']);
             $this->invalidateControl('table-body');
             $this->invalidateControl('table-foot');
             $this->presenter->payload->url = $this->link('this');
         } else {
             if ($form['_reset']->isSubmittedBy()) {
                 $form['filters']->setValues(array());
                 $this->filters = array();
                 $this['vp']->page = 1;
                 if (!$this->presenter->isAjax()) {
                     $this->redirect('this');
                 }
                 unset($this['actionForm']);
                 unset($this['vp']);
                 $this->invalidateControl('table-body');
                 $this->invalidateControl('table-foot');
                 $this->presenter->payload->url = $this->link('this');
             } else {
                 if ($form['perPageSubmit']->isSubmittedBy()) {
                     $this->perPage = $form['perPage']->value;
                     $this['vp']->page = 1;
                     if (!$this->presenter->isAjax()) {
                         $this->redirect('this');
                     }
                     unset($this['actionForm']);
                     unset($this['vp']);
                     $this->invalidateControl('table-body');
                     $this->invalidateControl('table-foot');
                     $this->presenter->payload->url = $this->link('this');
                 }
             }
         }
     }
 }
Пример #7
0
 public function createNew($arguments = array())
 {
     if (!count($arguments)) {
         $userPage = $this->getEntityManager()->getRepository('CmsModule\\Content\\Entities\\PageEntity')->findOneBy(array('special' => 'users'));
         $arguments = array($this->getEntityManager()->getRepository($userPage->class)->findOneBy(array('page' => $userPage->id)));
     }
     return parent::createNew($arguments);
 }
Пример #8
0
 public function save($entity, $withoutFlush = self::FLUSH)
 {
     $en = $entity;
     while ($en = $en->getParent()) {
         if ($en == $entity) {
             throw new \Nette\InvalidArgumentException('Cyclic recursion detected. Please set else parent.');
         }
     }
     return parent::save($entity, $withoutFlush);
 }
Пример #9
0
 /**
  * Performs an authentication
  *
  * @param  array
  * @return \Nette\Security\Identity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     try {
         return parent::authenticate($credentials);
     } catch (AuthenticationException $ex) {
         list($username, $password) = $credentials;
         if ($this->checkConnection->invoke()) {
             $user = $this->userRepository->findOneBy(array('email' => $username, 'published' => 1));
             if (!$user) {
                 throw $ex;
             }
             if (!$user->verifyByPassword($password)) {
                 throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
             }
             return new Identity($user->id, $user->getRoles());
         }
         throw $ex;
     }
 }
Пример #10
0
 /**
  * @param LanguageEntity $entity
  * @param bool $withoutFlush
  * @return mixed
  */
 public function delete($entity, $withoutFlush = self::FLUSH)
 {
     //		foreach ($entity->getPages() as $page) {
     //			if (count($page->getLanguages()) == 1) {
     //				throw new \Nette\InvalidArgumentException("Language '{$entity->name}' require some pages which have content only in this language.");
     //			}
     //		}
     $ret = parent::delete($entity, $withoutFlush);
     $this->generateConfig();
     return $ret;
 }
Пример #11
0
 public function authenticate(array $credentials)
 {
     if ($this->checkConnection->invoke()) {
         $data = $this->getData();
         try {
             /** @var $user \CmsModule\Pages\Users\UserEntity */
             $user = $this->userRepository->createQueryBuilder('a')->join('a.socialLogins', 's')->where('s.type = :type AND s.uniqueKey = :key')->setParameter('type', $this->getType())->setParameter('key', $data['id'])->getQuery()->getSingleResult();
         } catch (\Doctrine\ORM\NoResultException $e) {
         }
         if (!isset($user) || !$user) {
             throw new AuthenticationException($this->translator->translate('User does not exist.'), self::INVALID_CREDENTIAL);
         }
         return new Identity($user->email, $user->getRoles());
     }
 }
Пример #12
0
 /** ------------------------ Callbacks --------------------------------- */
 public function tableDelete($action, $id, $redirect = TRUE)
 {
     if (is_array($id)) {
         foreach ($id as $item) {
             $this->tableDelete($action, $item, FALSE);
         }
     } else {
         $this->repository->delete($this->repository->find($id));
     }
     if ($redirect) {
         if (!$this->presenter->isAjax()) {
             $this->redirect('this');
         }
         $this->invalidateControl('table');
         $this->presenter->payload->url = $this->link('this');
     }
 }
Пример #13
0
 /**
  * @param array $arguments
  * @return TagEntity
  */
 public function createNew($arguments = array())
 {
     return parent::createNew(array($this->getRssPageEntity()));
 }