Example #1
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     $database = \App::get('db');
     $this->moduleclass = $this->params->get('moduleclass');
     $this->limit = intval($this->params->get('limit', 10));
     // Find the user's most recent support tickets
     $recipient = new Recipient($database);
     $this->rows = $recipient->getUnreadMessages(User::get('id'), $this->limit);
     $this->total = count($recipient->getUnreadMessages(User::get('id')));
     if ($recipient->getError()) {
         $this->setError($recipient->getError());
     }
     require $this->getLayoutPath();
 }
Example #2
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     if (!Plugin::isEnabled('members', 'messages')) {
         $this->setError(Lang::txt('MOD_MYMESSAGES_REQUIRED_PLUGIN_DISABLED'));
     } else {
         $database = \App::get('db');
         $this->moduleclass = $this->params->get('moduleclass');
         $this->limit = intval($this->params->get('limit', 10));
         // Find the user's most recent support tickets
         $recipient = Recipient::blank();
         $this->rows = $recipient->getUnreadMessages(User::get('id'), $this->limit);
         $this->total = $recipient->getUnreadMessagesCount(User::get('id'));
         if ($recipient->getError()) {
             $this->setError($recipient->getError());
         }
     }
     require $this->getLayoutPath();
 }
Example #3
0
 /**
  * Get records for specific type, element, component, and user
  *
  * @param   string   $type       Action type
  * @param   string   $component  Component name
  * @param   integer  $element    ID of element that needs action
  * @param   integer  $uid        User ID
  * @return  object
  */
 public static function getActionItems($type, $component, $element, $uid)
 {
     $entries = self::all();
     $a = $entries->getTableName();
     $m = Message::blank()->getTableName();
     $r = Recipient::blank()->getTableName();
     return $entries->select($m . '.id')->join($r, $r . '.actionid', $a . '.id', 'inner')->join($m, $m . '.id', $r . '.mid', 'inner')->whereEquals($m . '.type', $type)->whereEquals($r . '.uid', $uid)->whereEquals($a . '.class', $component)->whereEquals($a . '.element', $element)->rows();
 }
Example #4
0
 /**
  * Send a message to one or more users
  *
  * @param   string   $type         Message type (maps to #__xmessage_component table)
  * @param   string   $subject      Message subject
  * @param   string   $message      Message to send
  * @param   array    $from         Message 'from' data (e.g., name, address)
  * @param   array    $to           List of user IDs
  * @param   string   $component    Component name
  * @param   integer  $element      ID of object that needs an action item
  * @param   string   $description  Action item description
  * @param   integer  $group_id     Parameter description (if any) ...
  * @return  mixed    True if no errors else error message
  */
 public function sendMessage($type, $subject, $message, $from = array(), $to = array(), $component = '', $element = null, $description = '', $group_id = 0)
 {
     // Do we have a message?
     if (!$message) {
         return false;
     }
     // Do we have a subject line? If not, create it from the message
     if (!$subject && $message) {
         $subject = substr($message, 0, 70);
         if (strlen($subject) >= 70) {
             $subject .= '...';
         }
     }
     $database = \App::get('db');
     // Create the message object and store it in the database
     $xmessage = new Message($database);
     $xmessage->subject = $subject;
     $xmessage->message = $message;
     $xmessage->created = Date::toSql();
     $xmessage->created_by = User::get('id');
     $xmessage->component = $component;
     $xmessage->type = $type;
     $xmessage->group_id = $group_id;
     if (!$xmessage->store()) {
         return $xmessage->getError();
     }
     // Does this message require an action?
     // **DEPRECATED**
     $action = new Action($database);
     /*if ($element || $description)
     		{
     			$action->class       = $component;
     			$action->element     = $element;
     			$action->description = $description;
     			if (!$action->store())
     			{
     				return $action->getError();
     			}
     		}*/
     // Do we have any recipients?
     if (count($to) > 0) {
         // Loop through each recipient
         foreach ($to as $uid) {
             // Create a recipient object that ties a user to a message
             $recipient = new Recipient($database);
             $recipient->uid = $uid;
             $recipient->mid = $xmessage->id;
             $recipient->created = Date::toSql();
             $recipient->expires = Date::of(time() + 168 * 24 * 60 * 60)->toSql();
             $recipient->actionid = $action->id;
             if (!$recipient->store()) {
                 return $recipient->getError();
             }
             // Get the user's methods for being notified
             $notify = new Notify($database);
             $methods = $notify->getRecords($uid, $type);
             $user = User::getInstance($uid);
             // Do we have any methods?
             if ($methods) {
                 // Loop through each method
                 foreach ($methods as $method) {
                     $action = strtolower($method->method);
                     if (!Event::trigger('xmessage.onMessage', array($from, $xmessage, $user, $action))) {
                         $this->setError(Lang::txt('Unable to message user %s with method %s', $uid, $action));
                     }
                 }
             }
         }
     }
     return true;
 }
Example #5
0
 /**
  * Builds a query string based on filters passed
  *
  * @param   array   $filters  Filters to build query from
  * @return  string  SQL
  */
 private function buildQuery($filters = array())
 {
     $entries = self::all();
     $m = $entries->getTableName();
     $u = '#__users';
     if (isset($filters['group_id']) && $filters['group_id'] != 0) {
         $entries->select($m . '.*,' . $u . '.name')->join($u, $u . '.id', $m . '.created_by', 'inner');
     } else {
         $r = Recipient::blank()->getTableName();
         $entries->select($m . '.*,' . $u . '.name')->join($r, $r . '.mid', $m . '.id', 'inner')->join($u, $u . '.id', $r . '.uid', 'inner');
     }
     if (isset($filters['created_by']) && $filters['created_by'] != 0) {
         $entries->whereEquals('created_by', $filters['created_by']);
     }
     if (isset($filters['daily_limit']) && $filters['daily_limit'] != 0) {
         $start = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . " 00:00:00";
         $end = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . " 23:59:59";
         $entries->where('created', '>=', $start);
         $entries->where('created', '<=', $end);
     }
     if (isset($filters['group_id']) && $filters['group_id'] != 0) {
         $entries->whereEquals('group_id', (int) $filters['group_id']);
     }
     return $entries;
 }