. */ /** * Type Service. This class provides functionality to * handle types */ require_once(FILESYSTEMROOTPATH."events/include/dao/TypeDao.php"); class TypeService { private $typeDao; /** * Default constructor * * @param TypeDao */ public function __construct(TypeDao $typeDao) { $this->typeDao = $typeDao; } /** * Load a type by id * * @param string id of the type to be loaded * @return Type containing the data of the requested type, or NULL in case type does not exist */ public function load($id) { $type = $this->typeDao->load($id); $ret = array ("id" => $type->getId(), "name" => $type->getName(), "active" => $type->getActive(), "description" => $type->getDescription()); return $ret; } /** * Load all Types * * @return array of Type */ public function loadAll() { $ret = array(); $types = $this->typeDao->loadAll(); foreach( $types as $type ) { $ret[ $type->getId() ] = array ("id" => $type->getId(), "name" => $type->getName(), "active" => $type->getActive(), "description" => $type->getDescription()); } return $ret; } /** * Load all Active Types * * @return array of Type */ public function loadActive() { $ret = array(); $types = $this->typeDao->loadActive(); foreach( $types as $type ) { $ret[ $type->getId() ] = array ("id" => $type->getId(), "name" => $type->getName(), "active" => $type->getActive(), "description" => $type->getDescription()); } return $ret; } /** * Save or update a type * * @param Type object with the type data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $type) { return $this->typeDao->saveOrUpdate($type); } }