This commit is contained in:
Alessandro Cosentino 2012-07-07 21:52:41 -04:00
Родитель 5754af967c
Коммит 4b154de452
5 изменённых файлов: 57 добавлений и 31 удалений

Просмотреть файл

@ -17,7 +17,7 @@ OCP\JSON::callCheck();
$userid = OCP\USER::getUser();
$feedid = trim($_POST['feedid']);
$feedid = $_POST['feedid'];
$feedmapper = new OC_News_FeedMapper();
$success = $feedmapper->deleteById($feedid);

Просмотреть файл

@ -15,20 +15,21 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
$itemid = trim($_POST['itemid']);
$itemid = $_POST['itemid'];
$itemmapper = new OC_News_ItemMapper();
$item = $itemmapper->find($itemid);
$feedid = $itemmapper->save($feed, 0);
$item->setRead();
$success = $itemmapper->update($item);
$l = OC_L10N::get('news');
if(!$feedid) {
OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.'))));
OCP\Util::writeLog('news','ajax/newfeed.php: Error adding feed: '.$_POST['feedurl'], OCP\Util::ERROR);
if(!$success) {
OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as read.'))));
OCP\Util::writeLog('news','ajax/markitem.php: Error marking item as read: '.$_POST['itemid'], OCP\Util::ERROR);
exit();
}
//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations
OCP\JSON::success(array('data' => array('message' => $l->t('Feed added!'))));
OCP\JSON::success(array('data' => array('message' => $l->t('Item updated!'))));

Просмотреть файл

@ -36,7 +36,12 @@ class OC_News_Item {
$this->url = $url;
$this->guid = $guid;
$this->body = $body;
$this->status |= StatusFlag::Unread;
if ($id == null) {
$this->status |= StatusFlag::Unread;
}
else {
$this->id = $id;
}
}
public function getGuid(){

Просмотреть файл

@ -18,6 +18,19 @@ class OC_News_ItemMapper {
const tableName = '*PREFIX*news_items';
public function fromRow($row){
$url = $row['url'];
$title = $row['title'];
$guid = $row['guid'];
$status = $row['status'];
$body = $row['body'];
$id = $row['id'];
$item = new OC_News_Item($url, $title, $guid, $body, $id);
$item->setStatus($status);
return $item;
}
/**
* @brief Retrieve all the item corresponding to a feed from the database
* @param feedid The id of the feed in the database table.
@ -28,13 +41,7 @@ class OC_News_ItemMapper {
$items = array();
while ($row = $result->fetchRow()) {
$url = $row['url'];
$title = $row['title'];
$guid = $row['guid'];
$status = $row['status'];
$body = $row['body'];
$item = new OC_News_Item($url, $title, $guid, $body);
$item->setStatus($status);
$item = $this->fromRow($row);
$items[] = $item;
}
@ -56,6 +63,30 @@ class OC_News_ItemMapper {
return $id;
}
/**
* @brief Update the item after its status has changed
* @returns The item whose status has changed.
*/
public function update(OC_News_Item $item){
$itemid = $item->getId();
$status = $item->getStatus();
$stmt = OCP\DB::prepare('
UPDATE ' . self::tableName .
' SET status = ?
WHERE id = ?
');
$params=array(
$status,
$itemid
);
$stmt->execute($params);
return true;
}
/**
* @brief Save the feed and all its items into the database
* @returns The id of the feed in the database table.
@ -99,20 +130,8 @@ class OC_News_ItemMapper {
$itemid = OCP\DB::insertid(self::tableName);
}
// update item: its status might have changed
// TODO: maybe make this a new function
else {
$stmt = OCP\DB::prepare('
UPDATE ' . self::tableName .
' SET status = ?
WHERE id = ?
');
$params=array(
$status,
$itemid
);
$stmt->execute($params);
update($item);
}
$item->setId($itemid);
return $itemid;
@ -127,8 +146,9 @@ class OC_News_ItemMapper {
$result = $stmt->execute(array($id));
$row = $result->fetchRow();
$url = $row['url'];
$title = $row['title'];
$item = $this->fromRow($row);
return $item;
}

Просмотреть файл

@ -14,7 +14,7 @@ foreach($items as $item) {
echo '<div class="title_read">' . $title . '</div>';
}
else {
echo '<div class="title_unread" onClick="News.Feed.markItem(' . $item->getId() . ')">' . $title . '</div>';
echo '<div class="title_unread" onClick="News.Feed.markItem(' . $item->getId() . ')">' . $title . '</div>';
}
echo '<div class="body">' . $item->getBody() . '</div></li>';
}