From 888fc0aa1a3a5cb71e7b6750bf4854d2e57cae03 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 8 Jun 2010 19:01:45 +0200 Subject: [PATCH] fixed getBy*() --- backend/lib/controller/datacontroller.php | 6 ++---- backend/lib/model/channel.php | 4 ++-- backend/lib/model/group.php | 4 ++-- backend/lib/model/user.php | 8 ++++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/backend/lib/controller/datacontroller.php b/backend/lib/controller/datacontroller.php index 345f955..2f82bb1 100644 --- a/backend/lib/controller/datacontroller.php +++ b/backend/lib/controller/datacontroller.php @@ -25,9 +25,7 @@ class DataController extends Controller { $channel = Channel::getByUcid($ucid); - // TODO add channel if it doesn't exist (use $this->add) - - $channel->addData($this->view->request->get); + $channel->addData($this->view->request->get); // array(timestamp, value, count) } public function get() { @@ -39,7 +37,7 @@ class DataController extends Controller { $groupBy = (isset($this->view->request->get['groupby'])) ? $this->view->request->get['groupby'] : 400; // get all readings by default $data['from'] = $from; // TODO use min max timestamps from Channel::getData() - $data['to'] = $to; + $data['to'] = $to; // TODO nescessary? $jsonChannels = array(); foreach ($channels as $channel) { diff --git a/backend/lib/model/channel.php b/backend/lib/model/channel.php index bec3ecc..28aa652 100644 --- a/backend/lib/model/channel.php +++ b/backend/lib/model/channel.php @@ -137,9 +137,9 @@ abstract class Channel extends DatabaseObject implements ChannelInterface { * simple self::getByFilter() wrapper */ static public function getByUcid($ucid) { - $channel = self::getByFilter(array('ucid' => $ucid)); + $channel = current(self::getByFilter(array('ucid' => $ucid))); - if (current($channel) === false) { + if ($channel === false) { throw new InvalidArgumentException('No such channel!'); } diff --git a/backend/lib/model/group.php b/backend/lib/model/group.php index be5efcb..56b2fed 100644 --- a/backend/lib/model/group.php +++ b/backend/lib/model/group.php @@ -38,9 +38,9 @@ class Group extends DatabaseObject { } public static function getByUgid($ugid) { - $group = self::getByFilter(array('ugid' => $ugid)); + $group = current(self::getByFilter(array('ugid' => $ugid))); - if (current($group) === false) { + if ($group === false) { throw new InvalidArgumentException('No such group!'); } diff --git a/backend/lib/model/user.php b/backend/lib/model/user.php index 95ef60a..9f3de77 100644 --- a/backend/lib/model/user.php +++ b/backend/lib/model/user.php @@ -29,9 +29,9 @@ class User extends DatabaseObject { * simple self::getByFilter() wrapper */ public static function getByUuid($uuid) { - $user = self::getByFilter(array('uuid' => $uuid)); + $user = current(self::getByFilter(array('uuid' => $uuid))); - if (current($user) === false) { + if ($user === false) { throw new InvalidArgumentException('No such user!'); } @@ -39,9 +39,9 @@ class User extends DatabaseObject { } public static function getByEMail($email) { - $user = self::getByFilter(array('email' => $email)); + $user = current(self::getByFilter(array('email' => $email))); - if (current($user) === false) { + if ($user === false) { throw new InvalidArgumentException('No such user!'); }