diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-19 20:32:44 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-19 20:32:44 +0100 |
commit | 50e00916ce1d4536acc2268161135a588fb0c12f (patch) | |
tree | 4948a618098435004c9a916a045adf010cd51565 /db | |
parent | 966af078df176fc96d1e37696d4725115ad9639f (diff) |
added namespaced indices for the newsapp
Diffstat (limited to 'db')
-rw-r--r-- | db/entity.php | 48 | ||||
-rw-r--r-- | db/item.php | 116 |
2 files changed, 107 insertions, 57 deletions
diff --git a/db/entity.php b/db/entity.php index 9adab3b7f..58c42cca7 100644 --- a/db/entity.php +++ b/db/entity.php @@ -27,10 +27,56 @@ namespace OCA\News\Db; abstract class Entity { - public function fromRow($row){ + public $id; + + private $updatedFields; + + + public function __construct(){ + $this->updatedFields = array(); + } + + + /** + * Each time a setter is called, push the part after set + * into an array: for instance setId will save Id in the + * updated fields array so it can be easily used to create the + * getter method + */ + public function __call($methodName, $args){ + if(startsWith($methodName, 'set')){ + $setterPart = substr($methodName, 2); + array_push($this->updatedFields, $setterPart); + } + } + + + /** + * @return array array of updated fields for update query + */ + public function getUpdatedFields(){ + return $this->updatedFields; + } + + + /** + * Maps the keys of the row array to the attributes + * @param array $row the row to map onto the entity + */ + public function fromRow(array $row){ foreach($row as $key => $value){ $this->$key = $value; } } + + public function setId($id){ + $this->id = $id; + } + + + public function getId(){ + return $this->id; + } + }
\ No newline at end of file diff --git a/db/item.php b/db/item.php index 7d07b337b..ee25ab122 100644 --- a/db/item.php +++ b/db/item.php @@ -12,16 +12,69 @@ namespace OCA\News\Db; + class Item extends Entity { + public $url; + public $feed_id; + public $guid; + public $status; + public $title; + public $feedTitle; + + + public function setUrl($url) { + $this->url = $url; + } + + public function getUrl() { + return $this->url; + } + + public function setFeedId($feed_id) { + $this->feed_id = $feed_id; + } + + public function getFeedId() { + return $this->feed_id; + } + + public function setGUID($guid) { + $this->guid = $guid; + } + + public function getGUID() { + return $this->guid; + } + + public function setStatus($status) { + $this->status = $status; + } + + public function getStatus() { + return $this->status; + } + + public function getTitle() { + return $this->title; + } + + public function setTitle($title) { + $this->title = $title; + } + + public function getFeedTitle() { + return $this->feedTitle; + } + + public function setFeedTitle($feedtitle) { + $this->feedTitle = $feedtitle; + } + } -/** - * This class models an item. - * - * It encapsulate a SimplePie_Item object and adds a status flag to it - */ + /*class Item { @@ -50,29 +103,9 @@ class Item extends Entity { } } - public function getFeedId() { - return $this->feedId; - } - - public function setFeedId($feedId) { - $this->feedId = $feedId; - } - - public function getGuid() { - return $this->guid; - } - public function setGuid($guid) { - $this->guid = $guid; - } - public function getId() { - return $this->id; - } - - public function setId($id) { - $this->id = $id; - } + public function setRead() { $this->status &= ~StatusFlag::UNREAD; @@ -97,38 +130,9 @@ class Item extends Entity { public function isImportant() { return ($this->status & StatusFlag::IMPORTANT); } - - public function getStatus() { - return $this->status; - } - - public function setStatus($status) { - $this->status = $status; - } - - public function getTitle() { - return $this->title; - } - - public function setTitle($title) { - $this->title = $title; - } - public function getFeedTitle() { - return $this->feedTitle; - } - public function setFeedTitle($feedtitle) { - $this->feedTitle = $feedtitle; - } - - public function getUrl() { - return $this->url; - } - - public function setUrl($url) { - $this->url = $url; - } + public function getBody() { return $this->body; |