return $tabs;
}
- public function format($notifs, $ident = "") {
+ /**
+ * @brief Format the notification query in an usable array
+ *
+ * @param array $notifs The array from the db query
+ * @param string $ident The notifications identifier (e.g. network)
+ * @return array
+ * string 'label' => The type of the notification
+ * string 'link' => URL to the source
+ * string 'image' => The avatar image
+ * string 'text' => The notification text
+ * string 'when' => Relative date of the notification
+ * bool 'seen' => Is the notification marked as "seen"
+ */
+ private function format($notifs, $ident = "") {
$notif = array();
$arr = array();
if (dbm::is_result($notifs)) {
foreach ($notifs as $it) {
+ // Because we use different db tables for the notification query
+ // we have sometimes $it['unseen'] and sometimes $it['seen].
+ // So we will have to transform $it['unseen']
if($it['unseen'])
$it['seen'] = ($it['unseen'] > 0 ? false : true);
+ // Depending on the identifier of the notification we need to use different defaults
switch ($ident) {
case 'system':
$default_item_label = 'notify';
- $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id'];
+ $default_item_link = $this->a->get_baseurl(true).'/notify/view/'. $it['id'];
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
$default_item_text = strip_tags(bbcode($it['msg']));
$default_item_when = relative_date($it['date']);
case 'home':
$default_item_label = 'comment';
- $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid'];
+ $default_item_link = $this->a->get_baseurl(true).'/display/'.$it['pguid'];
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
$default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']);
$default_item_when = relative_date($it['created']);
default:
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
- $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid'];
+ $default_item_link = $this->a->get_baseurl(true).'/display/'.$it['pguid'];
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
$default_item_text = (($it['id'] == $it['parent'])
? sprintf( t("%s created a new post"), $it['author-name'])
}
+ // Transform the different types of notification in an usable array
switch($it['verb']){
case ACTIVITY_LIKE:
$notif = array(
//'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'label' => 'like',
- 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
+ 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'],
'$image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
'when' => relative_date($it['created']),
$notif = array(
//'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'label' => 'dislike',
- 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
+ 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'],
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
'when' => relative_date($it['created']),
$notif = array(
//'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'label' => 'friend',
- 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
+ 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'],
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
'when' => relative_date($it['created']),
}
+ /**
+ * @brief Total number of network notifications
+ * @param int $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @return int Number of network notifications
+ */
private function networkTotal($seen = 0) {
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";
return 0;
}
- public function networkNotifs($seen = 0) {
+ /**
+ * @brief Get network notifications
+ *
+ * @param type $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @param int $start Start the query at this point
+ * @param int $limit Maximum number of query results
+ *
+ * @return array Query output
+ */
+ public function networkNotifs($seen = 0, $start = 0, $limit = 20) {
$ident = 'network';
$total = $this->networkTotal($seen);
WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
$sql_seen
- ORDER BY `item`.`created` DESC",
- intval(local_user())
+ ORDER BY `item`.`created` DESC LIMIT %d, %d ",
+ intval(local_user()),
+ intval($start),
+ intval($limit)
);
if(dbm::is_result($r)) {
}
}
+ /**
+ * @brief Total number of system notifications
+ * @param int $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @return int Number of system notifications
+ */
private function systemTotal($seen = 0) {
if($seen === 0)
$sql_seen = " AND `seen` = 0 ";
return 0;
}
- public function systemNotifs($seen = 0) {
+ /**
+ * @brief Get system notifications
+ *
+ * @param type $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @param int $start Start the query at this point
+ * @param int $limit Maximum number of query results
+ *
+ * @return array Query output
+ */
+ public function systemNotifs($seen = 0, $start = 0, $limit = 20) {
$ident = 'system';
$total = $this->systemTotal($seen);
if($seen === 0)
$sql_seen = " AND `seen` = 0 ";
- $r = q("SELECT * FROM `notify` WHERE `uid` = %d $sql_seen ORDER BY `date` DESC",
- intval(local_user())
+ $r = q("SELECT `id`, `photo`, `msg`, `date`, `seen` FROM `notify`
+ WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ",
+ intval(local_user()),
+ intval($start),
+ intval($limit)
);
if(dbm::is_result($r)) {
}
}
+ /**
+ * @brief Addional SQL query string for the personal notifications
+ *
+ * @return string The additional sql query
+ */
private function _personal_sql_extra() {
- $myurl = app::get_baseurl(true) . '/profile/'. $this->a->user['nickname'];
+ $myurl = $this->a->get_baseurl(true) . '/profile/'. $this->a->user['nickname'];
$myurl = substr($myurl,strpos($myurl,'://')+3);
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
$diasp_url = str_replace('/profile/','/u/',$myurl);
return $sql_extra;
}
+ /**
+ * @brief Total number of personal notifications
+ * @param int $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @return int Number of personal notifications
+ */
private function personalTotal($seen = 0) {
$sql_extra .= $this->_personal_sql_extra();
return 0;
}
- public function personalNotifs($seen = 0) {
+
+ /**
+ * @brief Get personal notifications
+ *
+ * @param type $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @param int $start Start the query at this point
+ * @param int $limit Maximum number of query results
+ *
+ * @return array Query output
+ */
+ public function personalNotifs($seen = 0, $start = 0, $limit = 20) {
$ident = 'personal';
$total = 0;
$sql_extra .= $this->_personal_sql_extra();
$sql_extra
$sql_seen
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
- ORDER BY `item`.`created` DESC" ,
- intval(local_user())
+ ORDER BY `item`.`created` DESC LIMIT %d, %d " ,
+ intval(local_user()),
+ intval($start),
+ intval($limit)
);
if(dbm::is_result($r)) {
}
}
+ /**
+ * @brief Total number of home notifications
+ * @param int $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @return int Number of home notifications
+ */
private function homeTotal($seen = 0) {
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";
$r = q("SELECT COUNT(*) AS `total` FROM `item`
- WHERE ``item`.`visible` = 1 AND
+ WHERE `item`.`visible` = 1 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
$sql_seen",
intval(local_user())
);
if(dbm::is_result($r))
- return $r['total'];
+ return $r[0]['total'];
return 0;
}
- public function homeNotifs($seen = 0) {
+ /**
+ * @brief Get home notifications
+ *
+ * @param type $seen
+ * If 0 only include notifications into the query
+ * which arn't marked as "seen" into
+ * @param int $start Start the query at this point
+ * @param int $limit Maximum number of query results
+ *
+ * @return array Query output
+ */
+ public function homeNotifs($seen = 0, $start = 0, $limit = 20) {
$ident = 'home';
$total = $this->homeTotal($seen);
WHERE `item`.`visible` = 1 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
$sql_seen
- ORDER BY `item`.`created` DESC",
- intval(local_user())
+ ORDER BY `item`.`created` DESC LIMIT %d, %d ",
+ intval(local_user()),
+ intval($start),
+ intval($limit)
);
if(dbm::is_result($r)) {
return;
}
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page'] : 1);
$show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0);
+
nav_set_selected('notifications');
$json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
// get the nav tabs for the notification pages
$tabs = $nm->getTabs();
$notif_content = array();
+ $perpage = 20;
+ $startrec = ($page * $perpage) - $perpage;
if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
nav_set_selected('introductions');
$notif_header = t('Notifications');
$notif_tpl = get_markup_template('notifications.tpl');
-// $notif_show_lnk .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
-// . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
$notif_show_lnk = array(
'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ),
);
if(dbm::is_result($r)) {
$a->set_pager_total($r[0]['total']);
- $a->set_pager_itemspage(20);
+ $a->set_pager_itemspage($perpage);
}
/// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
$notif_header = t('Network Notifications');
$notif_tpl = get_markup_template('notifications.tpl');
- $notifs = $nm->networkNotifs($show);
+ $notifs = $nm->networkNotifs($show, $startrec, $perpage);
$notif_show_lnk = array(
'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ),
$notif_header = t('System Notifications');
$notif_tpl = get_markup_template('notifications.tpl');
- $notifs = $nm->systemNotifs($show);
+ $notifs = $nm->systemNotifs($show, $startrec, $perpage);
$notif_show_lnk = array(
'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ),
$notif_header = t('Personal Notifications');
$notif_tpl = get_markup_template('notifications.tpl');
- $notifs = $nm->personalNotifs($show);
+ $notifs = $nm->personalNotifs($show, $startrec, $perpage);
$notif_show_lnk = array(
'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ),
$notif_header = t('Home Notifications');
$notif_tpl = get_markup_template('notifications.tpl');
- $notifs = $nm->homeNotifs($show);
+ $notifs = $nm->homeNotifs($show, $startrec, $perpage);
$notif_show_lnk = array(
'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ),
}
if(count($notifs['notifications']) > 0 ) {
+ // set the pager
+ $a->set_pager_total($notifs['total']);
+ $a->set_pager_itemspage($perpage);
+
+ // add additional informations (needed for json output)
+ $notifs['items_page'] = $a->pager['itemspage'];
+ $notifs['page'] = $a->pager['page'];
+
// The template files we need in different cases for formatting the content
$tpl_item_like = 'notifications_likes_item.tpl';
$tpl_item_dislike = 'notifications_dislikes_item.tpl';
'$notif_content' => $notif_content,
'$notif_nocontent' => $notif_nocontent,
'$notif_show_lnk' => $notif_show_lnk,
+ '$notif_paginate' => paginate($a)
));
- $o .= paginate($a);
return $o;
}