diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 13:20:24 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 13:20:24 +0100 |
commit | 196177a0ca3fc0103d359eec44f46173be685413 (patch) | |
tree | f721b656d64e240050980420202873e94f6e9edc /db | |
parent | 7a579b42fa731b65db26bd0c026bc68f2339c451 (diff) |
removed mapper parent class and use the new mapper methods from the framework
Diffstat (limited to 'db')
-rw-r--r-- | db/feedmapper.php | 6 | ||||
-rw-r--r-- | db/foldermapper.php | 5 | ||||
-rw-r--r-- | db/imapper.php | 29 | ||||
-rw-r--r-- | db/itemmapper.php | 20 | ||||
-rw-r--r-- | db/newsmapper.php | 57 |
5 files changed, 53 insertions, 64 deletions
diff --git a/db/feedmapper.php b/db/feedmapper.php index cf434257c..0fc8d3114 100644 --- a/db/feedmapper.php +++ b/db/feedmapper.php @@ -26,9 +26,9 @@ namespace OCA\News\Db; use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Db\Mapper; - -class FeedMapper extends NewsMapper { +class FeedMapper extends Mapper implements IMapper { public function __construct(API $api) { @@ -41,7 +41,7 @@ class FeedMapper extends NewsMapper { 'WHERE `id` = ? ' . 'AND `user_id` = ?'; - $row = $this->findRow($sql, $id, $userId); + $row = $this->findQuery($sql, array($id, $userId)); $feed = new Feed(); $feed->fromRow($row); diff --git a/db/foldermapper.php b/db/foldermapper.php index 041b3ada4..ef2f31f2d 100644 --- a/db/foldermapper.php +++ b/db/foldermapper.php @@ -26,9 +26,10 @@ namespace OCA\News\Db; use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Db\Mapper; -class FolderMapper extends NewsMapper { +class FolderMapper extends Mapper implements IMapper { public function __construct(API $api) { parent::__construct($api, 'news_folders'); @@ -39,7 +40,7 @@ class FolderMapper extends NewsMapper { 'WHERE `id` = ? ' . 'AND `user_id` = ?'; - $row = $this->findRow($sql, $id, $userId); + $row = $this->findQuery($sql, array($id, $userId)); $folder = new Folder(); $folder->fromRow($row); diff --git a/db/imapper.php b/db/imapper.php new file mode 100644 index 000000000..056a4b479 --- /dev/null +++ b/db/imapper.php @@ -0,0 +1,29 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\Db; + +interface IMapper { + public function find($id, $userId); +}
\ No newline at end of file diff --git a/db/itemmapper.php b/db/itemmapper.php index 04f073c36..2efa9b535 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -29,12 +29,28 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\AppFramework\Db\Mapper; use \OCA\AppFramework\Core\API; -class ItemMapper extends NewsMapper { +class ItemMapper extends Mapper implements IMapper { public function __construct(API $api){ parent::__construct($api, 'news_items'); } + + public function findByUrlHash($urlHash, $userId){ + $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . + 'JOIN `*dbprefix*news_feeds` ' . + 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . + 'WHERE `*dbprefix*news_items`.`url_hash` = ? ' . + 'AND `*dbprefix*news_feeds`.`user_id` = ? '; + $params = array($urlHash, $userId); + + $row = $this->findQuery($sql, $params); + $item = new Item(); + $item->fromRow($row); + + return $item; + } + protected function findAllRows($sql, $params, $limit=null, $offset=null) { $result = $this->execute($sql, $params, $limit, $offset); $items = array(); @@ -130,7 +146,7 @@ class ItemMapper extends NewsMapper { 'WHERE `*dbprefix*news_items`.`id` = ? ' . 'AND `*dbprefix*news_feeds`.`user_id` = ? '; - $row = $this->findRow($sql, $id, $userId); + $row = $this->findQuery($sql, array($id, $userId)); $item = new Item(); $item->fromRow($row); diff --git a/db/newsmapper.php b/db/newsmapper.php deleted file mode 100644 index bc2cf5679..000000000 --- a/db/newsmapper.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -/** - * ownCloud - App Framework - * - * @author Bernhard Posselt - * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -namespace OCA\News\Db; - -use \OCA\AppFramework\Db\DoesNotExistException; -use \OCA\AppFramework\Db\MultipleObjectsReturnedException; -use \OCA\AppFramework\Db\Mapper; -use \OCA\AppFramework\Core\API; - - -abstract class NewsMapper extends Mapper { - - - public function __construct(API $api, $tableName) { - parent::__construct($api, $tableName); - } - - - protected function findRow($sql, $id, $userId){ - - $result = $this->execute($sql, array($id, $userId)); - - $row = $result->fetchRow(); - - if($row === false){ - throw new DoesNotExistException('Item does not exist!'); - } elseif($result->fetchRow() !== false) { - throw new MultipleObjectsReturnedException('More than one result for Item with id ' . $id . '!'); - } else { - return $row; - } - } - - -}
\ No newline at end of file |