diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-08-12 21:59:02 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-08-12 21:59:02 -0400 |
commit | 93e7732a7c9d88ba570d95220c7df46a455cb4aa (patch) | |
tree | 2033dff188096713c021af5bafdc8cfde997a42d /ajax | |
parent | 8aa247ca730a16c837859b644b0e2998d41885ac (diff) | |
parent | d1459ce208daae48d2fa01ef3fe8131ce87b8cea (diff) |
Merge branch 'merge-requests/12' into newsapp
Diffstat (limited to 'ajax')
-rw-r--r-- | ajax/loadfeed.php | 18 | ||||
-rw-r--r-- | ajax/markitem.php | 35 | ||||
-rw-r--r-- | ajax/setallitemsread.php (renamed from ajax/importantitem.php) | 25 | ||||
-rw-r--r-- | ajax/setitemstatus.php | 53 |
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 ))); + |