improved controllers and added several minor fixes
This commit is contained in:
parent
d997ca4ad4
commit
38119c8b34
4 changed files with 28 additions and 8 deletions
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue