Exemplo n.º 1
0
Arquivo: User.php Projeto: pdyn/user
 /**
  * Get an array of user objects based on multiple user IDs.
  *
  * @param \pdyn\database\DbDriverInterface $DB A database connection.
  * @param array $ids Array of user IDs.
  * @param int $opts Bitmask of options.
  * @return array Array of user objects for each passed ID, indexed by user id.
  */
 public static function get_by_ids(\pdyn\database\DbDriverInterface $DB, $ids, $opts = self::NO_OPTS)
 {
     if (empty($ids)) {
         return [];
     }
     $filters = [];
     if ($ids !== 'all' && !in_array('*', $ids, true)) {
         $filters['id'] = $ids;
     }
     if (static::opts_contains($opts, self::INCLUDE_DELETED) === false) {
         $filters['deleted'] = 0;
     }
     $order = ['id' => 'DESC'];
     $retopts = ['idindexed' => 'id'];
     $users = $DB->get_records(static::DB_TABLE, $filters, $order, '*', 0, null, $retopts);
     foreach ($users as $userid => $user) {
         $userid = (int) $userid;
         $users[$userid] = static::instance_from_record($DB, $user);
     }
     return $users;
 }
Exemplo n.º 2
0
 /**
  * Get a list of active sessions.
  *
  * @param  \pdyn\database\DbDriverInterface $DB An active database connection.
  * @return array Array of records of active sessions.
  */
 public static function get_online_users(\pdyn\database\DbDriverInterface &$DB)
 {
     return $DB->get_records('online_users', ['sess_invalid' => '0'], ['sess_created' => 'DESC']);
 }
Exemplo n.º 3
0
 /**
  * Get an array of objects by object IDs.
  *
  * @param \pdyn\database\DbDriverInterface $DB A database connection.
  * @param array|string $ids An array of object IDs to get, if 'all', will get all albums.
  * @return array An array of found objects.
  */
 public static function get_by_ids(\pdyn\database\DbDriverInterface $DB, $ids, $additionalfilters = [])
 {
     if (empty($ids)) {
         return [];
     }
     $filters = [];
     if ($ids !== 'all' && !in_array('*', $ids, true)) {
         $filters[static::DB_ID_FIELDNAME] = $ids;
     }
     if (!empty($additionalfilters)) {
         $filters = array_merge($filters, $additionalfilters);
     }
     $order = ['timeupdated' => 'DESC'];
     $retopts = ['idindexed' => static::DB_ID_FIELDNAME];
     $items = $DB->get_records(static::DB_TABLE, $filters, $order, '*', 0, null, $retopts);
     foreach ($items as $itemid => $item) {
         $items[$itemid] = static::instance_from_record($DB, $item);
     }
     return $items;
 }