Exemplo n.º 1
0
 /**
  * Get matched users with limit 10
  * @param string $qry
  * @return array
  */
 public function find($qry, $catid, $tid)
 {
     $cid = (int) $catid;
     $tid = (int) $tid;
     $selector = '';
     if ($cid) {
         $selector = ', MAX(p.granted) AS allowed';
     }
     $users = \DB::table(PREFIX . 'codo_users AS u');
     $users->select(\DB::raw('u.id, u.username, u.avatar' . $selector))->where('u.username', 'LIKE', "{$qry}%")->where('u.mail', '<>', 'anonymous@localhost');
     if ($cid) {
         $users->leftJoin(PREFIX . 'codo_user_roles AS r', 'r.uid', '=', 'u.id')->leftJoin(PREFIX . 'codo_permissions AS p', function ($join) use($cid) {
             $join->on('p.permission', '=', \DB::raw('\'view all topics\''))->on('p.rid', '=', 'r.rid')->on('p.cid', '=', \DB::raw($cid))->on('p.tid', '=', \DB::raw(0));
         })->groupBy('u.id');
     }
     $users = $users->take(10)->get();
     $type = '';
     if ($cid) {
         $type = 'new_topic';
     }
     if ($tid) {
         $type = 'new_reply';
     }
     $mutedIds = array();
     if ($type != '' && count($users)) {
         $uids = array_column($users, 'id');
         $subscriber = new Subscriber();
         $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $uids);
     }
     $_users = array();
     $i = 0;
     foreach ($users as $user) {
         $_users[$i]["username"] = $user['username'];
         $_users[$i]["avatar"] = \CODOF\Util::get_avatar_path($user['avatar'], $user['id'], false);
         if ($cid) {
             //if $cid is not provided can't say whether user is mentionable or not
             $notMentionable = in_array($user['id'], $mutedIds) || $user['allowed'] === 0;
             $_users[$i]["mentionable"] = !$notMentionable ? 'yes' : 'no';
             //better for js -> y/n
         }
         $i++;
     }
     return $_users;
 }
Exemplo n.º 2
0
 /**
  *  Dequeues notification queue and enqueues email queue
  *  Table codo_notify
  *  type           id data              is_read
  *  new_reply      1  {tid: 4, pid: 5}  0      --> depends on subscription
  *  new_topic      2  {tid: 4}          1      --> depends on subscription
  *  new_badge      2  {bid: 3}          0      --> system notification
  *  vote_up        2  {pid: 5}          1      --> depend on user settings
  *  new_like       1  {pid: 7}          1      --> depend on user settings
  *  mention        4  {pid: 3}          0      --> depends on subscription
  */
 public function dequeueNotify()
 {
     $qry = 'SELECT q.id,q.type,q.nid,t.data FROM ' . PREFIX . 'codo_notify_queue AS q' . ' INNER JOIN codo_notify_text AS t ON q.nid=t.id';
     $res = $this->db->query($qry);
     if (!$res) {
         return false;
     }
     $maxID = 0;
     $queue = $res->fetchAll();
     $subscriber = new Subscriber();
     $user = \CODOF\User\User::get();
     $frequency = $user->prefers('notification_frequency');
     foreach ($queue as $queuedNotification) {
         $maxID = max($queuedNotification['id'], $maxID);
         $type = $queuedNotification['type'];
         $nid = $queuedNotification['nid'];
         $data = json_decode($queuedNotification['data']);
         $mentions = $data->mentions;
         $cid = $data->cid;
         $tid = $data->tid;
         $pid = $data->pid;
         if (!empty($mentions)) {
             $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $mentions);
             $notMuted = array_diff($mentions, $mutedIds);
             $this->notify($notMuted, 'mention', $nid);
         }
         $offset = 0;
         //get all types of subscribers of this category/topic
         while ($subscribers = $subscriber->of($type, $cid, $tid, $offset)) {
             //we do not need anyone subscribed to this topic since it
             //is a new topic and so the creator will be the first subscriber
             //segregate subscribers into different groups based on type
             $idTypes = $subscriber->groupBySubscriptionType($subscribers);
             //add notifications for FOLLOWING & NOTIFIED that a new topic is created
             $this->notify(array_merge($idTypes['FOLLOWING'], $idTypes['NOTIFIED']), $type, $nid);
             $offset += Subscriber::$maxRows;
         }
         //if ($frequency == 'immediate') {
         //queue all emails which will be sent in different cron run
         \CODOF\Hook::call('after_notify_insert', array("cid" => $cid, "tid" => $tid, "pid" => $pid, "type" => $type));
         //}
     }
     //delete old queued notifications
     $qry = 'DELETE FROM ' . PREFIX . 'codo_notify_queue WHERE id <= ' . $maxID;
     $this->db->query($qry);
 }