示例#1
0
 private function byName($contains, $limit, $project = false)
 {
     if ($limit) {
         $limit = Security::limitControl($limit, 20);
     }
     if (!$project) {
         $table = 'users';
         $field = 'username';
         $fetcher = $this->user;
     } else {
         $table = 'groups';
         $field = 'name';
         $fetcher = $this->project;
     }
     if (!($stmt = Db::query(['SELECT "' . $field . '" FROM "' . $table . '" u WHERE u.' . $field . ' ILIKE :contains ORDER BY u.' . $field . ' LIMIT ' . $limit, [':contains' => "%{$contains}%"]], Db::FETCH_STMT))) {
         return [];
     }
     $elements = $stmt->fetchAll(PDO::FETCH_COLUMN);
     $ret = [];
     foreach ($elements as $u) {
         $ret[] = $fetcher->getBasicInfo($u);
     }
     return $ret;
 }
示例#2
0
 public function getFriends($id, $limit = 0)
 {
     if ($limit) {
         $limit = Security::limitControl($limit, 20);
     }
     if (!($stmt = Db::query(['select "to" from (
                 select "to" from followers where "from" = :id) as f
                 inner join 
                 (select "from" from followers where "to" = :id) as e
                 on f.to = e.from
                 inner join users u on u.counter = f.to order by username' . ($limit != 0 ? ' LIMIT ' . $limit : ''), [':id' => $id]], Db::FETCH_STMT))) {
         return [];
     }
     return $stmt->fetchAll(PDO::FETCH_COLUMN);
 }
示例#3
0
 public function getInteractions($id, $limit = 0)
 {
     if (!$this->user->isLogged()) {
         return [];
     }
     if ($limit) {
         $limit = Security::limitControl($limit, 20);
     }
     $objs = [];
     if (!($objs = Db::query(['SELECT "type", extract(epoch from time) as time, pid, post_to
             FROM group_interactions(:me, :id) AS
             f("type" text, "time" timestamp with time zone, pid int8, post_to int8)
             ORDER BY f.time DESC' . ($limit !== 0 ? " LIMIT {$limit}" : ''), [':me' => $_SESSION['id'], ':id' => $id]], Db::FETCH_OBJ, true))) {
         return [];
     }
     $ret = [];
     for ($i = 0, $count = count($objs); $i < $count; ++$i) {
         $ret[$i]['type_n'] = $objs[$i]->type;
         $ret[$i]['datetime_n'] = $this->user->getDateTime($objs[$i]->time);
         $ret[$i]['pid_n'] = $objs[$i]->pid;
         $ret[$i]['postto_n'] = static::getName($objs[$i]->post_to);
         $ret[$i]['link_n'] = Utils::projectLink($ret[$i]['postto_n']) . $objs[$i]->pid;
     }
     return $ret;
 }