2 namespace Workspace\Service;
4 use Zend\ServiceManager\ServiceLocatorAwareInterface;
5 use Zend\ServiceManager\ServiceLocatorInterface;
10 * Abstract service node to provide global functionality to all workspace services.
11 * @author andre.fourie
13 abstract class Node implements ServiceLocatorAwareInterface
17 * @var ServiceLocatorInterface
21 * @var \Workspace\Workflow
27 protected $entityMap = array();
31 * @see \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator()
33 public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
35 $this->services = $serviceLocator;
36 $this->workflow->setServiceLocator($serviceLocator);
40 * @see \Zend\ServiceManager\ServiceLocatorAwareInterface::getServiceLocator()
42 public function getServiceLocator()
44 return $this->services;
48 * Retrieve Doctrine Entity Manager.
49 * @return \Doctrine\ORM\EntityManager
51 public function getEntityManager()
53 return $this->services->get('doctrine.entitymanager.orm_default');
57 * Validate unique value for a specified field.
58 * @param \Workspace\Utility\ServiceInputParams $contract
59 * @return multitype:string unknown NULL
61 public function fieldIsUnique(\Workspace\Utility\ServiceInputParams $contract)
63 if (!isset($this->entityMap[$contract->Group]))
65 return $contract->error(
66 'Invalid `Group` specified.',
70 $entityName = $this->entityMap[$contract->Group];
71 $entry = $this->getEntityManager()
72 ->getRepository($entityName)
73 ->findOneBy(array($contract->Field => $contract->Value));
74 return is_null($entry)
75 ? $contract->success()
76 : $contract->error('Value already used.', 'Value already used.');
80 * List available tasks.
81 * @param string $state
84 public function listTasks($state = 'Global')
86 return $this->workflow->listStateTasks($state);