. */ namespace Volkszaehler\Controller; use Volkszaehler\Definition; use Volkszaehler\Model; use Volkszaehler\Util; /** * Channel controller * * @author Steffen Vogel * @package default */ class ChannelController extends EntityController { /** * Get channel */ public function get($identifier = NULL) { $channel = parent::get($identifier); if (is_array($channel)) { // filter public entities return array('channels' => array_values(array_filter($channel['entities'], function($ch) { return ($ch instanceof Model\Channel); }))); } else if ($channel instanceof Model\Channel) { return $channel; } else { throw new \Exception($identifier . ' is not a channel'); } } /** * Add channel */ public function add() { $type = $this->view->request->getParameter('type'); if (!isset($type)) { throw new \Exception('Missing entity type'); } $channel = new Model\Channel($type); $this->setProperties($channel, $this->view->request->getParameters()); $this->em->persist($channel); $this->em->flush(); return $channel; } } ?>