Permalink
Browse files

Merge pull request #2 from MissAllSunday/Notifications

Notifications
  • Loading branch information...
2 parents 178e292 + adbba13 commit 5fd3d6d6b91aee973d3baddc7c841a2b861dbd78 @MissAllSunday committed Jul 6, 2012
@@ -55,7 +55,7 @@ function __autoload($class_name)
class Breeze
{
static public $BreezeName = 'Breeze';
- static public $BreezeVersion = '1.0 Beta 1';
+ static public $BreezeVersion = '1.0 Beta 3';
static public $BreezeFolder = '/Breeze/';
public function __construct(){}
@@ -44,17 +44,17 @@ public function __construct(){}
public static function Buddy()
{
- global $user_info, $scripturl, $context, $memberContext;
+ global $user_info, $scripturl, $context;
checkSession('get');
isAllowedTo('profile_identity_own');
is_not_guest();
/* We need all this stuff */
- $sa = new BreezeGlobals('get');
- $notification = new BreezeNotifications();
- $settings = BreezeSettings::getInstance();
+ $sa = Breeze::sGlobals('get');
+ $notification = Breeze::notifications();
+ $settings = Breeze::settings();
/* There's gotta be an user... */
if ($sa->validate('u') == false)
@@ -75,49 +75,48 @@ public static function Buddy()
/* Before anything else, let's ask the user shall we? */
elseif ($user_info['id'] != $sa->getRaw('u'))
{
- /* Load the users link */
- $user_load = array(
- $user_info['id'],
- $sa->getRaw('u')
- );
-
- /* Load all the members up. */
- $temp_users_load = BreezeSubs::LoadUserInfo($user_load);
-
$params = array(
- 'user' => $sa->getRaw('u'),
+ 'user' => $user_info['id'],
+ 'user_to' => $sa->getRaw('u'),
'type' => 'buddy',
'time' => time(),
'read' => 0,
- 'content' => array(
- 'message' => sprintf($settings->getText('buddy_messagerequest_message'), $temp_users_load[$user_info['id']]['link']),
- 'url' => $scripturl .'?action=profile;area=breezebuddies;u='. $sa->getRaw('u'),
- 'from_link' => $temp_users_load[$user_info['id']]['link'],
- 'from_id' => $user_info['id'],
- 'from_buddies' => $user_info['buddies']
- )
);
/* Notification here */
- $notification->Create($params);
+ $notification->createBuddy($params);
/* Show a nice message saying the user must approve the friendship request */
redirectexit('action=breezebuddyrequest;u=' . $sa->getRaw('u'));
}
}
- public function ShowBuddyRequests($user)
+ public function showBuddyRequests($user)
{
- $query = BreezeQuery::getInstance();
+ global $context;
+
+ $query = Breeze::query();
+ $text = Breeze::text();
+ $tools = Breeze::tools();
/* Load all buddy request for this user */
- $temp = $query->GetNotificationByType('buddy');
+ $temp = $query->getNotificationByType('buddy');
$temp2 = array();
/* We only want the notifications for this user... */
- foreach($temp as $t)
- if ($t['user'] == $user)
- $temp2[$t['id']] = $t;
+ if (!empty($temp))
+ foreach($temp as $t)
+ if ($t['user_to'] == $user)
+ {
+ $temp2[$t['id']] = $t;
+
+ /* load the user's link */
+ if (!isset($context['Breeze']['user_info'][$t['user']]))
+ $tools->loadUserInfo($t['user']);
+
+ /* build the message */
+ $temp2[$t['id']]['content']['message'] = sprintf ($text->getText('buddy_messagerequest_message'), $context['Breeze']['user_info'][$t['user']]['link']);
+ }
/* Return the notifications */
return $temp2;
@@ -40,17 +40,23 @@
class BreezeNotifications
{
- protected $types = array();
- protected $params = array();
- private $user = 0;
- private $settings = '';
- private $query = '';
- private $ReturnArray = array();
- private $usersData = array();
+ protected $_settings = array();
+ protected $_params = array();
+ protected $_user = 0;
+ private $_query;
+ protected $_returnArray = array();
+ protected $_usersData = array();
+ protected $_types = array();
+ protected $_currentUser;
function __construct()
{
- $this->types = array(
+ global $user_info;
+
+ /* Current user */
+ $this->_currentUser = $user_info['id'];
+
+ $this->_types = array(
'comment',
'status',
'like',
@@ -59,79 +65,105 @@ function __construct()
);
/* We kinda need all this stuff, dont' ask why, just nod your head... */
- $this->settings = BreezeSettings::getInstance();
- $this->query = BreezeQuery::getInstance();
+ $this->_settings = Breeze::settings();
+ $this->_query = Breeze::query();
+ $this->_tools = Breeze::tools();
+ $this->_text = Breeze::text();
}
- public function Create($params)
+ public function create($params)
{
- global $user_info;
-
- /* Set this as false by default */
- $double_request = false;
-
- /* if the type is buddy then let's do a check to avoid duplicate entries */
- if (!empty($params) && in_array($params['type'], $this->types))
+ /* We have to make sure, we just have to! */
+ if (!empty($params) && in_array($params['type'], $this->_types))
{
- /* Load all the Notifications */
- $temp = $this->query->GetNotifications();
+ /* Is there additional content? */
+ if (!empty($params['content']))
+ $params['content'] = json_encode($params['content']);
- if (!empty($temp))
- foreach ($temp as $t)
- if ($t['user'] == $params['user'] && $t['content']->from_id == $user_info['id'] && $t['type'] != 'mention')
- $double_request = true;
+ else
+ $params['content'] = '';
+
+ $this->_query->insertNotification($params);
}
- if ($double_request)
- fatal_lang_error('BreezeMod_buddyrequest_error_doublerequest', false);
+ else
+ return false;
+ }
- elseif (!empty($params) && in_array($params['type'], $this->types) && !$double_request)
- {
- $this->params = $params;
+ public function createMention($params)
+ {
- /* Convert to a json string */
- $this->params['content'] = json_encode($this->params['content']);
+ }
- $this->query->InsertNotification($this->params);
+ public function createBuddy($params)
+ {
+ /* Set this as false by default */
+ $double_request = false;
+
+ /* Yes, I know this is fugly! */
+ $tempQuery = new BreezeDB('breeze_notifications');
+
+ /* if the type is buddy then let's do a check to avoid duplicate entries */
+ if (!empty($params) && in_array($params['type'], $this->_types))
+ {
+ /* Doing a quick query will be better than loading the entire notifications array */
+ $tempParams = array (
+ 'rows' => '*',
+ 'where' => 'user = {int:user} AND user_to = {int:user_to}',
+ );
+ $tempData = array(
+ 'user' => !empty($params['user']) ? $params['user'] : $this->_currentUser,
+ 'user_to' => $params['user_to'],
+ );
+ $tempQuery->params($tempParams, $tempData);
+ $tempQuery->getData('id');
+
+ $return = $tempQuery->dataResult();
+
+ /* Patience is a virtue, you obviously don't know that, huh? */
+ if (!empty($return))
+ fatal_lang_error('BreezeMod_buddyrequest_error_doublerequest', false);
+
+ /* We are good to go */
+ else
+ $this->create($params);
}
else
return false;
}
- public function Count()
+ public function count()
{
- return count($this->query->GetNotifications());
+ return count($this->query->getNotifications());
}
- protected function GetByUser($user)
+ protected function getByUser($user)
{
/* Dont even bother... */
if (empty($user))
- return;
-
- $user = (int) $user;
+ return false;
- return $this->query->GetNotificationByUser($user);
+ return $this->query->getNotificationByUser($user);
}
public function doStream($user)
{
global $context;
- $this->all = $this->GetByUser($user);
+ $this->_all = $this->getByUser($user);
$context['insert_after_template'] .= '
<script type="text/javascript"><!-- // --><![CDATA[
$(document).ready(function()
{';
/* Check for the type and act in accordance */
- foreach($this->all as $all)
- if (in_array($all['type'], $this->types))
+ foreach($this->_all as $all)
+ if (in_array($all['type'], $this->_types))
{
- $call = 'do' . ucfirst($this->types[$all['type']]);
- $context['insert_after_template'] .= $this->$call($all) == false ? '' : $this->$call($all);
+ $call = 'do' . ucfirst($this->_types[$all['type']]);
+ $context['insert_after_template'] .= '$.sticky(\''. JavaScriptEscape($this->$call($all) == false ? '' : $this->$call($all)) .'\');';
}
$context['insert_after_template'] .= '
@@ -144,21 +176,39 @@ protected function doComments($noti)
{
global $user_info;
- if ($noti['content']['user_who_commented'] == $user_info['id'])
+ if ($noti['content']['user_who_commented'] == $this->_currentUser)
return false;
- if ($noti['content']['user_who_created_the_status'] == $user_info['id'])
- $message = '$.sticky(\''. JavaScriptEscape($s['content']->message) .'\');';
+ if ($noti['content']['user_who_created_the_status'] == $this->_currentUser)
+ $message = '';
+
+ return $message;
+ }
+
+ protected function doBuddy($noti)
+ {
+ global $user_info;
+
+ /* Extra check */
+ if ($noti['user_to'] != $this->_currentUser)
+ return false;
+
+ /* load the user's link */
+ if (!isset($context['Breeze']['user_info'][$noti['user']]))
+ $this->_tools->loadUserInfo($noti['user']);
+
+ if ($noti['content']['user_who_created_the_status'] == $this->_currentUser)
+ $message = '$.sticky(\''. sprintf ($this->_text->getText('buddy_messagerequest_message'), $context['Breeze']['user_info'][$noti['user']]['link']) .'\');';
return $message;
}
- protected function Delete($id)
+ protected function delete($id)
{
- $this->query->DeleteNotification($id);
+ $this->query->deleteNotification($id);
}
- protected function MarkAsRead($id)
+ protected function markAsRead($id)
{
$this->query->MarkAsReadNotification($id);
}
Oops, something went wrong.

0 comments on commit 5fd3d6d

Please sign in to comment.