Example #1
0
	/**
	 * @param array|\Traversable
	 * @param bool
	 * @return \Nella\Models\IEntity
	 * @throws \Nette\InvalidArgumentException
	 */
	public function create($values, $withoutFlush = FALSE)
	{
		try {
			if (!$values['role'] instanceof \Nella\Security\RoleEntity) {
				$roleService = $this->getContainer()->getService('Nella\Security\RoleEntity');
				$values['role'] = $roleService->repository->find($values['role']);
			}

			$entity = parent::create($values, TRUE);
			$em = $this->getEntityManager();
			$em->persist($entity);
			if (!$withoutFlush) {
				$em->flush();
			}
			return $entity;
		} catch (\PDOException $e) {
			$this->processPDOException($e);
		}
	}
Example #2
0
	public function testGetClassMetadata()
	{
		$this->assertInstanceOf('Doctrine\ORM\Mapping\ClassMetadata', $this->service->getClassMetadata(), "->getClassMetadata() is instaceof Doctrine ClassMetadata");
		$this->assertInstanceOf('Doctrine\ORM\Mapping\ClassMetadata', $this->service->classMetadata, "->classMetadata is instaceof Doctrine ClassMetadata");
	}
Example #3
0
	/**
	 * @param \Nella\Media\BaseFileEntity
	 * @return \Doctrine\ORM\EntityManager
	 * @throws \Nette\InvalidArgumentException
	 * @throws \Nella\Models\Exception
	 * @throws \Nella\Models\EmptyValueException
	 * @throws \Nella\Models\DuplicateEntryException
	 */
	public function delete(\Nella\Models\IEntity $entity)
	{
		$class = get_class($entity);
		if ($class == 'Nella\Media\FileEntity' || $class == 'Nella\Media\ImageEntity') {
			$path = $this->getContainer()->expand(static::STORAGE_DIR);
			$path .= "/" . $entity->path;
			@unlink($path);

			return parent::delete($entity);
		} else {
			return parent::delete($entity);
		}
	}