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
|
|
|
|
* @Table(name="channels")
|
|
|
|
*/
|
2010-07-20 00:32:52 +02:00
|
|
|
class Channel extends Entity {
|
2010-07-24 13:05:23 +02:00
|
|
|
/** @Column(type="string", nullable=false) */
|
2010-07-18 17:12:00 +02:00
|
|
|
protected $name;
|
|
|
|
|
2010-07-24 13:05:23 +02:00
|
|
|
/** @Column(type="string", nullable=true) */
|
2010-07-18 17:12:00 +02:00
|
|
|
protected $description;
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-24 13:05:23 +02:00
|
|
|
/** @Column(type="string", nullable=false) */
|
2010-07-18 17:12:00 +02:00
|
|
|
protected $indicator;
|
|
|
|
|
|
|
|
/**
|
2010-07-25 23:17:30 +02:00
|
|
|
* @OneToMany(targetEntity="Data", mappedBy="channel", cascade={"remove"})
|
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-24 13:05:23 +02:00
|
|
|
/** @Column(type="integer", nullable=true) */
|
2010-07-20 22:43:08 +02:00
|
|
|
protected $resolution;
|
2010-07-19 18:55:18 +02:00
|
|
|
|
2010-07-24 13:05:23 +02:00
|
|
|
/** @Column(type="decimal", precision="5", scale="2", nullable=true) */
|
2010-07-20 22:43:08 +02:00
|
|
|
protected $cost;
|
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-07-19 18:55:18 +02:00
|
|
|
* indicator => interpreter, unit mapping
|
|
|
|
*/
|
|
|
|
protected static $indicators = array(
|
2010-07-28 00:39:23 +02:00
|
|
|
'power' => array('meter', 'W'),
|
|
|
|
'gas' => array('meter', 'm³'),
|
|
|
|
'water' => array('meter', 'm³'),
|
|
|
|
'temperature' => array('sensor', '°C'),
|
2010-07-19 18:55:18 +02:00
|
|
|
'pressure' => array('sensor', 'hPa'),
|
|
|
|
'humidity' => array('sensor', '%')
|
|
|
|
);
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-21 12:44:01 +02:00
|
|
|
/**
|
2010-07-18 17:12:00 +02:00
|
|
|
* constructor
|
|
|
|
*/
|
|
|
|
public function __construct($indicator) {
|
|
|
|
parent::__construct();
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-28 00:39:23 +02:00
|
|
|
if (!in_array($indicator, array_keys(self::$indicators))) {
|
2010-07-24 13:05:23 +02:00
|
|
|
throw new \Exception($indicator . ' is no known indicator');
|
2010-07-19 18:55:18 +02:00
|
|
|
}
|
2010-07-22 10:32:51 +02:00
|
|
|
|
2010-07-18 17:12:00 +02:00
|
|
|
$this->indicator = $indicator;
|
|
|
|
$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-18 17:12:00 +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-18 17:12:00 +02:00
|
|
|
* obtain channels data interpreter to calculate statistical information
|
|
|
|
*/
|
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-21 12:44:01 +02:00
|
|
|
/**
|
2010-07-19 18:55:18 +02:00
|
|
|
* getter & setter
|
|
|
|
*/
|
|
|
|
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-28 00:39:23 +02:00
|
|
|
|
|
|
|
public function getType() { return self::$indicators[$this->indicator][0]; }
|
|
|
|
public function getUnit() { return self::$indicators[$this->indicator][1]; }
|
|
|
|
public function getIndicator() { return $this->indicator; }
|
2010-07-22 10:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|