2010-07-18 17:12:00 +02:00
|
|
|
<?php
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
2010-07-22 18:37:14 +02:00
|
|
|
* @package default
|
2010-07-21 12:44:01 +02:00
|
|
|
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
|
2010-07-22 16:21:26 +02:00
|
|
|
*/
|
|
|
|
/*
|
2010-07-21 12:44:01 +02:00
|
|
|
* This file is part of volkzaehler.org
|
2010-07-18 17:12:00 +02:00
|
|
|
*
|
2010-07-21 12:44:01 +02:00
|
|
|
* volkzaehler.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2010-07-18 17:12:00 +02:00
|
|
|
*
|
2010-07-21 12:44:01 +02:00
|
|
|
* volkzaehler.org is distributed in the hope that it will be useful,
|
2010-07-18 17:12:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-07-21 12:44:01 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-07-18 17:12:00 +02:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2010-07-21 12:44:01 +02:00
|
|
|
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-18 17:12:00 +02:00
|
|
|
*/
|
|
|
|
|
2010-07-19 18:55:18 +02:00
|
|
|
namespace Volkszaehler\Model;
|
2010-07-18 17:12:00 +02:00
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
|
|
|
/**
|
2010-07-21 12:44:01 +02:00
|
|
|
* Channel entity
|
2010-07-18 17:12:00 +02:00
|
|
|
*
|
2010-07-21 12:44:01 +02:00
|
|
|
* @author Steffen Vogel <info@steffenvogel.de>
|
2010-07-22 18:37:14 +02:00
|
|
|
* @package default
|
2010-07-22 10:32:51 +02:00
|
|
|
*
|
2010-07-18 17:12:00 +02:00
|
|
|
* @Entity
|
|
|
|
*/
|
2010-07-20 00:32:52 +02:00
|
|
|
class Channel extends Entity {
|
2010-07-18 17:12:00 +02:00
|
|
|
/**
|
2010-07-25 23:17:30 +02:00
|
|
|
* @OneToMany(targetEntity="Data", mappedBy="channel", cascade={"remove"})
|
2010-07-31 17:52:48 +02:00
|
|
|
* @OrderBy({"timestamp" = "ASC"})
|
2010-07-18 17:12:00 +02:00
|
|
|
*/
|
2010-07-20 22:43:08 +02:00
|
|
|
protected $data = NULL;
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-25 23:17:30 +02:00
|
|
|
/** @ManyToMany(targetEntity="Group", mappedBy="channels") */
|
|
|
|
protected $groups;
|
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
2010-08-24 15:33:55 +02:00
|
|
|
* Constructor
|
2010-07-18 17:12:00 +02:00
|
|
|
*/
|
2010-08-24 15:33:55 +02:00
|
|
|
public function __construct($properties = array()) {
|
|
|
|
parent::__construct($properties);
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-18 17:12:00 +02:00
|
|
|
$this->data = new ArrayCollection();
|
2010-07-25 23:17:30 +02:00
|
|
|
$this->groups = new ArrayCollection();
|
2010-07-18 17:12:00 +02:00
|
|
|
}
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
2010-07-29 00:04:33 +02:00
|
|
|
* Add a new data to the database
|
2010-07-20 22:43:08 +02:00
|
|
|
* @todo move to Logger\Logger?
|
2010-07-18 17:12:00 +02:00
|
|
|
*/
|
|
|
|
public function addData(\Volkszaehler\Model\Data $data) {
|
|
|
|
$this->data->add($data);
|
|
|
|
}
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
2010-07-29 00:04:33 +02:00
|
|
|
* Obtain channel interpreter to obtain data and statistical information for a given time interval
|
|
|
|
*
|
|
|
|
* @param Doctrine\ORM\EntityManager $em
|
|
|
|
* @param integer $from timestamp in ms since 1970
|
|
|
|
* @param integer $to timestamp in ms since 1970
|
|
|
|
* @return Interpreter
|
2010-07-18 17:12:00 +02:00
|
|
|
*/
|
2010-07-28 00:39:23 +02:00
|
|
|
public function getInterpreter(\Doctrine\ORM\EntityManager $em, $from, $to) {
|
|
|
|
$interpreterClassName = 'Volkszaehler\Interpreter\\' . ucfirst($this->getType()) . 'Interpreter';
|
|
|
|
return new $interpreterClassName($this, $em, $from, $to);
|
2010-07-18 17:12:00 +02:00
|
|
|
}
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-29 00:04:33 +02:00
|
|
|
/**
|
|
|
|
* Validate
|
|
|
|
*
|
|
|
|
* @PrePersist @PreUpdate
|
|
|
|
*/
|
|
|
|
protected function validate() {
|
|
|
|
if ($this->getResolution() <= 0 && $this->getType() == 'meter') {
|
|
|
|
throw new Exception('resolution has to be a positive integer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
2010-07-19 18:55:18 +02:00
|
|
|
* getter & setter
|
2010-07-31 17:52:48 +02:00
|
|
|
*
|
|
|
|
* @todo change to new property model
|
2010-07-19 18:55:18 +02:00
|
|
|
*/
|
|
|
|
public function getName() { return $this->name; }
|
|
|
|
public function setName($name) { $this->name = $name; }
|
|
|
|
public function getDescription() { return $this->description; }
|
|
|
|
public function setDescription($description) { $this->description = $description; }
|
2010-07-28 00:39:23 +02:00
|
|
|
|
2010-07-19 18:55:18 +02:00
|
|
|
public function getResolution() { return $this->resolution; }
|
|
|
|
public function setResolution($resolution) { $this->resolution = $resolution; }
|
|
|
|
public function getCost() { return $this->cost; }
|
|
|
|
public function setCost($cost) { $this->cost = $cost; }
|
2010-07-22 10:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|