summaryrefslogtreecommitdiffstats
path: root/ajax
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-08-12 21:30:42 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-08-12 21:30:42 -0400
commitbe10a14e5877221041acd66a9da08e4514c8f8d1 (patch)
treeeff8ecca550cd0b4f69f57536beee2e167282e3d /ajax
parent90fb216e7dd61c9571d225aa7c5c834c654d9cef (diff)
parent6c327bd5f8cdbebf45c6aa87f2d54f3dd26663a2 (diff)
Merge commit 'refs/merge-requests/12' of git://gitorious.org/owncloud/apps into merge-requests/12
Diffstat (limited to 'ajax')
-rw-r--r--ajax/loadfeed.php18
-rw-r--r--ajax/markitem.php35
-rw-r--r--ajax/setallitemsread.php (renamed from ajax/importantitem.php)25
-rw-r--r--ajax/setitemstatus.php53
4 files changed, 74 insertions, 57 deletions
diff --git a/ajax/loadfeed.php b/ajax/loadfeed.php
index 992e65019..020f7a706 100644
--- a/ajax/loadfeed.php
+++ b/ajax/loadfeed.php
@@ -17,19 +17,19 @@ OCP\JSON::callCheck();
$userid = OCP\USER::getUser();
-$feedid = trim($_POST['feedid']);
+$feedId = trim($_POST['feedId']);
$l = OC_L10N::get('news');
-$tmpl_items = new OCP\Template("news", "part.items");
-$tmpl_items->assign('feedid', $feedid);
-$part_items = $tmpl_items->fetchPage();
+$itemsTpl = new OCP\Template("news", "part.items");
+$itemsTpl->assign('feedid', $feedId);
+$feedItems = $itemsTpl->fetchPage();
-$tmpl_items_header = new OCP\Template("news", "part.items.header");
-$tmpl_items_header->assign('feedid', $feedid);
-$items_header = $tmpl_items_header->fetchPage();
+$feedMapper = new OCA\News\FeedMapper();
+$feed = $feedMapper->findById($feedId);
+$feedTitle = $feed->getTitle();
OCP\JSON::success(array('data' => array( 'message' => $l->t('Feed loaded!'),
- 'items_header' => $items_header,
- 'part_items' => $part_items )));
+ 'feedTitle' => $feedTitle,
+ 'feedItems' => $feedItems )));
diff --git a/ajax/markitem.php b/ajax/markitem.php
deleted file mode 100644
index a6efc8521..000000000
--- a/ajax/markitem.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-// Check if we are a user
-OCP\JSON::checkLoggedIn();
-OCP\JSON::checkAppEnabled('news');
-OCP\JSON::callCheck();
-
-$itemid = $_POST['itemid'];
-
-$itemmapper = new OCA\News\ItemMapper();
-$item = $itemmapper->find($itemid);
-$item->setRead();
-$success = $itemmapper->update($item);
-
-$l = OC_L10N::get('news');
-
-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('itemid' => $itemid )));
-
diff --git a/ajax/importantitem.php b/ajax/setallitemsread.php
index 72a07f747..4c1876b50 100644
--- a/ajax/importantitem.php
+++ b/ajax/setallitemsread.php
@@ -15,28 +15,27 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
-$itemId = $_POST['itemId'];
-$isImportant = $_POST['isImportant'];
+$feedId = $_POST['feedId'];
$itemMapper = new OCA\News\ItemMapper();
-$item = $itemMapper->find($itemId);
-
-if($isImportant){
- $item->setImportant();
-} else {
- $item->setUnimportant();
+$items = $itemMapper->findAllStatus($feedId, OCA\News\StatusFlag::Unread);
+
+// FIXME: maybe there is a way to set all items read in the
+// FeedMapper instead of iterating through every item and updating as
+// necessary
+foreach($items as $item){
+ $item->setRead();
+ $success = $itemMapper->update($item);
}
-$success = $itemMapper->update($item);
-
$l = OC_L10N::get('news');
if(!$success) {
- OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as important.'))));
- OCP\Util::writeLog('news','ajax/importantitem.php: Error marking item as important: '.$_POST['itemId'], OCP\Util::ERROR);
+ OCP\JSON::error(array('data' => array('message' => $l->t('Error setting all items as read.'))));
+ OCP\Util::writeLog('news','ajax/setallitemsread.php: Error setting all items as read of feed '. $feedId, 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('itemId' => $itemId)));
+OCP\JSON::success(array('data' => array('feedId' => $feedId )));
diff --git a/ajax/setitemstatus.php b/ajax/setitemstatus.php
new file mode 100644
index 000000000..03dff7d94
--- /dev/null
+++ b/ajax/setitemstatus.php
@@ -0,0 +1,53 @@
+<?php
+/**
+* ownCloud - News app
+*
+* @author Alessandro Cosentino
+* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
+*
+* This file is licensed under the Affero General Public License version 3 or later.
+* See the COPYING-README file
+*
+*/
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('news');
+OCP\JSON::callCheck();
+
+$itemId = $_POST['itemId'];
+$status = $_POST['status'];
+
+$itemMapper = new OCA\News\ItemMapper();
+$item = $itemMapper->find($itemId);
+
+switch ($status) {
+ case 'read':
+ $item->setRead();
+ break;
+ case 'unread':
+ $item->setUnread();
+ break;
+ case 'important':
+ $item->setImportant();
+ break;
+ case 'unimportant':
+ $item->setUnimportant();
+ break;
+ default:
+ break;
+}
+
+$success = $itemMapper->update($item);
+
+$l = OC_L10N::get('news');
+
+if(!$success) {
+ OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as read.'))));
+ OCP\Util::writeLog('news','ajax/setitemstatus.php: Error setting itemstatus to '. $status .': '.$_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('itemId' => $itemId )));
+