From e8e2e8fae12b86995ca5c4696d36ed8980556d3e Mon Sep 17 00:00:00 2001 From: Knut Kohl Date: Wed, 31 Aug 2016 13:39:28 +0200 Subject: [PATCH 01/16] Several fixes --- api/r6/index.php | 2 + api/r6/routes/data.php | 2 +- core/Channel.php | 99 +- core/Channel/Accumulator.php | 3 + core/Channel/Baseline.php | 20 +- core/Channel/DatabaseUsage.php | 4 +- core/Channel/History.php | 103 +- frontend/View/Index/content.private.inc.tpl | 2 - frontend/View/Index/content.public.inc.tpl | 1 - frontend/View/Index/script.js.html | 504 ++-- frontend/View/Mobile/footer.inc.tpl | 2 +- frontend/View/Mobile/script.js.html | 50 +- public/css/min.css | 2 +- public/css/min.css.gz | Bin 23603 -> 24098 bytes public/css/spectrum.css | 161 +- public/css/spectrum.min.css | 2 +- public/js/min.js | 2 +- public/js/min.js.gz | Bin 139700 -> 141828 bytes public/js/min.mobile.js.gz | Bin 3536 -> 3536 bytes public/js/script.js | 2 +- public/js/script.min.js | 2 +- public/js/spectrum.js | 2363 ++++++++++++------- public/js/spectrum.min.js | 2 +- sql/patches/007.sql | 57 + sql/pvlng.data.sql | 1 - 25 files changed, 2081 insertions(+), 1305 deletions(-) create mode 100644 sql/patches/007.sql diff --git a/api/r6/index.php b/api/r6/index.php index 92b2378..3687e81 100644 --- a/api/r6/index.php +++ b/api/r6/index.php @@ -8,6 +8,8 @@ * @version 1.0.0 */ +set_time_limit(0); + define('DEVELOP', (isset($_SERVER['HTTP_X_DEBUG']) AND $_SERVER['HTTP_X_DEBUG'])); if (DEVELOP) { diff --git a/api/r6/routes/data.php b/api/r6/routes/data.php index 45f187ff..422139d 100644 --- a/api/r6/routes/data.php +++ b/api/r6/routes/data.php @@ -30,7 +30,7 @@ function($guid) use ($api) try { $cnt = Channel::byGUID($guid)->write($request, $timestamp); } catch (Exception $e) { - $api->stopAPI($e->getMessage(), 400); + $api->stopAPI($e->getMessage(), $e->getCode() ?: 400); } if ($cnt) $api->stopAPI($cnt.' reading(s) added', 201); diff --git a/core/Channel.php b/core/Channel.php index 3c87150..e651b62 100644 --- a/core/Channel.php +++ b/core/Channel.php @@ -9,6 +9,9 @@ */ abstract class Channel { + /** + * + */ public static $Database; /** @@ -404,6 +407,7 @@ public function read( $request ) { ->limit(1); $row = $this->db->queryRow($q); + if (!$row) return $this->after_read($buffer); $buffer->write((array) $row); @@ -437,19 +441,22 @@ public function read( $request ) { if ($this->period[1] == self::LAST OR $this->period[1] == self::ALL) { + // Select plain data $q->get($q->FROM_UNIXTIME('timestamp'), 'datetime') ->get('timestamp') ->get('data') ->get('data', 'min') ->get('data', 'max') ->get(1, 'count') - ->get(0, 'timediff') - ->get('timestamp', 'g'); + ->get(0, 'timediff'); } else { - $q->get($q->FROM_UNIXTIME($q->MIN('timestamp')), 'datetime') - ->get($q->MIN('timestamp'), 'timestamp'); + // Select data grouped by period + $timestamp = $this->groupTimestampByPeriod(); + + $q->get($q->FROM_UNIXTIME($timestamp), 'datetime') + ->get($timestamp, 'timestamp'); switch (TRUE) { // Raw data for non-numeric channels @@ -474,8 +481,7 @@ public function read( $request ) { ->get($q->MAX('data'), 'max') ->get($q->COUNT('id'), 'count') ->get($q->MAX('timestamp').'-'.$q->MIN('timestamp'), 'timediff') - ->get($this->periodGrouping(), 'g') - ->group('g'); + ->group($timestamp); } $q->filter('id', $this->entity)->order('timestamp'); @@ -498,7 +504,7 @@ public function read( $request ) { if ($row['timestamp'] >= $this->start) { $row['data'] = 0; $row['consumption'] = 0; - $this->writeReadingToBuffer($buffer, $row); + $buffer->write($row, $row['timestamp']); } // Read remaining rows @@ -513,13 +519,13 @@ public function read( $request ) { $row['consumption'] = $row['data'] - $last; $last = $row['data']; - $this->writeReadingToBuffer($buffer, $row); + $buffer->write($row, $row['timestamp']); } } } else { // Use all readings as is while ($row = $res->fetch_assoc()) { - $this->writeReadingToBuffer($buffer, $row); + $buffer->write($row, $row['timestamp']); } } @@ -567,35 +573,35 @@ public function __destruct() { * Grouping */ const NO = 0; - const ASCHILD = 1; // Required for grouping by at least 1 minute - const MINUTE = 10; - const HOUR = 20; - const DAY = 30; - const WEEK = 40; - const MONTH = 50; - const QUARTER = 60; + const SECOND = 10; + const MINUTE = 20; + const HOUR = 30; + const DAY = 40; + const WEEK = 50; + const MONTH = 60; + const QUARTER = 61; const YEAR = 70; const LAST = 80; const READLAST = 81; - const ALL = 90; + const ALL = 99; /** * Period in seconds for each grouping period and SQL equivalent * Hold static only once in memory */ - protected static $Grouping = array( - self::NO => array( 0, '`timestamp`' ), - self::ASCHILD => array( 60, '`timestamp` DIV 60' ), - self::MINUTE => array( 60, '`timestamp` DIV (60 * %d)' ), - self::HOUR => array( 3600, 'FROM_UNIXTIME(`timestamp`, "%%Y%%j%%H") DIV %d' ), - self::DAY => array( 86400, 'FROM_UNIXTIME(`timestamp`, "%%Y%%j") DIV %d' ), - self::WEEK => array( 604800, 'FROM_UNIXTIME(`timestamp`, "%%x%%v") DIV %d' ), - self::MONTH => array( 2678400, 'FROM_UNIXTIME(`timestamp`, "%%Y%%m") DIV %d' ), - self::QUARTER => array( 7776000, 'FROM_UNIXTIME(`timestamp`, "%%Y%%m") DIV (3 * %d)' ), - self::YEAR => array( 31536000, 'FROM_UNIXTIME(`timestamp`, "%%Y") DIV %d'), - self::LAST => array( 0, '`timestamp`' ), - self::READLAST => array( 0, '`timestamp`' ), - self::ALL => array( 0, '`timestamp`' ) + protected static $secondsPerPeriod = array( + self::NO => 1, + self::SECOND => 1, + self::MINUTE => 60, + self::HOUR => 3600, + self::DAY => 86400, + self::WEEK => 604800, + self::MONTH => 2678400, + self::QUARTER => 7776000, + self::YEAR => 31536000, + self::LAST => 1, + self::READLAST => 1, + self::ALL => 1 ); /** @@ -679,8 +685,14 @@ protected function __construct( ORM\Tree $channel ) { /** * */ - protected function periodGrouping() { - return sprintf(self::$Grouping[$this->period[1]][1], $this->period[0]); + protected function groupTimestampByPeriod() { + return $this->period[0] * self::$secondsPerPeriod[$this->period[1]] == 1 + ? '`timestamp`' + : sprintf( + '`timestamp` DIV (%1$d * %2$d) * %1$d * %2$d', + $this->period[0], + self::$secondsPerPeriod[$this->period[1]] + ); } /** @@ -839,7 +851,8 @@ protected function before_read( &$request ) { // Normalize aggregation period if (preg_match( - '~^([.\d]*)(|l|last|r|readlast|i|min|minutes?|h|hours?|'. + '~^([.\d]*)(|l|last|r|readlast|'. + 's|sec|seconds?|i|min|minutes?|h|hours?|'. 'd|days?|w|weeks?|m|months?|q|quarters?|y|years|a|all)$~', strtolower($request['period']), $args @@ -849,6 +862,7 @@ protected function before_read( &$request ) { switch (substr($args[2], 0, 2)) { default: $this->period[1] = self::NO; break; + case 's': case 'se': $this->period[1] = self::SECOND; break; case 'i': case 'mi': $this->period[1] = self::MINUTE; break; case 'h': case 'ho': $this->period[1] = self::HOUR; break; case 'd': case 'da': $this->period[1] = self::DAY; break; @@ -864,6 +878,8 @@ protected function before_read( &$request ) { throw new \Exception('Unknown aggregation period: ' . $request['period'], 400); } +/* Obsolete with temp. table buffering + // If no period is set for channels with childs, align child data at least to 1 min. if ($this->childs != 0 AND $this->period[1] == self::NO) { // Correct period for this channel @@ -871,6 +887,7 @@ protected function before_read( &$request ) { // Correct period for later child channel reads $request['period'] = '1min'; } +*/ } /** @@ -948,10 +965,11 @@ protected function after_read( Buffer $buffer ) { protected function filterReadTimestamp( &$q ) { if ($this->period[1] == self::ALL) return; - // Read one period before real start for meter calculation + // Read one period before real start for meter calculations $start = $this->meter - ? $this->start - $this->period[0] * self::$Grouping[$this->period[1]][0] + ? $this->start - $this->period[0] * self::$secondsPerPeriod[$this->period[1]] : $this->start; + // End is midnight > minus 1 second $q->filter('timestamp', array('bt' => array($start, $this->end-1))); } @@ -967,17 +985,6 @@ protected function SQLHeader( $request, $q ) { Header('X-SQL-' . uniqid() . ': ' . $sql . ': ' . preg_replace('~\n+~', ' ', $q)); } - /** - * Shortcut method to save cleaned reading to buffer - */ - protected function writeReadingToBuffer(&$buffer, array $data) - { - // Remember and remove grouping column and save - $id = $data['g']; - unset($data['g']); - $buffer->write($data, $id); - } - /** * Shortcut method for save array access */ diff --git a/core/Channel/Accumulator.php b/core/Channel/Accumulator.php index 74ad7ce..9a62c7c 100644 --- a/core/Channel/Accumulator.php +++ b/core/Channel/Accumulator.php @@ -38,6 +38,9 @@ public function read( $request ) { default: $this->meter = $childs[0]->meter; $lazy = !$this->extra; + if (empty($request['period'])) { + $request['period'] = '1i'; + } $buffer = $childs[0]->read($request); // Combine all data for same timestamp diff --git a/core/Channel/Baseline.php b/core/Channel/Baseline.php index 26f3a60..27da0d9 100644 --- a/core/Channel/Baseline.php +++ b/core/Channel/Baseline.php @@ -15,8 +15,8 @@ /** * */ -class Baseline extends InternalCalc { - +class Baseline extends InternalCalc +{ // ----------------------------------------------------------------------- // PROTECTED // ----------------------------------------------------------------------- @@ -24,14 +24,16 @@ class Baseline extends InternalCalc { /** * */ - protected function before_read( &$request ) { - + protected function before_read(&$request) + { parent::before_read($request); - if (!$this->dataExists()) { - // Calc direct inside database - $this->db->query('CALL pvlng_model_baseline({1}, {2})', $this->entity, $this->getChild(1)->entity); - $this->dataCreated(); - } + if ($this->dataExists()) return; + + // Calc direct inside database + $this->db->query('CALL pvlng_model_baseline({1}, {2})', $this->entity, $this->getChild(1)->entity); + + $this->dataCreated(); } + } diff --git a/core/Channel/DatabaseUsage.php b/core/Channel/DatabaseUsage.php index afcec98..18a9393 100644 --- a/core/Channel/DatabaseUsage.php +++ b/core/Channel/DatabaseUsage.php @@ -16,16 +16,18 @@ class DatabaseUsage extends Channel { /** * */ - public function read( $request ) { + public function __read( $request ) { $this->performance->setAction('read'); $this->before_read($request); +/* if ($this->period[1] == self::NO) { // Set period to at least 1 minute $this->period[1] = self::ASCHILD; } +*/ $q = new \DBQuery; diff --git a/core/Channel/History.php b/core/Channel/History.php index 6238074..b156ca5 100644 --- a/core/Channel/History.php +++ b/core/Channel/History.php @@ -41,15 +41,19 @@ public function read( $request ) { $result = new \Buffer; - if ($this->period[0] * self::$Grouping[$this->period[1]][0] < 600) { + if ($this->period[0] * self::$secondsPerPeriod[$this->period[1]] < 600) { // Smooth result at least 10 minutes $this->period = array(10, self::MINUTE); } + $secondsRange = $this->period[0] * self::$secondsPerPeriod[$this->period[1]]; + + $timestamp = $this->groupTimestampByPeriod(); + // Prepare inner query $q = new \DBQuery('pvlng_reading_num_tmp'); - $q->get($q->FROM_UNIXTIME('timestamp', '"%H"'), 'hour') - ->get($q->FROM_UNIXTIME('timestamp', '"%i"'), 'minute'); + $q->get($q->FROM_UNIXTIME($timestamp, '"%H"'), 'hour') + ->get($q->FROM_UNIXTIME($timestamp, '"%i"'), 'minute'); if ($this->meter) { $q->get($q->MAX('data'), 'data'); @@ -76,7 +80,7 @@ public function read( $request ) { $q->get($q->MIN('data'), 'min') ->get($q->MAX('data'), 'max') ->get($q->COUNT(0), 'count') - ->get($this->periodGrouping(), 'g') + ->get($timestamp, 'g') ->filter('id', $this->entity) ->groupBy('g'); @@ -86,32 +90,68 @@ public function read( $request ) { do { $h = clone $inner; - $h->filter('timestamp', array('bt' => array($day - $this->valid_from * 86400, $day - $this->valid_from * 86400 + 86400))); - $q = (new \DBQuery)->select('('.substr($h, 0, -1).') t')->groupBy('hour')->groupBy('minute'); + $start = $day - $this->valid_from * 86400; + +# $h->filter('timestamp', array('bt' => array($start, $start + $this->valid_from * 86400))); + + $h->filter(sprintf( + 'FROM_UNIXTIME(`timestamp`, "%%j") BETWEEN + IF (FROM_UNIXTIME(%1$s, "%%j") < FROM_UNIXTIME(%2$s, "%%j"), + FROM_UNIXTIME(%1$s, "%%j"), FROM_UNIXTIME(%1$s, "%%j") - 365) + AND + IF (FROM_UNIXTIME(%2$s, "%%j") > FROM_UNIXTIME(%1$s, "%%j"), + FROM_UNIXTIME(%2$s, "%%j"), FROM_UNIXTIME(%2$s, "%%j") + 365)', + $start, $start + $this->valid_from * 86400 + )); + +/* + +FROM_UNIXTIME(`timestamp`, '%j') BETWEEN +IF (FROM_UNIXTIME(&1$s, '%j') < FROM_UNIXTIME(&2$s, '%j'), FROM_UNIXTIME(&1$s, '%j'), FROM_UNIXTIME(&1$s, '%j')-365) +AND +IF (FROM_UNIXTIME(&2$s, '%j') > FROM_UNIXTIME(&1$s, '%j'), FROM_UNIXTIME(&2$s, '%j'), FROM_UNIXTIME(&2$s, '%j')+365) + +*/ + + + + $q = (new \DBQuery)->select('('.substr($h, 0, -1).') t'); + $q->get('hour') + ->get('minute') + ->get('data') + ->get($q->MIN('min'), 'min') + ->get($q->MAX('max'), 'max') + ->get($q->SUM('count'), 'count') + ->groupBy('hour') + ->groupBy('minute'); + + $this->SQLHeader($request, $q); -#echo $q; $d = date('d', $day); $m = date('m', $day); $y = date('Y', $day); - if ($res = $this->db->query($h)) { - $first = TRUE; + if ($res = $this->db->query($q)) { + $first = true; + while ($row = $res->fetch_object()) { $ts = mktime($row->hour, $row->minute, 0, $m, $d, $y); + if ($first) { $result->write(array( - 'datetime' => date('Y-m-d H:i:s', $ts-60), - 'timestamp' => $ts-60, + 'datetime' => date('Y-m-d H:i:s', $ts-$secondsRange), + 'timestamp' => $ts-$secondsRange, 'data' => 0, 'min' => 0, 'max' => 0, 'count' => 1, 'timediff' => 0, 'consumption' => 0 - ), $row->g-1); - $first = FALSE; + ), $ts-$secondsRange); + $first = false; } + $result->write(array( 'datetime' => date('Y-m-d H:i:s', $ts), 'timestamp' => $ts, @@ -121,29 +161,32 @@ public function read( $request ) { 'count' => +$row->count, 'timediff' => 0, 'consumption' => 0 - ), $row->g); + ), $ts); $last = $row; } + if (isset($last)) { $result->write(array( - 'datetime' => date('Y-m-d H:i:s', $ts+60), - 'timestamp' => $ts+60, + 'datetime' => date('Y-m-d H:i:s', $ts+$secondsRange), + 'timestamp' => $ts+$secondsRange, 'data' => 0, 'min' => 0, 'max' => 0, 'count' => 1, 'timediff' => 0, 'consumption' => 0 - ), $last->g+1); + ), $ts+$secondsRange); } + } - $day += 24*60*60; + $day += 86400; + } while ($day < $this->end); // Skip validity handling of after_read! - $this->valid_from = $this->valid_to = NULL; + $this->valid_from = $this->valid_to = null; return $this->after_read($result); } @@ -166,7 +209,7 @@ protected function before_read( &$request ) { if (!$child) return; // Read out all data - $request['period'] = '1i'; + unset($request['period']); // Inherit properties from child $this->meter = $child->meter; @@ -180,17 +223,21 @@ protected function before_read( &$request ) { // Save data into temp. table $this->saveValues($child->read($request)); } else { - // Find earliest data - $q = new \DBQuery('pvlng_reading_num'); - $q->get($q->FROM_UNIXTIME($q->MIN('timestamp'), '"%Y"')); - for ($i=$this->db->queryOne($q)-date('Y'); $i<=0; $i++) { - $request['start'] = strtotime(date('Y-m-d ', $this->start - $this->valid_from * 86400).$i.'years'); - $request['end'] = strtotime(date('Y-m-d ', $this->end + $this->valid_to * 86400).$i.'years'); + $back = $this->valid_from * 86400; + $foreward = $this->valid_to * 86400; + + // Clone request + $r = array_merge(array(), $request); + + for ($y=1970; $ystart) . ' -' . $this->valid_from . 'days'; + $r['end'] = date($y.'-m-d', $this->start) . ' +' . $this->valid_to . 'days'; // Save data into temp. table - $this->saveValues($child->read($request)); + $this->saveValues($child->read($r)); } + } - $this->dataCreated(TRUE); + $this->dataCreated(true); } } diff --git a/frontend/View/Index/content.private.inc.tpl b/frontend/View/Index/content.private.inc.tpl index 3c0cb01..956dd85 100644 --- a/frontend/View/Index/content.private.inc.tpl +++ b/frontend/View/Index/content.private.inc.tpl @@ -48,8 +48,6 @@ class="alias"> - o diff --git a/frontend/View/Index/content.public.inc.tpl b/frontend/View/Index/content.public.inc.tpl index d6ce34b..f310bcd 100644 --- a/frontend/View/Index/content.public.inc.tpl +++ b/frontend/View/Index/content.public.inc.tpl @@ -34,7 +34,6 @@ - o diff --git a/frontend/View/Index/script.js.html b/frontend/View/Index/script.js.html index e2f58f2..658b39b 100644 --- a/frontend/View/Index/script.js.html +++ b/frontend/View/Index/script.js.html @@ -15,11 +15,10 @@ diff --git a/frontend/View/Scatter/style.css b/frontend/View/Scatter/style.css new file mode 100644 index 0000000..7dc496a --- /dev/null +++ b/frontend/View/Scatter/style.css @@ -0,0 +1,50 @@ +/** + * + * + * @author Knut Kohl + * @copyright 2012-2014 Knut Kohl + * @license MIT License (MIT) http://opensource.org/licenses/MIT + * @version 1.0.0 + */ + +#top-select { + display: none; + padding: 3em 0; + font-weight: bold; + text-align: center; +} + +#zoom-hint { + display: none; + font-size: smaller; + text-align: center; + margin-bottom: 2em; +} + +#chart { + margin-top: 1em; +} + +.spaced { + margin: .75em 0; +} + +.icheckbox_line disabled, +.iradio_line disabled { + background-color: #606060; +} + +.confirmed .ui-button-text { + color: red; + font-weight: bold; +} + +.disabled { + color: #C0C0C0; +} + +.iradio_flat, +.icheckbox_flat { + float: left; + margin-right: .25em; +} From 25045898b21a779956ba14223297a3bc9e656f08 Mon Sep 17 00:00:00 2001 From: Knut Kohl Date: Sat, 10 Sep 2016 22:09:59 +0200 Subject: [PATCH 05/16] Minor fixes in channel logic --- core/Channel.php | 20 +- core/ORM/ChannelBase.php | 48 ++-- core/ORM/ChannelTypeBase.php | 22 +- core/ORM/ChannelViewBase.php | 54 ++--- core/ORM/ConfigBase.php | 6 +- core/ORM/DashboardBase.php | 10 +- core/ORM/LogBase.php | 8 +- core/ORM/PerformanceBase.php | 6 +- core/ORM/ReadingCalculatedBase.php | 18 +- core/ORM/ReadingLast.php | 29 +++ core/ORM/ReadingLastBase.php | 244 ++++++++++++++++++++ core/ORM/ReadingNum.php | 13 +- core/ORM/ReadingNumBase.php | 10 +- core/ORM/ReadingNumMemoryBase.php | 10 +- core/ORM/ReadingStatisticsBase.php | 20 +- core/ORM/ReadingStr.php | 13 +- core/ORM/ReadingStrBase.php | 10 +- core/ORM/ReadingStrMemoryBase.php | 10 +- core/ORM/SettingsBase.php | 20 +- core/ORM/SettingsKeysBase.php | 4 +- core/ORM/TariffBase.php | 6 +- core/ORM/TariffDateBase.php | 10 +- core/ORM/TariffTimeBase.php | 20 +- core/ORM/TariffViewBase.php | 18 +- core/ORM/Tree.php | 120 +++++++++- core/ORM/TreeBase.php | 76 +++--- core/ORM/ViewBase.php | 12 +- frontend/View/Index/content.private.inc.tpl | 2 +- frontend/View/Index/script.js.html | 14 +- lib/slimMVC/ORM.php | 27 ++- public/css/min.css.gz | Bin 24117 -> 24117 bytes public/js/min.js.gz | Bin 142698 -> 142698 bytes public/js/min.mobile.js.gz | Bin 4445 -> 4445 bytes sql/patches/009.sql | 102 ++++++++ tools/upgrade.git | 4 +- 35 files changed, 731 insertions(+), 255 deletions(-) create mode 100644 core/ORM/ReadingLast.php create mode 100644 core/ORM/ReadingLastBase.php create mode 100644 sql/patches/009.sql diff --git a/core/Channel.php b/core/Channel.php index 4ed691b..0badd99 100644 --- a/core/Channel.php +++ b/core/Channel.php @@ -47,11 +47,11 @@ public static function byId($id, $alias=true) public static function byGUID($guid, $alias=true) { if ($guid == '') { - throw new \Exception('Missing channel GUID!'); + throw new \Exception('Missing channel GUID!', 400); } $channel = new \ORM\Tree; - $channel->filterRaw('`guid` like "'.$guid.'%"')->findOne(); + $channel->filter('guid', array('like' => $guid.'%'))->findOne(); $aliasOf = $channel->getAliasOf(); if ($aliasOf && $alias) { @@ -75,7 +75,7 @@ public static function byGUID($guid, $alias=true) } } - throw new \Exception('No channel found for GUID: '.$guid, 400); + throw new \Exception('No channel found for GUID: '.$guid, 404); } /** @@ -285,7 +285,8 @@ public function write($request, $timestamp=null) // Default behavior $reading = \ORM\Reading::factory($this->numeric); - $this->lastReading = $reading->getLastReading($this->entity, $timestamp); + $this->lastReading = \ORM\ReadingLast::f($this->entity)->getData(); +# $this->lastReading = $reading->getLastReading($this->entity, $timestamp); $this->before_write($request); @@ -342,7 +343,7 @@ public function update($request, $timestamp) // Default behavior $reading = \ORM\Reading::factory($this->numeric); - $this->lastReading = $reading->getLastReading($this->entity, $timestamp); + $this->lastReading = \ORM\ReadingLast::f($this->entity)->getData(); $this->check_before_write($request, $timestamp); @@ -905,7 +906,10 @@ protected function after_read(\Buffer $buffer) foreach ($buffer as $id=>$row) { // Filter out data produced by meter channels with large periods - if ($row['timestamp'] < $this->start || $row['timestamp'] > $this->end) continue; + if ($this->meter && + ($row['timestamp'] < $this->start || $row['timestamp'] > $this->end)) { + continue; + } if ($checkMeter) { /* check meter values raising */ @@ -1013,7 +1017,7 @@ private function read_LastRow() : DBQuery::forge($this->table[$this->numeric]); // Fetch last reading and set some data to 0 to get correct field order - $q->get($q->FROM_UNIXTIME('timestamp'), 'datetime') + return $q->get($q->FROM_UNIXTIME('timestamp'), 'datetime') ->get('timestamp') ->get('data') ->get(0, 'min') @@ -1024,8 +1028,6 @@ private function read_LastRow() ->filter('id', $this->entity) ->orderDescending('timestamp') ->limit(1); - - return $q; } /** diff --git a/core/ORM/ChannelBase.php b/core/ORM/ChannelBase.php index afce604..7e03bce 100644 --- a/core/ORM/ChannelBase.php +++ b/core/ORM/ChannelBase.php @@ -843,7 +843,7 @@ public function getIcon() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -855,7 +855,7 @@ public function filterById($id) */ public function filterByGuid($guid) { - $this->filter[] = '`guid` = '.$this->quote($guid); + $this->filter[] = $this->field('guid').' = '.$this->quote($guid); return $this; } // filterByGuid() @@ -867,7 +867,7 @@ public function filterByGuid($guid) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -879,7 +879,7 @@ public function filterByType($type) */ public function filterByTariff($tariff) { - $this->filter[] = '`tariff` = '.$this->quote($tariff); + $this->filter[] = $this->field('tariff').' = '.$this->quote($tariff); return $this; } // filterByTariff() @@ -891,7 +891,7 @@ public function filterByTariff($tariff) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -903,7 +903,7 @@ public function filterByName($name) */ public function filterByDescription($description) { - $this->filter[] = '`description` = '.$this->quote($description); + $this->filter[] = $this->field('description').' = '.$this->quote($description); return $this; } // filterByDescription() @@ -915,7 +915,7 @@ public function filterByDescription($description) */ public function filterBySerial($serial) { - $this->filter[] = '`serial` = '.$this->quote($serial); + $this->filter[] = $this->field('serial').' = '.$this->quote($serial); return $this; } // filterBySerial() @@ -927,7 +927,7 @@ public function filterBySerial($serial) */ public function filterByChannel($channel) { - $this->filter[] = '`channel` = '.$this->quote($channel); + $this->filter[] = $this->field('channel').' = '.$this->quote($channel); return $this; } // filterByChannel() @@ -939,7 +939,7 @@ public function filterByChannel($channel) */ public function filterByResolution($resolution) { - $this->filter[] = '`resolution` = '.$this->quote($resolution); + $this->filter[] = $this->field('resolution').' = '.$this->quote($resolution); return $this; } // filterByResolution() @@ -951,7 +951,7 @@ public function filterByResolution($resolution) */ public function filterByUnit($unit) { - $this->filter[] = '`unit` = '.$this->quote($unit); + $this->filter[] = $this->field('unit').' = '.$this->quote($unit); return $this; } // filterByUnit() @@ -963,7 +963,7 @@ public function filterByUnit($unit) */ public function filterByDecimals($decimals) { - $this->filter[] = '`decimals` = '.$this->quote($decimals); + $this->filter[] = $this->field('decimals').' = '.$this->quote($decimals); return $this; } // filterByDecimals() @@ -975,7 +975,7 @@ public function filterByDecimals($decimals) */ public function filterByMeter($meter) { - $this->filter[] = '`meter` = '.$this->quote($meter); + $this->filter[] = $this->field('meter').' = '.$this->quote($meter); return $this; } // filterByMeter() @@ -987,7 +987,7 @@ public function filterByMeter($meter) */ public function filterByNumeric($numeric) { - $this->filter[] = '`numeric` = '.$this->quote($numeric); + $this->filter[] = $this->field('numeric').' = '.$this->quote($numeric); return $this; } // filterByNumeric() @@ -999,7 +999,7 @@ public function filterByNumeric($numeric) */ public function filterByOffset($offset) { - $this->filter[] = '`offset` = '.$this->quote($offset); + $this->filter[] = $this->field('offset').' = '.$this->quote($offset); return $this; } // filterByOffset() @@ -1011,7 +1011,7 @@ public function filterByOffset($offset) */ public function filterByAdjust($adjust) { - $this->filter[] = '`adjust` = '.$this->quote($adjust); + $this->filter[] = $this->field('adjust').' = '.$this->quote($adjust); return $this; } // filterByAdjust() @@ -1023,7 +1023,7 @@ public function filterByAdjust($adjust) */ public function filterByCost($cost) { - $this->filter[] = '`cost` = '.$this->quote($cost); + $this->filter[] = $this->field('cost').' = '.$this->quote($cost); return $this; } // filterByCost() @@ -1035,7 +1035,7 @@ public function filterByCost($cost) */ public function filterByThreshold($threshold) { - $this->filter[] = '`threshold` = '.$this->quote($threshold); + $this->filter[] = $this->field('threshold').' = '.$this->quote($threshold); return $this; } // filterByThreshold() @@ -1047,7 +1047,7 @@ public function filterByThreshold($threshold) */ public function filterByValidFrom($valid_from) { - $this->filter[] = '`valid_from` = '.$this->quote($valid_from); + $this->filter[] = $this->field('valid_from').' = '.$this->quote($valid_from); return $this; } // filterByValidFrom() @@ -1059,7 +1059,7 @@ public function filterByValidFrom($valid_from) */ public function filterByValidTo($valid_to) { - $this->filter[] = '`valid_to` = '.$this->quote($valid_to); + $this->filter[] = $this->field('valid_to').' = '.$this->quote($valid_to); return $this; } // filterByValidTo() @@ -1071,7 +1071,7 @@ public function filterByValidTo($valid_to) */ public function filterByPublic($public) { - $this->filter[] = '`public` = '.$this->quote($public); + $this->filter[] = $this->field('public').' = '.$this->quote($public); return $this; } // filterByPublic() @@ -1083,7 +1083,7 @@ public function filterByPublic($public) */ public function filterByTags($tags) { - $this->filter[] = '`tags` = '.$this->quote($tags); + $this->filter[] = $this->field('tags').' = '.$this->quote($tags); return $this; } // filterByTags() @@ -1095,7 +1095,7 @@ public function filterByTags($tags) */ public function filterByExtra($extra) { - $this->filter[] = '`extra` = '.$this->quote($extra); + $this->filter[] = $this->field('extra').' = '.$this->quote($extra); return $this; } // filterByExtra() @@ -1107,7 +1107,7 @@ public function filterByExtra($extra) */ public function filterByComment($comment) { - $this->filter[] = '`comment` = '.$this->quote($comment); + $this->filter[] = $this->field('comment').' = '.$this->quote($comment); return $this; } // filterByComment() @@ -1119,7 +1119,7 @@ public function filterByComment($comment) */ public function filterByIcon($icon) { - $this->filter[] = '`icon` = '.$this->quote($icon); + $this->filter[] = $this->field('icon').' = '.$this->quote($icon); return $this; } // filterByIcon() diff --git a/core/ORM/ChannelTypeBase.php b/core/ORM/ChannelTypeBase.php index 94e658c..fc649ab 100644 --- a/core/ORM/ChannelTypeBase.php +++ b/core/ORM/ChannelTypeBase.php @@ -421,7 +421,7 @@ public function getIcon() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -433,7 +433,7 @@ public function filterById($id) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -445,7 +445,7 @@ public function filterByName($name) */ public function filterByChilds($childs) { - $this->filter[] = '`childs` = '.$this->quote($childs); + $this->filter[] = $this->field('childs').' = '.$this->quote($childs); return $this; } // filterByChilds() @@ -457,7 +457,7 @@ public function filterByChilds($childs) */ public function filterByRead($read) { - $this->filter[] = '`read` = '.$this->quote($read); + $this->filter[] = $this->field('read').' = '.$this->quote($read); return $this; } // filterByRead() @@ -469,7 +469,7 @@ public function filterByRead($read) */ public function filterByWrite($write) { - $this->filter[] = '`write` = '.$this->quote($write); + $this->filter[] = $this->field('write').' = '.$this->quote($write); return $this; } // filterByWrite() @@ -481,7 +481,7 @@ public function filterByWrite($write) */ public function filterByDescription($description) { - $this->filter[] = '`description` = '.$this->quote($description); + $this->filter[] = $this->field('description').' = '.$this->quote($description); return $this; } // filterByDescription() @@ -493,7 +493,7 @@ public function filterByDescription($description) */ public function filterByModel($model) { - $this->filter[] = '`model` = '.$this->quote($model); + $this->filter[] = $this->field('model').' = '.$this->quote($model); return $this; } // filterByModel() @@ -505,7 +505,7 @@ public function filterByModel($model) */ public function filterByUnit($unit) { - $this->filter[] = '`unit` = '.$this->quote($unit); + $this->filter[] = $this->field('unit').' = '.$this->quote($unit); return $this; } // filterByUnit() @@ -517,7 +517,7 @@ public function filterByUnit($unit) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -529,7 +529,7 @@ public function filterByType($type) */ public function filterByGraph($graph) { - $this->filter[] = '`graph` = '.$this->quote($graph); + $this->filter[] = $this->field('graph').' = '.$this->quote($graph); return $this; } // filterByGraph() @@ -541,7 +541,7 @@ public function filterByGraph($graph) */ public function filterByIcon($icon) { - $this->filter[] = '`icon` = '.$this->quote($icon); + $this->filter[] = $this->field('icon').' = '.$this->quote($icon); return $this; } // filterByIcon() diff --git a/core/ORM/ChannelViewBase.php b/core/ORM/ChannelViewBase.php index 37b26f3..ae68fc0 100644 --- a/core/ORM/ChannelViewBase.php +++ b/core/ORM/ChannelViewBase.php @@ -321,7 +321,7 @@ public function getTree() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -333,7 +333,7 @@ public function filterById($id) */ public function filterByGuid($guid) { - $this->filter[] = '`guid` = '.$this->quote($guid); + $this->filter[] = $this->field('guid').' = '.$this->quote($guid); return $this; } // filterByGuid() @@ -345,7 +345,7 @@ public function filterByGuid($guid) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -357,7 +357,7 @@ public function filterByName($name) */ public function filterBySerial($serial) { - $this->filter[] = '`serial` = '.$this->quote($serial); + $this->filter[] = $this->field('serial').' = '.$this->quote($serial); return $this; } // filterBySerial() @@ -369,7 +369,7 @@ public function filterBySerial($serial) */ public function filterByChannel($channel) { - $this->filter[] = '`channel` = '.$this->quote($channel); + $this->filter[] = $this->field('channel').' = '.$this->quote($channel); return $this; } // filterByChannel() @@ -381,7 +381,7 @@ public function filterByChannel($channel) */ public function filterByDescription($description) { - $this->filter[] = '`description` = '.$this->quote($description); + $this->filter[] = $this->field('description').' = '.$this->quote($description); return $this; } // filterByDescription() @@ -393,7 +393,7 @@ public function filterByDescription($description) */ public function filterByResolution($resolution) { - $this->filter[] = '`resolution` = '.$this->quote($resolution); + $this->filter[] = $this->field('resolution').' = '.$this->quote($resolution); return $this; } // filterByResolution() @@ -405,7 +405,7 @@ public function filterByResolution($resolution) */ public function filterByCost($cost) { - $this->filter[] = '`cost` = '.$this->quote($cost); + $this->filter[] = $this->field('cost').' = '.$this->quote($cost); return $this; } // filterByCost() @@ -417,7 +417,7 @@ public function filterByCost($cost) */ public function filterByNumeric($numeric) { - $this->filter[] = '`numeric` = '.$this->quote($numeric); + $this->filter[] = $this->field('numeric').' = '.$this->quote($numeric); return $this; } // filterByNumeric() @@ -429,7 +429,7 @@ public function filterByNumeric($numeric) */ public function filterByOffset($offset) { - $this->filter[] = '`offset` = '.$this->quote($offset); + $this->filter[] = $this->field('offset').' = '.$this->quote($offset); return $this; } // filterByOffset() @@ -441,7 +441,7 @@ public function filterByOffset($offset) */ public function filterByAdjust($adjust) { - $this->filter[] = '`adjust` = '.$this->quote($adjust); + $this->filter[] = $this->field('adjust').' = '.$this->quote($adjust); return $this; } // filterByAdjust() @@ -453,7 +453,7 @@ public function filterByAdjust($adjust) */ public function filterByUnit($unit) { - $this->filter[] = '`unit` = '.$this->quote($unit); + $this->filter[] = $this->field('unit').' = '.$this->quote($unit); return $this; } // filterByUnit() @@ -465,7 +465,7 @@ public function filterByUnit($unit) */ public function filterByDecimals($decimals) { - $this->filter[] = '`decimals` = '.$this->quote($decimals); + $this->filter[] = $this->field('decimals').' = '.$this->quote($decimals); return $this; } // filterByDecimals() @@ -477,7 +477,7 @@ public function filterByDecimals($decimals) */ public function filterByMeter($meter) { - $this->filter[] = '`meter` = '.$this->quote($meter); + $this->filter[] = $this->field('meter').' = '.$this->quote($meter); return $this; } // filterByMeter() @@ -489,7 +489,7 @@ public function filterByMeter($meter) */ public function filterByThreshold($threshold) { - $this->filter[] = '`threshold` = '.$this->quote($threshold); + $this->filter[] = $this->field('threshold').' = '.$this->quote($threshold); return $this; } // filterByThreshold() @@ -501,7 +501,7 @@ public function filterByThreshold($threshold) */ public function filterByValidFrom($valid_from) { - $this->filter[] = '`valid_from` = '.$this->quote($valid_from); + $this->filter[] = $this->field('valid_from').' = '.$this->quote($valid_from); return $this; } // filterByValidFrom() @@ -513,7 +513,7 @@ public function filterByValidFrom($valid_from) */ public function filterByValidTo($valid_to) { - $this->filter[] = '`valid_to` = '.$this->quote($valid_to); + $this->filter[] = $this->field('valid_to').' = '.$this->quote($valid_to); return $this; } // filterByValidTo() @@ -525,7 +525,7 @@ public function filterByValidTo($valid_to) */ public function filterByPublic($public) { - $this->filter[] = '`public` = '.$this->quote($public); + $this->filter[] = $this->field('public').' = '.$this->quote($public); return $this; } // filterByPublic() @@ -537,7 +537,7 @@ public function filterByPublic($public) */ public function filterByTypeId($type_id) { - $this->filter[] = '`type_id` = '.$this->quote($type_id); + $this->filter[] = $this->field('type_id').' = '.$this->quote($type_id); return $this; } // filterByTypeId() @@ -549,7 +549,7 @@ public function filterByTypeId($type_id) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -561,7 +561,7 @@ public function filterByType($type) */ public function filterByModel($model) { - $this->filter[] = '`model` = '.$this->quote($model); + $this->filter[] = $this->field('model').' = '.$this->quote($model); return $this; } // filterByModel() @@ -573,7 +573,7 @@ public function filterByModel($model) */ public function filterByChilds($childs) { - $this->filter[] = '`childs` = '.$this->quote($childs); + $this->filter[] = $this->field('childs').' = '.$this->quote($childs); return $this; } // filterByChilds() @@ -585,7 +585,7 @@ public function filterByChilds($childs) */ public function filterByRead($read) { - $this->filter[] = '`read` = '.$this->quote($read); + $this->filter[] = $this->field('read').' = '.$this->quote($read); return $this; } // filterByRead() @@ -597,7 +597,7 @@ public function filterByRead($read) */ public function filterByWrite($write) { - $this->filter[] = '`write` = '.$this->quote($write); + $this->filter[] = $this->field('write').' = '.$this->quote($write); return $this; } // filterByWrite() @@ -609,7 +609,7 @@ public function filterByWrite($write) */ public function filterByGraph($graph) { - $this->filter[] = '`graph` = '.$this->quote($graph); + $this->filter[] = $this->field('graph').' = '.$this->quote($graph); return $this; } // filterByGraph() @@ -621,7 +621,7 @@ public function filterByGraph($graph) */ public function filterByIcon($icon) { - $this->filter[] = '`icon` = '.$this->quote($icon); + $this->filter[] = $this->field('icon').' = '.$this->quote($icon); return $this; } // filterByIcon() @@ -633,7 +633,7 @@ public function filterByIcon($icon) */ public function filterByTree($tree) { - $this->filter[] = '`tree` = '.$this->quote($tree); + $this->filter[] = $this->field('tree').' = '.$this->quote($tree); return $this; } // filterByTree() diff --git a/core/ORM/ConfigBase.php b/core/ORM/ConfigBase.php index a104666..152d2d2 100644 --- a/core/ORM/ConfigBase.php +++ b/core/ORM/ConfigBase.php @@ -149,7 +149,7 @@ public function getComment() */ public function filterByKey($key) { - $this->filter[] = '`key` = '.$this->quote($key); + $this->filter[] = $this->field('key').' = '.$this->quote($key); return $this; } // filterByKey() @@ -161,7 +161,7 @@ public function filterByKey($key) */ public function filterByValue($value) { - $this->filter[] = '`value` = '.$this->quote($value); + $this->filter[] = $this->field('value').' = '.$this->quote($value); return $this; } // filterByValue() @@ -173,7 +173,7 @@ public function filterByValue($value) */ public function filterByComment($comment) { - $this->filter[] = '`comment` = '.$this->quote($comment); + $this->filter[] = $this->field('comment').' = '.$this->quote($comment); return $this; } // filterByComment() diff --git a/core/ORM/DashboardBase.php b/core/ORM/DashboardBase.php index a507d3f..e61ee0e 100644 --- a/core/ORM/DashboardBase.php +++ b/core/ORM/DashboardBase.php @@ -197,7 +197,7 @@ public function getSlug() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -209,7 +209,7 @@ public function filterById($id) */ public function filterBySlug($slug) { - $this->filter[] = '`slug` = '.$this->quote($slug); + $this->filter[] = $this->field('slug').' = '.$this->quote($slug); return $this; } // filterBySlug() @@ -221,7 +221,7 @@ public function filterBySlug($slug) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -233,7 +233,7 @@ public function filterByName($name) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() @@ -245,7 +245,7 @@ public function filterByData($data) */ public function filterByPublic($public) { - $this->filter[] = '`public` = '.$this->quote($public); + $this->filter[] = $this->field('public').' = '.$this->quote($public); return $this; } // filterByPublic() diff --git a/core/ORM/LogBase.php b/core/ORM/LogBase.php index 51ff1d0..20273ff 100644 --- a/core/ORM/LogBase.php +++ b/core/ORM/LogBase.php @@ -163,7 +163,7 @@ public function getData() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -175,7 +175,7 @@ public function filterById($id) */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -187,7 +187,7 @@ public function filterByTimestamp($timestamp) */ public function filterByScope($scope) { - $this->filter[] = '`scope` = '.$this->quote($scope); + $this->filter[] = $this->field('scope').' = '.$this->quote($scope); return $this; } // filterByScope() @@ -199,7 +199,7 @@ public function filterByScope($scope) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/PerformanceBase.php b/core/ORM/PerformanceBase.php index b966ffd..dbd2d95 100644 --- a/core/ORM/PerformanceBase.php +++ b/core/ORM/PerformanceBase.php @@ -149,7 +149,7 @@ public function getTime() */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -161,7 +161,7 @@ public function filterByTimestamp($timestamp) */ public function filterByAction($action) { - $this->filter[] = '`action` = '.$this->quote($action); + $this->filter[] = $this->field('action').' = '.$this->quote($action); return $this; } // filterByAction() @@ -173,7 +173,7 @@ public function filterByAction($action) */ public function filterByTime($time) { - $this->filter[] = '`time` = '.$this->quote($time); + $this->filter[] = $this->field('time').' = '.$this->quote($time); return $this; } // filterByTime() diff --git a/core/ORM/ReadingCalculatedBase.php b/core/ORM/ReadingCalculatedBase.php index 4b4e25a..30548ee 100644 --- a/core/ORM/ReadingCalculatedBase.php +++ b/core/ORM/ReadingCalculatedBase.php @@ -252,9 +252,9 @@ public function getCreated() public function filterByIdStartEnd($id, $start, $end) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`start` = '.$this->quote($start).''; - $this->filter[] = '`end` = '.$this->quote($end).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('start').' = '.$this->quote($start).''; + $this->filter[] = $this->field('end').' = '.$this->quote($end).''; return $this; } // filterByIdStartEnd() @@ -266,7 +266,7 @@ public function filterByIdStartEnd($id, $start, $end) */ public function filterByUid($uid) { - $this->filter[] = '`uid` = '.$this->quote($uid); + $this->filter[] = $this->field('uid').' = '.$this->quote($uid); return $this; } // filterByUid() @@ -278,7 +278,7 @@ public function filterByUid($uid) */ public function filterByCreated($created) { - $this->filter[] = '`created` = '.$this->quote($created); + $this->filter[] = $this->field('created').' = '.$this->quote($created); return $this; } // filterByCreated() @@ -290,7 +290,7 @@ public function filterByCreated($created) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -302,7 +302,7 @@ public function filterById($id) */ public function filterByStart($start) { - $this->filter[] = '`start` = '.$this->quote($start); + $this->filter[] = $this->field('start').' = '.$this->quote($start); return $this; } // filterByStart() @@ -314,7 +314,7 @@ public function filterByStart($start) */ public function filterByEnd($end) { - $this->filter[] = '`end` = '.$this->quote($end); + $this->filter[] = $this->field('end').' = '.$this->quote($end); return $this; } // filterByEnd() @@ -326,7 +326,7 @@ public function filterByEnd($end) */ public function filterByLifetime($lifetime) { - $this->filter[] = '`lifetime` = '.$this->quote($lifetime); + $this->filter[] = $this->field('lifetime').' = '.$this->quote($lifetime); return $this; } // filterByLifetime() diff --git a/core/ORM/ReadingLast.php b/core/ORM/ReadingLast.php new file mode 100644 index 0000000..eb8a4a6 --- /dev/null +++ b/core/ORM/ReadingLast.php @@ -0,0 +1,29 @@ + + * @copyright 2016 Knut Kohl + * @license MIT License (MIT) http://opensource.org/licenses/MIT + * @version 1.0.0 + * + * 1.0.0 + * - Initial creation + */ +namespace ORM; + +/** + * + */ +class ReadingLast extends ReadingLastBase +{ + + /** + * Insert your extensions here... + * + * Access table name with $this->table + */ + +} diff --git a/core/ORM/ReadingLastBase.php b/core/ORM/ReadingLastBase.php new file mode 100644 index 0000000..fdf6f2ad --- /dev/null +++ b/core/ORM/ReadingLastBase.php @@ -0,0 +1,244 @@ + + * @copyright 2016 Knut Kohl + * @license MIT License (MIT) http://opensource.org/licenses/MIT + * + * @author PVLng ORM class builder + * @version 1.4.0 / 2016-07-18 + */ +namespace ORM; + +/** + * + */ +abstract class ReadingLastBase extends \slimMVC\ORM +{ + + // ----------------------------------------------------------------------- + // PUBLIC + // ----------------------------------------------------------------------- + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + + /** + * Basic setter for field "id" + * + * @param mixed $id Id value + * @return Instance For fluid interface + */ + public function setId($id) + { + $this->fields['id'] = $id; + return $this; + } // setId() + + /** + * Raw setter for field "id", for INSERT, REPLACE and UPDATE + * + * @param mixed $id Id value + * @return Instance For fluid interface + */ + public function setIdRaw($id) + { + $this->raw['id'] = $id; + return $this; + } // setIdRaw() + + /** + * Basic setter for field "timestamp" + * + * @param mixed $timestamp Timestamp value + * @return Instance For fluid interface + */ + public function setTimestamp($timestamp) + { + $this->fields['timestamp'] = $timestamp; + return $this; + } // setTimestamp() + + /** + * Raw setter for field "timestamp", for INSERT, REPLACE and UPDATE + * + * @param mixed $timestamp Timestamp value + * @return Instance For fluid interface + */ + public function setTimestampRaw($timestamp) + { + $this->raw['timestamp'] = $timestamp; + return $this; + } // setTimestampRaw() + + /** + * Basic setter for field "data" + * + * @param mixed $data Data value + * @return Instance For fluid interface + */ + public function setData($data) + { + $this->fields['data'] = $data; + return $this; + } // setData() + + /** + * Raw setter for field "data", for INSERT, REPLACE and UPDATE + * + * @param mixed $data Data value + * @return Instance For fluid interface + */ + public function setDataRaw($data) + { + $this->raw['data'] = $data; + return $this; + } // setDataRaw() + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + + /** + * Basic getter for field "id" + * + * @return mixed Id value + */ + public function getId() + { + return $this->fields['id']; + } // getId() + + /** + * Basic getter for field "timestamp" + * + * @return mixed Timestamp value + */ + public function getTimestamp() + { + return $this->fields['timestamp']; + } // getTimestamp() + + /** + * Basic getter for field "data" + * + * @return mixed Data value + */ + public function getData() + { + return $this->fields['data']; + } // getData() + + // ----------------------------------------------------------------------- + // Filter methods + // ----------------------------------------------------------------------- + + /** + * Filter for field "id" + * + * @param mixed $id Filter value + * @return Instance For fluid interface + */ + public function filterById($id) + { + $this->filter[] = $this->field('id').' = '.$this->quote($id); + return $this; + } // filterById() + + /** + * Filter for field "timestamp" + * + * @param mixed $timestamp Filter value + * @return Instance For fluid interface + */ + public function filterByTimestamp($timestamp) + { + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); + return $this; + } // filterByTimestamp() + + /** + * Filter for field "data" + * + * @param mixed $data Filter value + * @return Instance For fluid interface + */ + public function filterByData($data) + { + $this->filter[] = $this->field('data').' = '.$this->quote($data); + return $this; + } // filterByData() + + // ----------------------------------------------------------------------- + // PROTECTED + // ----------------------------------------------------------------------- + + /** + * Update fields on insert on duplicate key + */ + protected function onDuplicateKey() + { + return '`timestamp` = '.$this->quote($this->fields['timestamp']).' + , `data` = '.$this->quote($this->fields['data']).''; + } // onDuplicateKey() + + /** + * Table name + * + * @var string $table Table name + */ + protected $table = 'pvlng_reading_last'; + + /** + * SQL for creation + * + * @var string $createSQL + */ + protected $createSQL = ' + CREATE TABLE `pvlng_reading_last` ( + `id` smallint(5) unsigned NOT NULL, + `timestamp` int(10) unsigned NOT NULL, + `data` varchar(50) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'Numeric readings\' + '; + + /** + * + */ + protected $fields = array( + 'id' => '', + 'timestamp' => '', + 'data' => '' + ); + + /** + * + */ + protected $nullable = array( + 'id' => false, + 'timestamp' => false, + 'data' => false + ); + + /** + * + */ + protected $primary = array( + 'id' + ); + + /** + * + */ + protected $autoinc = ''; + +} diff --git a/core/ORM/ReadingNum.php b/core/ORM/ReadingNum.php index 6e4eac3..537d9ff 100644 --- a/core/ORM/ReadingNum.php +++ b/core/ORM/ReadingNum.php @@ -16,20 +16,11 @@ /** * */ -class ReadingNum extends ReadingNumBase { +class ReadingNum extends ReadingNumBase +{ /** * */ - public function getLastReading( $id, $timestamp=NULL ) { - $q = new \DBQuery($this->table); - $q->get('data')->filter('id', $id)->order('timestamp', TRUE)->limit(1); - - if (!is_null($timestamp)) { - $q->filter('timestamp', array('le'=>$timestamp)); - } - - return self::$db->queryOne($q); - } } diff --git a/core/ORM/ReadingNumBase.php b/core/ORM/ReadingNumBase.php index 46f61e6..96f611b 100644 --- a/core/ORM/ReadingNumBase.php +++ b/core/ORM/ReadingNumBase.php @@ -150,8 +150,8 @@ public function getData() public function filterByIdTimestamp($id, $timestamp) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`timestamp` = '.$this->quote($timestamp).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp).''; return $this; } // filterByIdTimestamp() @@ -163,7 +163,7 @@ public function filterByIdTimestamp($id, $timestamp) */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -175,7 +175,7 @@ public function filterByTimestamp($timestamp) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -187,7 +187,7 @@ public function filterById($id) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/ReadingNumMemoryBase.php b/core/ORM/ReadingNumMemoryBase.php index 20073e9..d14645f 100644 --- a/core/ORM/ReadingNumMemoryBase.php +++ b/core/ORM/ReadingNumMemoryBase.php @@ -150,8 +150,8 @@ public function getData() public function filterByIdTimestamp($id, $timestamp) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`timestamp` = '.$this->quote($timestamp).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp).''; return $this; } // filterByIdTimestamp() @@ -163,7 +163,7 @@ public function filterByIdTimestamp($id, $timestamp) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -175,7 +175,7 @@ public function filterById($id) */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -187,7 +187,7 @@ public function filterByTimestamp($timestamp) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/ReadingStatisticsBase.php b/core/ORM/ReadingStatisticsBase.php index 0731205..9ffe406 100644 --- a/core/ORM/ReadingStatisticsBase.php +++ b/core/ORM/ReadingStatisticsBase.php @@ -151,7 +151,7 @@ public function getReadings() */ public function filterByGuid($guid) { - $this->filter[] = '`guid` = '.$this->quote($guid); + $this->filter[] = $this->field('guid').' = '.$this->quote($guid); return $this; } // filterByGuid() @@ -163,7 +163,7 @@ public function filterByGuid($guid) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -175,7 +175,7 @@ public function filterByName($name) */ public function filterByDescription($description) { - $this->filter[] = '`description` = '.$this->quote($description); + $this->filter[] = $this->field('description').' = '.$this->quote($description); return $this; } // filterByDescription() @@ -187,7 +187,7 @@ public function filterByDescription($description) */ public function filterBySerial($serial) { - $this->filter[] = '`serial` = '.$this->quote($serial); + $this->filter[] = $this->field('serial').' = '.$this->quote($serial); return $this; } // filterBySerial() @@ -199,7 +199,7 @@ public function filterBySerial($serial) */ public function filterByChannel($channel) { - $this->filter[] = '`channel` = '.$this->quote($channel); + $this->filter[] = $this->field('channel').' = '.$this->quote($channel); return $this; } // filterByChannel() @@ -211,7 +211,7 @@ public function filterByChannel($channel) */ public function filterByUnit($unit) { - $this->filter[] = '`unit` = '.$this->quote($unit); + $this->filter[] = $this->field('unit').' = '.$this->quote($unit); return $this; } // filterByUnit() @@ -223,7 +223,7 @@ public function filterByUnit($unit) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -235,7 +235,7 @@ public function filterByType($type) */ public function filterByIcon($icon) { - $this->filter[] = '`icon` = '.$this->quote($icon); + $this->filter[] = $this->field('icon').' = '.$this->quote($icon); return $this; } // filterByIcon() @@ -247,7 +247,7 @@ public function filterByIcon($icon) */ public function filterByDatetime($datetime) { - $this->filter[] = '`datetime` = '.$this->quote($datetime); + $this->filter[] = $this->field('datetime').' = '.$this->quote($datetime); return $this; } // filterByDatetime() @@ -259,7 +259,7 @@ public function filterByDatetime($datetime) */ public function filterByReadings($readings) { - $this->filter[] = '`readings` = '.$this->quote($readings); + $this->filter[] = $this->field('readings').' = '.$this->quote($readings); return $this; } // filterByReadings() diff --git a/core/ORM/ReadingStr.php b/core/ORM/ReadingStr.php index 05ea1e6..f679cdb 100644 --- a/core/ORM/ReadingStr.php +++ b/core/ORM/ReadingStr.php @@ -16,20 +16,11 @@ /** * */ -class ReadingStr extends ReadingStrBase { +class ReadingStr extends ReadingStrBase +{ /** * */ - public function getLastReading( $id, $timestamp=NULL ) { - $q = new \DBQuery($this->table); - $q->get('data')->filter('id', $id)->order('timestamp', TRUE)->limit(1); - - if (!is_null($timestamp)) { - $q->filter('timestamp', array('le'=>$timestamp)); - } - - return self::$db->queryOne($q); - } } diff --git a/core/ORM/ReadingStrBase.php b/core/ORM/ReadingStrBase.php index acda4f1..19ef1f9 100644 --- a/core/ORM/ReadingStrBase.php +++ b/core/ORM/ReadingStrBase.php @@ -150,8 +150,8 @@ public function getData() public function filterByIdTimestamp($id, $timestamp) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`timestamp` = '.$this->quote($timestamp).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp).''; return $this; } // filterByIdTimestamp() @@ -163,7 +163,7 @@ public function filterByIdTimestamp($id, $timestamp) */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -175,7 +175,7 @@ public function filterByTimestamp($timestamp) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -187,7 +187,7 @@ public function filterById($id) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/ReadingStrMemoryBase.php b/core/ORM/ReadingStrMemoryBase.php index 56d9106..3a970ac 100644 --- a/core/ORM/ReadingStrMemoryBase.php +++ b/core/ORM/ReadingStrMemoryBase.php @@ -150,8 +150,8 @@ public function getData() public function filterByIdTimestamp($id, $timestamp) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`timestamp` = '.$this->quote($timestamp).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp).''; return $this; } // filterByIdTimestamp() @@ -163,7 +163,7 @@ public function filterByIdTimestamp($id, $timestamp) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -175,7 +175,7 @@ public function filterById($id) */ public function filterByTimestamp($timestamp) { - $this->filter[] = '`timestamp` = '.$this->quote($timestamp); + $this->filter[] = $this->field('timestamp').' = '.$this->quote($timestamp); return $this; } // filterByTimestamp() @@ -187,7 +187,7 @@ public function filterByTimestamp($timestamp) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/SettingsBase.php b/core/ORM/SettingsBase.php index 3c023d0..f130c25 100644 --- a/core/ORM/SettingsBase.php +++ b/core/ORM/SettingsBase.php @@ -286,9 +286,9 @@ public function getData() public function filterByScopeNameKey($scope, $name, $key) { - $this->filter[] = '`scope` = '.$this->quote($scope).''; - $this->filter[] = '`name` = '.$this->quote($name).''; - $this->filter[] = '`key` = '.$this->quote($key).''; + $this->filter[] = $this->field('scope').' = '.$this->quote($scope).''; + $this->filter[] = $this->field('name').' = '.$this->quote($name).''; + $this->filter[] = $this->field('key').' = '.$this->quote($key).''; return $this; } // filterByScopeNameKey() @@ -300,7 +300,7 @@ public function filterByScopeNameKey($scope, $name, $key) */ public function filterByScope($scope) { - $this->filter[] = '`scope` = '.$this->quote($scope); + $this->filter[] = $this->field('scope').' = '.$this->quote($scope); return $this; } // filterByScope() @@ -312,7 +312,7 @@ public function filterByScope($scope) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -324,7 +324,7 @@ public function filterByName($name) */ public function filterByKey($key) { - $this->filter[] = '`key` = '.$this->quote($key); + $this->filter[] = $this->field('key').' = '.$this->quote($key); return $this; } // filterByKey() @@ -336,7 +336,7 @@ public function filterByKey($key) */ public function filterByValue($value) { - $this->filter[] = '`value` = '.$this->quote($value); + $this->filter[] = $this->field('value').' = '.$this->quote($value); return $this; } // filterByValue() @@ -348,7 +348,7 @@ public function filterByValue($value) */ public function filterByOrder($order) { - $this->filter[] = '`order` = '.$this->quote($order); + $this->filter[] = $this->field('order').' = '.$this->quote($order); return $this; } // filterByOrder() @@ -360,7 +360,7 @@ public function filterByOrder($order) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -372,7 +372,7 @@ public function filterByType($type) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/core/ORM/SettingsKeysBase.php b/core/ORM/SettingsKeysBase.php index d50049d..01825dd 100644 --- a/core/ORM/SettingsKeysBase.php +++ b/core/ORM/SettingsKeysBase.php @@ -71,7 +71,7 @@ public function getValue() */ public function filterByKey($key) { - $this->filter[] = '`key` = '.$this->quote($key); + $this->filter[] = $this->field('key').' = '.$this->quote($key); return $this; } // filterByKey() @@ -83,7 +83,7 @@ public function filterByKey($key) */ public function filterByValue($value) { - $this->filter[] = '`value` = '.$this->quote($value); + $this->filter[] = $this->field('value').' = '.$this->quote($value); return $this; } // filterByValue() diff --git a/core/ORM/TariffBase.php b/core/ORM/TariffBase.php index 4201c6f..fff6cc4 100644 --- a/core/ORM/TariffBase.php +++ b/core/ORM/TariffBase.php @@ -129,7 +129,7 @@ public function getComment() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -141,7 +141,7 @@ public function filterById($id) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -153,7 +153,7 @@ public function filterByName($name) */ public function filterByComment($comment) { - $this->filter[] = '`comment` = '.$this->quote($comment); + $this->filter[] = $this->field('comment').' = '.$this->quote($comment); return $this; } // filterByComment() diff --git a/core/ORM/TariffDateBase.php b/core/ORM/TariffDateBase.php index c4c6507..ff0ac2b 100644 --- a/core/ORM/TariffDateBase.php +++ b/core/ORM/TariffDateBase.php @@ -150,8 +150,8 @@ public function getCost() public function filterByIdDate($id, $date) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`date` = '.$this->quote($date).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('date').' = '.$this->quote($date).''; return $this; } // filterByIdDate() @@ -163,7 +163,7 @@ public function filterByIdDate($id, $date) */ public function filterByDate($date) { - $this->filter[] = '`date` = '.$this->quote($date); + $this->filter[] = $this->field('date').' = '.$this->quote($date); return $this; } // filterByDate() @@ -175,7 +175,7 @@ public function filterByDate($date) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -187,7 +187,7 @@ public function filterById($id) */ public function filterByCost($cost) { - $this->filter[] = '`cost` = '.$this->quote($cost); + $this->filter[] = $this->field('cost').' = '.$this->quote($cost); return $this; } // filterByCost() diff --git a/core/ORM/TariffTimeBase.php b/core/ORM/TariffTimeBase.php index dae62d6..666b676 100644 --- a/core/ORM/TariffTimeBase.php +++ b/core/ORM/TariffTimeBase.php @@ -252,10 +252,10 @@ public function getComment() public function filterByIdDateTimeDays($id, $date, $time, $days) { - $this->filter[] = '`id` = '.$this->quote($id).''; - $this->filter[] = '`date` = '.$this->quote($date).''; - $this->filter[] = '`time` = '.$this->quote($time).''; - $this->filter[] = '`days` = '.$this->quote($days).''; + $this->filter[] = $this->field('id').' = '.$this->quote($id).''; + $this->filter[] = $this->field('date').' = '.$this->quote($date).''; + $this->filter[] = $this->field('time').' = '.$this->quote($time).''; + $this->filter[] = $this->field('days').' = '.$this->quote($days).''; return $this; } // filterByIdDateTimeDays() @@ -267,7 +267,7 @@ public function filterByIdDateTimeDays($id, $date, $time, $days) */ public function filterByDays($days) { - $this->filter[] = '`days` = '.$this->quote($days); + $this->filter[] = $this->field('days').' = '.$this->quote($days); return $this; } // filterByDays() @@ -279,7 +279,7 @@ public function filterByDays($days) */ public function filterByDate($date) { - $this->filter[] = '`date` = '.$this->quote($date); + $this->filter[] = $this->field('date').' = '.$this->quote($date); return $this; } // filterByDate() @@ -291,7 +291,7 @@ public function filterByDate($date) */ public function filterByTime($time) { - $this->filter[] = '`time` = '.$this->quote($time); + $this->filter[] = $this->field('time').' = '.$this->quote($time); return $this; } // filterByTime() @@ -303,7 +303,7 @@ public function filterByTime($time) */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -315,7 +315,7 @@ public function filterById($id) */ public function filterByTariff($tariff) { - $this->filter[] = '`tariff` = '.$this->quote($tariff); + $this->filter[] = $this->field('tariff').' = '.$this->quote($tariff); return $this; } // filterByTariff() @@ -327,7 +327,7 @@ public function filterByTariff($tariff) */ public function filterByComment($comment) { - $this->filter[] = '`comment` = '.$this->quote($comment); + $this->filter[] = $this->field('comment').' = '.$this->quote($comment); return $this; } // filterByComment() diff --git a/core/ORM/TariffViewBase.php b/core/ORM/TariffViewBase.php index f5e1bb8..6d0802e 100644 --- a/core/ORM/TariffViewBase.php +++ b/core/ORM/TariffViewBase.php @@ -141,7 +141,7 @@ public function getTimeComment() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -153,7 +153,7 @@ public function filterById($id) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -165,7 +165,7 @@ public function filterByName($name) */ public function filterByTariffComment($tariff_comment) { - $this->filter[] = '`tariff_comment` = '.$this->quote($tariff_comment); + $this->filter[] = $this->field('tariff_comment').' = '.$this->quote($tariff_comment); return $this; } // filterByTariffComment() @@ -177,7 +177,7 @@ public function filterByTariffComment($tariff_comment) */ public function filterByDate($date) { - $this->filter[] = '`date` = '.$this->quote($date); + $this->filter[] = $this->field('date').' = '.$this->quote($date); return $this; } // filterByDate() @@ -189,7 +189,7 @@ public function filterByDate($date) */ public function filterByCost($cost) { - $this->filter[] = '`cost` = '.$this->quote($cost); + $this->filter[] = $this->field('cost').' = '.$this->quote($cost); return $this; } // filterByCost() @@ -201,7 +201,7 @@ public function filterByCost($cost) */ public function filterByTime($time) { - $this->filter[] = '`time` = '.$this->quote($time); + $this->filter[] = $this->field('time').' = '.$this->quote($time); return $this; } // filterByTime() @@ -213,7 +213,7 @@ public function filterByTime($time) */ public function filterByDays($days) { - $this->filter[] = '`days` = '.$this->quote($days); + $this->filter[] = $this->field('days').' = '.$this->quote($days); return $this; } // filterByDays() @@ -225,7 +225,7 @@ public function filterByDays($days) */ public function filterByTariff($tariff) { - $this->filter[] = '`tariff` = '.$this->quote($tariff); + $this->filter[] = $this->field('tariff').' = '.$this->quote($tariff); return $this; } // filterByTariff() @@ -237,7 +237,7 @@ public function filterByTariff($tariff) */ public function filterByTimeComment($time_comment) { - $this->filter[] = '`time_comment` = '.$this->quote($time_comment); + $this->filter[] = $this->field('time_comment').' = '.$this->quote($time_comment); return $this; } // filterByTimeComment() diff --git a/core/ORM/Tree.php b/core/ORM/Tree.php index 9244fda..a10511a 100644 --- a/core/ORM/Tree.php +++ b/core/ORM/Tree.php @@ -51,7 +51,7 @@ public function getWithParents( $publicOnly=FALSE ) { $nodes = array(); // Without root node - $this->reset()->filter('id', array('min'=>2)); + $this->reset()->filter('id', array('min' => 2)); if ($publicOnly) $this->filterByPublic(1); $rows = $this->find()->asAssoc(); @@ -68,9 +68,123 @@ public function getWithParents( $publicOnly=FALSE ) { /** * Get full name with description (if defined): Name (Description) */ - public function getFullName() { + public function getFullName($format='%$1s (%$2s') { $name = $this->getName(); - if ($description = $this->getDescription) $name .= ' ('.$description.')'; + if ($desc = $this->getDescription()) { + $name = sprintf($format, $name, $desc); + } return $name; } + + /** + * Translate fields with mapping + */ + protected function field($field) + { + return preg_match('~^[[:alpha:]_]\w*$~', $field) ? self::$fieldMapping[$field] : $field; + } + + /** + * + */ + protected function _sql() + { + return ' + SELECT `n`.`id` AS `id`, + `n`.`entity` AS `entity`, + IFNULL(`n`.`guid`,`c`.`guid`) AS `guid`, + IF(`co`.`id`,`co`.`name`,`c`.`name`) AS `name`, + IF(`co`.`id`,`co`.`serial`,`c`.`serial`) AS `serial`, + `c`.`channel` AS `channel`, + IF(`co`.`id`,`co`.`description`,`c`.`description`) AS `description`, + IF(`co`.`id`,`co`.`resolution`,`c`.`resolution`) AS `resolution`, + IF(`co`.`id`,`co`.`cost`,`c`.`cost`) AS `cost`, + IF(`co`.`id`,`co`.`meter`,`c`.`meter`) AS `meter`, + IF(`co`.`id`,`co`.`numeric`,`c`.`numeric`) AS `numeric`, + IF(`co`.`id`,`co`.`offset`,`c`.`offset`) AS `offset`, + IF(`co`.`id`,`co`.`adjust`,`c`.`adjust`) AS `adjust`, + IF(`co`.`id`,`co`.`unit`,`c`.`unit`) AS `unit`, + IF(`co`.`id`,`co`.`decimals`,`c`.`decimals`) AS `decimals`, + IF(`co`.`id`,`co`.`threshold`,`c`.`threshold`) AS `threshold`, + IF(`co`.`id`,`co`.`valid_from`,`c`.`valid_from`) AS `valid_from`, + IF(`co`.`id`,`co`.`valid_to`,`c`.`valid_to`) AS `valid_to`, + IF(`co`.`id`,`co`.`public`,`c`.`public`) AS `public`, + IF(`co`.`id`,`co`.`tags`,`c`.`tags`) AS `tags`, + IF(`co`.`id`,`co`.`extra`,`c`.`extra`) AS `extra`, + IF(`co`.`id`,`co`.`comment`,`c`.`comment`) AS `comment`, + `t`.`id` AS `type_id`, + `t`.`name` AS `type`, + `t`.`model` AS `model`, + `t`.`childs` AS `childs`, + `t`.`read` AS `read`, + `t`.`write` AS `write`, + `t`.`graph` AS `graph`, + IF(`co`.`id`,`co`.`icon`,`c`.`icon`) AS `icon`, + `ca`.`id` AS `alias`, + `ta`.`id` AS `alias_of`, + `ta`.`entity` AS `entity_of`, + COUNT(1) + (`n`.`lft` > 1) AS `level`, + ROUND((`n`.`rgt` - `n`.`lft` - 1) / 2, 0) AS `haschilds`, + ((MIN(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1)) / 2) > 0 AS `lower`, + (`n`.`lft` - MAX(`p`.`lft`)) > 1 AS `upper` + FROM `pvlng_tree` `n` + JOIN `pvlng_tree` `p` ON `n`.`lft` BETWEEN `p`.`lft` AND `p`.`rgt` AND (`p`.`id` <> `n`.`id` OR `n`.`lft` = 1) + LEFT JOIN `pvlng_channel` `c` on `n`.`entity` = `c`.`id` + LEFT JOIN `pvlng_type` `t` on `c`.`type` = `t`.`id` + LEFT JOIN `pvlng_channel` `ca` on IF(`t`.`childs`,`n`.`guid`,`c`.`guid`) = `ca`.`channel` AND `ca`.`type` = 0 + LEFT JOIN `pvlng_tree` `ta` on `c`.`channel` = `ta`.`guid` + LEFT JOIN `pvlng_channel` `co` on `ta`.`entity` = `co`.`id` AND `c`.`type` = 0 + ' . $this->_filter() . ' + GROUP BY `n`.`id` -- Fixed grouping + ORDER BY `n`.`lft` -- Fixed order + '; + } + + // ----------------------------------------------------------------------- + // PRIVATE + // ----------------------------------------------------------------------- + + /** + * + */ + private static $fieldMapping = array( + 'id' => '`n`.`id`', + 'entity' => '`n`.`entity`', + 'guid' => 'IFNULL(`n`.`guid`,`c`.`guid`)', + 'name' => 'IF(`co`.`id`,`co`.`name`,`c`.`name`)', + 'serial' => 'IF(`co`.`id`,`co`.`serial`,`c`.`serial`)', + 'channel' => '`c`.`channel`', + 'description' => 'IF(`co`.`id`,`co`.`description`,`c`.`description`)', + 'resolution' => 'IF(`co`.`id`,`co`.`resolution`,`c`.`resolution`)', + 'cost' => 'IF(`co`.`id`,`co`.`cost`,`c`.`cost`)', + 'meter' => 'IF(`co`.`id`,`co`.`meter`,`c`.`meter`)', + 'numeric' => 'IF(`co`.`id`,`co`.`numeric`,`c`.`numeric`)', + 'offset' => 'IF(`co`.`id`,`co`.`offset`,`c`.`offset`)', + 'adjust' => 'IF(`co`.`id`,`co`.`adjust`,`c`.`adjust`)', + 'unit' => 'IF(`co`.`id`,`co`.`unit`,`c`.`unit`)', + 'decimals' => 'IF(`co`.`id`,`co`.`decimals`,`c`.`decimals`)', + 'threshold' => 'IF(`co`.`id`,`co`.`threshold`,`c`.`threshold`)', + 'valid_from' => 'IF(`co`.`id`,`co`.`valid_from`,`c`.`valid_from`)', + 'valid_to' => 'IF(`co`.`id`,`co`.`valid_to`,`c`.`valid_to`)', + 'public' => 'IF(`co`.`id`,`co`.`public`,`c`.`public`)', + 'tags' => 'IF(`co`.`id`,`co`.`tags`,`c`.`tags`)', + 'extra' => 'IF(`co`.`id`,`co`.`extra`,`c`.`extra`)', + 'comment' => 'IF(`co`.`id`,`co`.`comment`,`c`.`comment`)', + 'type_id' => '`t`.`id`', + 'type' => '`t`.`name`', + 'model' => '`t`.`model`', + 'childs' => '`t`.`childs`', + 'read' => '`t`.`read`', + 'write' => '`t`.`write`', + 'graph' => '`t`.`graph`', + 'icon' => 'IF(`co`.`id`,`co`.`icon`,`c`.`icon`)', + 'alias' => '`ca`.`id`', + 'alias_of' => '`ta`.`id`', + 'entity_of' => '`ta`.`entity`', + 'level' => 'COUNT(1) + (`n`.`lft` > 1)', + 'haschilds' => 'ROUND((`n`.`rgt` - `n`.`lft` - 1) / 2, 0)', + 'lower' => '((MIN(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1)) / 2) > 0', + 'upper' => '(`n`.`lft` - MAX(`p`.`lft`)) > 1' + ); + } diff --git a/core/ORM/TreeBase.php b/core/ORM/TreeBase.php index fc489e2..2641b4c 100644 --- a/core/ORM/TreeBase.php +++ b/core/ORM/TreeBase.php @@ -421,7 +421,7 @@ public function getUpper() */ public function filterById($id) { - $this->filter[] = '`id` = '.$this->quote($id); + $this->filter[] = $this->field('id').' = '.$this->quote($id); return $this; } // filterById() @@ -433,7 +433,7 @@ public function filterById($id) */ public function filterByEntity($entity) { - $this->filter[] = '`entity` = '.$this->quote($entity); + $this->filter[] = $this->field('entity').' = '.$this->quote($entity); return $this; } // filterByEntity() @@ -445,7 +445,7 @@ public function filterByEntity($entity) */ public function filterByGuid($guid) { - $this->filter[] = '`guid` = '.$this->quote($guid); + $this->filter[] = $this->field('guid').' = '.$this->quote($guid); return $this; } // filterByGuid() @@ -457,7 +457,7 @@ public function filterByGuid($guid) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -469,7 +469,7 @@ public function filterByName($name) */ public function filterBySerial($serial) { - $this->filter[] = '`serial` = '.$this->quote($serial); + $this->filter[] = $this->field('serial').' = '.$this->quote($serial); return $this; } // filterBySerial() @@ -481,7 +481,7 @@ public function filterBySerial($serial) */ public function filterByChannel($channel) { - $this->filter[] = '`channel` = '.$this->quote($channel); + $this->filter[] = $this->field('channel').' = '.$this->quote($channel); return $this; } // filterByChannel() @@ -493,7 +493,7 @@ public function filterByChannel($channel) */ public function filterByDescription($description) { - $this->filter[] = '`description` = '.$this->quote($description); + $this->filter[] = $this->field('description').' = '.$this->quote($description); return $this; } // filterByDescription() @@ -505,7 +505,7 @@ public function filterByDescription($description) */ public function filterByResolution($resolution) { - $this->filter[] = '`resolution` = '.$this->quote($resolution); + $this->filter[] = $this->field('resolution').' = '.$this->quote($resolution); return $this; } // filterByResolution() @@ -517,7 +517,7 @@ public function filterByResolution($resolution) */ public function filterByCost($cost) { - $this->filter[] = '`cost` = '.$this->quote($cost); + $this->filter[] = $this->field('cost').' = '.$this->quote($cost); return $this; } // filterByCost() @@ -529,7 +529,7 @@ public function filterByCost($cost) */ public function filterByMeter($meter) { - $this->filter[] = '`meter` = '.$this->quote($meter); + $this->filter[] = $this->field('meter').' = '.$this->quote($meter); return $this; } // filterByMeter() @@ -541,7 +541,7 @@ public function filterByMeter($meter) */ public function filterByNumeric($numeric) { - $this->filter[] = '`numeric` = '.$this->quote($numeric); + $this->filter[] = $this->field('numeric').' = '.$this->quote($numeric); return $this; } // filterByNumeric() @@ -553,7 +553,7 @@ public function filterByNumeric($numeric) */ public function filterByOffset($offset) { - $this->filter[] = '`offset` = '.$this->quote($offset); + $this->filter[] = $this->field('offset').' = '.$this->quote($offset); return $this; } // filterByOffset() @@ -565,7 +565,7 @@ public function filterByOffset($offset) */ public function filterByAdjust($adjust) { - $this->filter[] = '`adjust` = '.$this->quote($adjust); + $this->filter[] = $this->field('adjust').' = '.$this->quote($adjust); return $this; } // filterByAdjust() @@ -577,7 +577,7 @@ public function filterByAdjust($adjust) */ public function filterByUnit($unit) { - $this->filter[] = '`unit` = '.$this->quote($unit); + $this->filter[] = $this->field('unit').' = '.$this->quote($unit); return $this; } // filterByUnit() @@ -589,7 +589,7 @@ public function filterByUnit($unit) */ public function filterByDecimals($decimals) { - $this->filter[] = '`decimals` = '.$this->quote($decimals); + $this->filter[] = $this->field('decimals').' = '.$this->quote($decimals); return $this; } // filterByDecimals() @@ -601,7 +601,7 @@ public function filterByDecimals($decimals) */ public function filterByThreshold($threshold) { - $this->filter[] = '`threshold` = '.$this->quote($threshold); + $this->filter[] = $this->field('threshold').' = '.$this->quote($threshold); return $this; } // filterByThreshold() @@ -613,7 +613,7 @@ public function filterByThreshold($threshold) */ public function filterByValidFrom($valid_from) { - $this->filter[] = '`valid_from` = '.$this->quote($valid_from); + $this->filter[] = $this->field('valid_from').' = '.$this->quote($valid_from); return $this; } // filterByValidFrom() @@ -625,7 +625,7 @@ public function filterByValidFrom($valid_from) */ public function filterByValidTo($valid_to) { - $this->filter[] = '`valid_to` = '.$this->quote($valid_to); + $this->filter[] = $this->field('valid_to').' = '.$this->quote($valid_to); return $this; } // filterByValidTo() @@ -637,7 +637,7 @@ public function filterByValidTo($valid_to) */ public function filterByPublic($public) { - $this->filter[] = '`public` = '.$this->quote($public); + $this->filter[] = $this->field('public').' = '.$this->quote($public); return $this; } // filterByPublic() @@ -649,7 +649,7 @@ public function filterByPublic($public) */ public function filterByTags($tags) { - $this->filter[] = '`tags` = '.$this->quote($tags); + $this->filter[] = $this->field('tags').' = '.$this->quote($tags); return $this; } // filterByTags() @@ -661,7 +661,7 @@ public function filterByTags($tags) */ public function filterByExtra($extra) { - $this->filter[] = '`extra` = '.$this->quote($extra); + $this->filter[] = $this->field('extra').' = '.$this->quote($extra); return $this; } // filterByExtra() @@ -673,7 +673,7 @@ public function filterByExtra($extra) */ public function filterByComment($comment) { - $this->filter[] = '`comment` = '.$this->quote($comment); + $this->filter[] = $this->field('comment').' = '.$this->quote($comment); return $this; } // filterByComment() @@ -685,7 +685,7 @@ public function filterByComment($comment) */ public function filterByTypeId($type_id) { - $this->filter[] = '`type_id` = '.$this->quote($type_id); + $this->filter[] = $this->field('type_id').' = '.$this->quote($type_id); return $this; } // filterByTypeId() @@ -697,7 +697,7 @@ public function filterByTypeId($type_id) */ public function filterByType($type) { - $this->filter[] = '`type` = '.$this->quote($type); + $this->filter[] = $this->field('type').' = '.$this->quote($type); return $this; } // filterByType() @@ -709,7 +709,7 @@ public function filterByType($type) */ public function filterByModel($model) { - $this->filter[] = '`model` = '.$this->quote($model); + $this->filter[] = $this->field('model').' = '.$this->quote($model); return $this; } // filterByModel() @@ -721,7 +721,7 @@ public function filterByModel($model) */ public function filterByChilds($childs) { - $this->filter[] = '`childs` = '.$this->quote($childs); + $this->filter[] = $this->field('childs').' = '.$this->quote($childs); return $this; } // filterByChilds() @@ -733,7 +733,7 @@ public function filterByChilds($childs) */ public function filterByRead($read) { - $this->filter[] = '`read` = '.$this->quote($read); + $this->filter[] = $this->field('read').' = '.$this->quote($read); return $this; } // filterByRead() @@ -745,7 +745,7 @@ public function filterByRead($read) */ public function filterByWrite($write) { - $this->filter[] = '`write` = '.$this->quote($write); + $this->filter[] = $this->field('write').' = '.$this->quote($write); return $this; } // filterByWrite() @@ -757,7 +757,7 @@ public function filterByWrite($write) */ public function filterByGraph($graph) { - $this->filter[] = '`graph` = '.$this->quote($graph); + $this->filter[] = $this->field('graph').' = '.$this->quote($graph); return $this; } // filterByGraph() @@ -769,7 +769,7 @@ public function filterByGraph($graph) */ public function filterByIcon($icon) { - $this->filter[] = '`icon` = '.$this->quote($icon); + $this->filter[] = $this->field('icon').' = '.$this->quote($icon); return $this; } // filterByIcon() @@ -781,7 +781,7 @@ public function filterByIcon($icon) */ public function filterByAlias($alias) { - $this->filter[] = '`alias` = '.$this->quote($alias); + $this->filter[] = $this->field('alias').' = '.$this->quote($alias); return $this; } // filterByAlias() @@ -793,7 +793,7 @@ public function filterByAlias($alias) */ public function filterByAliasOf($alias_of) { - $this->filter[] = '`alias_of` = '.$this->quote($alias_of); + $this->filter[] = $this->field('alias_of').' = '.$this->quote($alias_of); return $this; } // filterByAliasOf() @@ -805,7 +805,7 @@ public function filterByAliasOf($alias_of) */ public function filterByEntityOf($entity_of) { - $this->filter[] = '`entity_of` = '.$this->quote($entity_of); + $this->filter[] = $this->field('entity_of').' = '.$this->quote($entity_of); return $this; } // filterByEntityOf() @@ -817,7 +817,7 @@ public function filterByEntityOf($entity_of) */ public function filterByLevel($level) { - $this->filter[] = '`level` = '.$this->quote($level); + $this->filter[] = $this->field('level').' = '.$this->quote($level); return $this; } // filterByLevel() @@ -829,7 +829,7 @@ public function filterByLevel($level) */ public function filterByHaschilds($haschilds) { - $this->filter[] = '`haschilds` = '.$this->quote($haschilds); + $this->filter[] = $this->field('haschilds').' = '.$this->quote($haschilds); return $this; } // filterByHaschilds() @@ -841,7 +841,7 @@ public function filterByHaschilds($haschilds) */ public function filterByLower($lower) { - $this->filter[] = '`lower` = '.$this->quote($lower); + $this->filter[] = $this->field('lower').' = '.$this->quote($lower); return $this; } // filterByLower() @@ -853,7 +853,7 @@ public function filterByLower($lower) */ public function filterByUpper($upper) { - $this->filter[] = '`upper` = '.$this->quote($upper); + $this->filter[] = $this->field('upper').' = '.$this->quote($upper); return $this; } // filterByUpper() @@ -874,7 +874,7 @@ public function filterByUpper($upper) * @var string $createSQL */ protected $createSQL = ' - CREATE ALGORITHM=UNDEFINED DEFINER=`pvlng`@`localhost` SQL SECURITY DEFINER VIEW `pvlng_tree_view` AS select `n`.`id` AS `id`,`n`.`entity` AS `entity`,ifnull(`n`.`guid`,`c`.`guid`) AS `guid`,if(`co`.`id`,`co`.`name`,`c`.`name`) AS `name`,if(`co`.`id`,`co`.`serial`,`c`.`serial`) AS `serial`,`c`.`channel` AS `channel`,if(`co`.`id`,`co`.`description`,`c`.`description`) AS `description`,if(`co`.`id`,`co`.`resolution`,`c`.`resolution`) AS `resolution`,if(`co`.`id`,`co`.`cost`,`c`.`cost`) AS `cost`,if(`co`.`id`,`co`.`meter`,`c`.`meter`) AS `meter`,if(`co`.`id`,`co`.`numeric`,`c`.`numeric`) AS `numeric`,if(`co`.`id`,`co`.`offset`,`c`.`offset`) AS `offset`,if(`co`.`id`,`co`.`adjust`,`c`.`adjust`) AS `adjust`,if(`co`.`id`,`co`.`unit`,`c`.`unit`) AS `unit`,if(`co`.`id`,`co`.`decimals`,`c`.`decimals`) AS `decimals`,if(`co`.`id`,`co`.`threshold`,`c`.`threshold`) AS `threshold`,if(`co`.`id`,`co`.`valid_from`,`c`.`valid_from`) AS `valid_from`,if(`co`.`id`,`co`.`valid_to`,`c`.`valid_to`) AS `valid_to`,if(`co`.`id`,`co`.`public`,`c`.`public`) AS `public`,if(`co`.`id`,`co`.`tags`,`c`.`tags`) AS `tags`,if(`co`.`id`,`co`.`extra`,`c`.`extra`) AS `extra`,if(`co`.`id`,`co`.`comment`,`c`.`comment`) AS `comment`,`t`.`id` AS `type_id`,`t`.`name` AS `type`,`t`.`model` AS `model`,`t`.`childs` AS `childs`,`t`.`read` AS `read`,`t`.`write` AS `write`,`t`.`graph` AS `graph`,if(`co`.`id`,`co`.`icon`,`c`.`icon`) AS `icon`,`ca`.`id` AS `alias`,`ta`.`id` AS `alias_of`,`ta`.`entity` AS `entity_of`,(((count(0) - 1) + (`n`.`lft` > 1)) + 1) AS `level`,round((((`n`.`rgt` - `n`.`lft`) - 1) / 2),0) AS `haschilds`,((((min(`p`.`rgt`) - `n`.`rgt`) - (`n`.`lft` > 1)) / 2) > 0) AS `lower`,((`n`.`lft` - max(`p`.`lft`)) > 1) AS `upper` from ((((((`pvlng_tree` `n` join `pvlng_tree` `p`) join `pvlng_channel` `c` on((`n`.`entity` = `c`.`id`))) join `pvlng_type` `t` on((`c`.`type` = `t`.`id`))) left join `pvlng_channel` `ca` on(((if(`t`.`childs`,`n`.`guid`,`c`.`guid`) = `ca`.`channel`) and (`ca`.`type` = 0)))) left join `pvlng_tree` `ta` on((`c`.`channel` = `ta`.`guid`))) left join `pvlng_channel` `co` on(((`ta`.`entity` = `co`.`id`) and (`c`.`type` = 0)))) where ((`n`.`lft` between `p`.`lft` and `p`.`rgt`) and ((`p`.`id` <> `n`.`id`) or (`n`.`lft` = 1))) group by `n`.`id` order by `n`.`lft` + CREATE ALGORITHM=UNDEFINED DEFINER=`pvlng`@`localhost` SQL SECURITY DEFINER VIEW `pvlng_tree_view` AS select `n`.`id` AS `id`,`n`.`entity` AS `entity`,ifnull(`n`.`guid`,`c`.`guid`) AS `guid`,if(`co`.`id`,`co`.`name`,`c`.`name`) AS `name`,if(`co`.`id`,`co`.`serial`,`c`.`serial`) AS `serial`,`c`.`channel` AS `channel`,if(`co`.`id`,`co`.`description`,`c`.`description`) AS `description`,if(`co`.`id`,`co`.`resolution`,`c`.`resolution`) AS `resolution`,if(`co`.`id`,`co`.`cost`,`c`.`cost`) AS `cost`,if(`co`.`id`,`co`.`meter`,`c`.`meter`) AS `meter`,if(`co`.`id`,`co`.`numeric`,`c`.`numeric`) AS `numeric`,if(`co`.`id`,`co`.`offset`,`c`.`offset`) AS `offset`,if(`co`.`id`,`co`.`adjust`,`c`.`adjust`) AS `adjust`,if(`co`.`id`,`co`.`unit`,`c`.`unit`) AS `unit`,if(`co`.`id`,`co`.`decimals`,`c`.`decimals`) AS `decimals`,if(`co`.`id`,`co`.`threshold`,`c`.`threshold`) AS `threshold`,if(`co`.`id`,`co`.`valid_from`,`c`.`valid_from`) AS `valid_from`,if(`co`.`id`,`co`.`valid_to`,`c`.`valid_to`) AS `valid_to`,if(`co`.`id`,`co`.`public`,`c`.`public`) AS `public`,if(`co`.`id`,`co`.`tags`,`c`.`tags`) AS `tags`,if(`co`.`id`,`co`.`extra`,`c`.`extra`) AS `extra`,if(`co`.`id`,`co`.`comment`,`c`.`comment`) AS `comment`,`t`.`id` AS `type_id`,`t`.`name` AS `type`,`t`.`model` AS `model`,`t`.`childs` AS `childs`,`t`.`read` AS `read`,`t`.`write` AS `write`,`t`.`graph` AS `graph`,if(`co`.`id`,`co`.`icon`,`c`.`icon`) AS `icon`,`ca`.`id` AS `alias`,`ta`.`id` AS `alias_of`,`ta`.`entity` AS `entity_of`,(((count(1) - 1) + (`n`.`lft` > 1)) + 1) AS `level`,round((((`n`.`rgt` - `n`.`lft`) - 1) / 2),0) AS `haschilds`,((((min(`p`.`rgt`) - `n`.`rgt`) - (`n`.`lft` > 1)) / 2) > 0) AS `lower`,((`n`.`lft` - max(`p`.`lft`)) > 1) AS `upper` from ((((((`pvlng_tree` `n` left join `pvlng_channel` `c` on((`n`.`entity` = `c`.`id`))) left join `pvlng_type` `t` on((`c`.`type` = `t`.`id`))) left join `pvlng_channel` `ca` on(((if(`t`.`childs`,`n`.`guid`,`c`.`guid`) = `ca`.`channel`) and (`ca`.`type` = 0)))) left join `pvlng_tree` `ta` on((`c`.`channel` = `ta`.`guid`))) left join `pvlng_channel` `co` on(((`ta`.`entity` = `co`.`id`) and (`c`.`type` = 0)))) join `pvlng_tree` `p`) where (((`n`.`lft` between `p`.`lft` and `p`.`rgt`) and (`p`.`id` <> `n`.`id`)) or (`n`.`lft` = 1)) group by `n`.`id` order by `n`.`lft` '; /** diff --git a/core/ORM/ViewBase.php b/core/ORM/ViewBase.php index ae74936..2c26d38 100644 --- a/core/ORM/ViewBase.php +++ b/core/ORM/ViewBase.php @@ -184,8 +184,8 @@ public function getSlug() public function filterByNamePublic($name, $public) { - $this->filter[] = '`name` = '.$this->quote($name).''; - $this->filter[] = '`public` = '.$this->quote($public).''; + $this->filter[] = $this->field('name').' = '.$this->quote($name).''; + $this->filter[] = $this->field('public').' = '.$this->quote($public).''; return $this; } // filterByNamePublic() @@ -197,7 +197,7 @@ public function filterByNamePublic($name, $public) */ public function filterBySlug($slug) { - $this->filter[] = '`slug` = '.$this->quote($slug); + $this->filter[] = $this->field('slug').' = '.$this->quote($slug); return $this; } // filterBySlug() @@ -209,7 +209,7 @@ public function filterBySlug($slug) */ public function filterByPublic($public) { - $this->filter[] = '`public` = '.$this->quote($public); + $this->filter[] = $this->field('public').' = '.$this->quote($public); return $this; } // filterByPublic() @@ -221,7 +221,7 @@ public function filterByPublic($public) */ public function filterByName($name) { - $this->filter[] = '`name` = '.$this->quote($name); + $this->filter[] = $this->field('name').' = '.$this->quote($name); return $this; } // filterByName() @@ -233,7 +233,7 @@ public function filterByName($name) */ public function filterByData($data) { - $this->filter[] = '`data` = '.$this->quote($data); + $this->filter[] = $this->field('data').' = '.$this->quote($data); return $this; } // filterByData() diff --git a/frontend/View/Index/content.private.inc.tpl b/frontend/View/Index/content.private.inc.tpl index 6fd1a30..a82b993 100644 --- a/frontend/View/Index/content.private.inc.tpl +++ b/frontend/View/Index/content.private.inc.tpl @@ -92,7 +92,7 @@
- - - - - - - + + + + + + +