From 38119c8b34af5787f1e3baef56e6917de5cda0e0 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 25 Jul 2010 23:17:30 +0200 Subject: [PATCH] improved controllers and added several minor fixes --- backend/lib/Controller/DataController.php | 6 +++++- backend/lib/Controller/GroupController.php | 11 ++++++++--- backend/lib/Model/Channel.php | 6 +++++- backend/lib/Model/Group.php | 13 ++++++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/backend/lib/Controller/DataController.php b/backend/lib/Controller/DataController.php index 94dbfcf..f277119 100644 --- a/backend/lib/Controller/DataController.php +++ b/backend/lib/Controller/DataController.php @@ -35,10 +35,12 @@ use Volkszaehler\Util; class DataController extends Controller { /** + * query for data + * * @todo authentification/indentification + * @todo use uuids for groups or channels */ public function get() { - // TODO use uuids for groups or channels $ids = explode(',', trim($this->view->request->getParameter('ids'))); $q = $this->em->createQuery('SELECT c FROM Volkszaehler\Model\Channel c WHERE c.id IN (' . implode(', ', $ids) . ')'); @@ -55,7 +57,9 @@ class DataController extends Controller { } /** + * log new readings * + * @todo authentification/indentification */ public function add() { $ucid = $this->view->request->getParameter('ucid'); diff --git a/backend/lib/Controller/GroupController.php b/backend/lib/Controller/GroupController.php index 366976c..18f519c 100644 --- a/backend/lib/Controller/GroupController.php +++ b/backend/lib/Controller/GroupController.php @@ -35,11 +35,16 @@ class GroupController extends Controller { /** * get groups by filter + * + * @todo filter to root groups when using recursion */ public function get() { - $dql = 'SELECT g FROM Volkszaehler\Model\Group g'; + $dql = 'SELECT g, c, d FROM Volkszaehler\Model\Group g LEFT JOIN g.children c LEFT JOIN g.channels d'; - $recursion = $this->view->request->getParameter('recursion'); + // TODO fix this (depending on DDC-719) + if ($recursion = $this->view->request->getParameter('recursion')) { + //$dql .= ' WHERE g.parents IS EMPTY'; + } if ($uuid = $this->view->request->getParameter('uuid')) { // TODO add conditions @@ -64,7 +69,7 @@ class GroupController extends Controller { $ugid = $this->view->request->getParameter('ugid'); $parent = $this->em->getRepository('Volkszaehler\Model\Group')->findOneBy(array('uuid' => $ugid)); - if ($parent === FALSE) { + if ($parent == FALSE) { throw new \Exception('every group needs a parent'); } diff --git a/backend/lib/Model/Channel.php b/backend/lib/Model/Channel.php index ae81f38..ec5d579 100644 --- a/backend/lib/Model/Channel.php +++ b/backend/lib/Model/Channel.php @@ -45,7 +45,7 @@ class Channel extends Entity { protected $indicator; /** - * @OneToMany(targetEntity="Data", mappedBy="channel"), cascade={"remove"} + * @OneToMany(targetEntity="Data", mappedBy="channel", cascade={"remove"}) */ protected $data = NULL; @@ -55,6 +55,9 @@ class Channel extends Entity { /** @Column(type="decimal", precision="5", scale="2", nullable=true) */ protected $cost; + /** @ManyToMany(targetEntity="Group", mappedBy="channels") */ + protected $groups; + /** * indicator => interpreter, unit mapping */ @@ -79,6 +82,7 @@ class Channel extends Entity { $this->indicator = $indicator; $this->data = new ArrayCollection(); + $this->groups = new ArrayCollection(); } /** diff --git a/backend/lib/Model/Group.php b/backend/lib/Model/Group.php index b241ba3..10f3a53 100644 --- a/backend/lib/Model/Group.php +++ b/backend/lib/Model/Group.php @@ -44,7 +44,7 @@ class Group extends Entity { protected $description; /** - * @ManyToMany(targetEntity="Channel") + * @ManyToMany(targetEntity="Channel", inversedBy="groups") * @JoinTable(name="groups_channel", * joinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="channel_id", referencedColumnName="id")} @@ -53,7 +53,7 @@ class Group extends Entity { protected $channels = NULL; /** - * @ManyToMany(targetEntity="Group") + * @ManyToMany(targetEntity="Group", inversedBy="parents") * @JoinTable(name="groups_groups", * joinColumns={@JoinColumn(name="parent_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="child_id", referencedColumnName="id")} @@ -61,6 +61,11 @@ class Group extends Entity { */ protected $children = NULL; + /** + * @ManyToMany(targetEntity="Group", mappedBy="children") + */ + protected $parents = NULL; + /** * construct */ @@ -69,6 +74,7 @@ class Group extends Entity { $this->channels = new ArrayCollection(); $this->children = new ArrayCollection(); + $this->parents = new ArrayCollection(); } /** @@ -99,7 +105,8 @@ class Group extends Entity { public function setName($name) { $this->name = $name; } public function getDescription() { return $this->description; } public function setDescription($description) { $this->description = $description; } - public function getSubGroups() { return $this->children; } + public function getChildren() { return $this->children; } + public function getParents() { return $this->parents; } public function getChannels() { return $this->channels; } }