зеркало из https://github.com/nextcloud/news.git
mark as read item working now
This commit is contained in:
Родитель
5754af967c
Коммит
4b154de452
|
@ -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,8 +36,13 @@ class OC_News_Item {
|
|||
$this->url = $url;
|
||||
$this->guid = $guid;
|
||||
$this->body = $body;
|
||||
if ($id == null) {
|
||||
$this->status |= StatusFlag::Unread;
|
||||
}
|
||||
else {
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
||||
public function getGuid(){
|
||||
return $this->guid;
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче