Get the standard favouriting sql.

@param int $userid The ID of the user we are getting the sql for
@return [$sql, $params] An array comprising of the sql and any associated params
439919
private function get_favourite_sql(int $userid): array {

        $usercontext = \context_user::instance($userid);
        $alias = $this->get_table_alias();
        $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext);
        list($favsql, $favparams) = $ufservice->get_join_sql_by_type('mod_forum', 'discussions',
            $this->get_favourite_alias(), "$alias.id");

        return [$favsql, $favparams];
    }
1043512
public static function getSessionWithUserId($userid)
	{
		// get list of all sessions
		$sessions = \App::get('session')->getStore()->all(array(
			'guest'    => 0,
			'distinct' => 1
		));

		// see if any session matches our userid
		foreach ($sessions as $session)
		{
			if ($session->userid == $userid)
			{
				return $session;
			}
		}

		// nothing found
		return null;
	}
484667
public function deleteUserQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->delete($this->getTableName());

        if (is_numeric($userId)) {
            $qb->where('id = :userId');
        } else {
            $qb->where('username = :userId')->orWhere('email = :userId');
        }
        $qb->setParameter('userId', $userId);

        return $qb;
    }
1230399
public static function get_contexts_for_userid(int $userid) : contextlist {
        $params = ['modulename' => 'assign',
                   'contextlevel' => CONTEXT_MODULE,
                   'userid' => $userid,
                   'graderid' => $userid,
                   'aouserid' => $userid,
                   'asnuserid' => $userid,
                   'aufuserid' => $userid,
                   'aumuserid' => $userid];

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)";

        $contextlist = new contextlist();
        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_overrides} ao ON a.id = ao.assignid
                 WHERE ao.userid = :aouserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_submission} asn ON a.id = asn.assignment
                 WHERE asn.userid = :asnuserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_user_flags} auf ON a.id = auf.assignment
                 WHERE auf.userid = :aufuserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_user_mapping} aum ON a.id = aum.assignment
                 WHERE aum.userid = :aumuserid";

        $contextlist->add_from_sql($sql, $params);

        manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
                'get_context_for_userid_within_feedback', [$userid, $contextlist]);
        manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
                'get_context_for_userid_within_submission', [$userid, $contextlist]);

        return $contextlist;
    }
1082199
public function getUser(string $userid)
    {
        $cl = $this->getUserClass();
        $user = new $cl;
        return $user->obtainByUserID($userid);
    }
107546
public static function all($userId, $params = null, $options = null)
    {
        return self::_userBasedList($userId, $params, $options);
    }
734366
protected function fetchUserData($userId)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query
            ->select(
                $this->dbHandler->quoteColumn('contentobject_id', 'ezuser'),
                $this->dbHandler->quoteColumn('login', 'ezuser'),
                $this->dbHandler->quoteColumn('email', 'ezuser'),
                $this->dbHandler->quoteColumn('password_hash', 'ezuser'),
                $this->dbHandler->quoteColumn('password_hash_type', 'ezuser')
            )
            ->from($this->dbHandler->quoteTable('ezuser'))
            ->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('contentobject_id', 'ezuser'),
                    $query->bindValue($userId)
                )
            );

        $stmt = $query->prepare();
        $stmt->execute();

        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        return isset($rows[0]) ? $this->convertColumnsToProperties($rows[0]) : array();
    }
953173
public function get($userId)
    {
        $endpoint = '/admin/users/'.$userId.'.json';
        $response = $this->request($endpoint);
        return $this->createObject(User::class, $response['user']);
    }
152512
public function findOneByUserId($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->field('userId')->equals($userId);

        return $qb->getQuery()->getSingleResult();
    }
144522
public static function get_user_competencies_by_userevidenceid($userevidenceid) {
        global $DB;

        $sql = "SELECT uc.*
                  FROM {" . user_competency::TABLE . "} uc
                  JOIN {" . self::TABLE . "} uec
                    ON uc.competencyid = uec.competencyid
                  JOIN {" . user_evidence::TABLE . "} ue
                    ON uec.userevidenceid = ue.id
                   AND uc.userid = ue.userid
                   AND ue.id = ?
              ORDER BY uc.id ASC";

        $usercompetencies = array();
        $records = $DB->get_recordset_sql($sql, array($userevidenceid));
        foreach ($records as $record) {
            $usercompetencies[] = new user_competency(0, $record);
        }
        $records->close();
        return $usercompetencies;
    }
779072
public static function getAllMenuIdArrByUserId($userId)
    {
        $data = static::find()
            ->findByUserId($userId)
            ->asArray()
            ->all();

        $menuIdArr = [];
        foreach ($data as $item) {
            $menu = DpAdminMenu::find()
                ->findByMenuId($item['menu_id'])
                ->asArray()
                ->one();
            if ($menu) {
                $menuIdArr[] = $item['menu_id'];
            }
        }

        return $menuIdArr;
    }
837043
public function getGroupIds($userId)
    {
        $groups = $this->find()
            ->select(['group_id'])
            ->where(['user_id' => $userId])
            ->hydrate(false)
            ->toArray();

        return Hash::extract($groups, '{n}.group_id');
    }
443021
public static function count_user_subscriptions($userid = 0) {
        global $DB, $USER;;
        if ($userid == 0) {
            $userid = $USER->id;
        }
        $sql = self::get_subscription_join_rule_sql(true);
        $sql .= "WHERE s.userid = :userid";

        return $DB->count_records_sql($sql, array('userid' => $userid));
    }
90826
public function GetCount($UserID = '') {
      $this->SQL
         ->Select('a.ActivityID', 'count', 'ActivityCount')
         ->From('Activity a')
         ->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
      
      if ($UserID != '') {
         $this->SQL
            ->BeginWhereGroup()
            ->Where('a.ActivityUserID', $UserID)
            ->OrWhere('a.RegardingUserID', $UserID)
            ->EndWhereGroup();
      }
      
      $Session = Gdn::Session();
      if (!$Session->IsValid() || $Session->UserID != $UserID)
         $this->SQL->Where('t.Public', '1');

      $this->FireEvent('BeforeGetCount');
      return $this->SQL
         ->Get()
         ->FirstRow()
         ->ActivityCount;
   }
989152
public static function getCredential($userId)
    {
        $model = new User_Credential();
        $where = 'account_id = ' . $model->_toDb($userId, 'account_id');
        $creds = $model->getList(array(
            'filter' => $where
        ));
        if ($creds === false or count($creds) !== 1) {
            return false;
        }
        return $creds[0];
    }
324407
public function getUser($userId)
    {
        $response = $this->client->get(sprintf('/v2/user/%s', $userId));

        return new User($response);
    }
714965
public static function get_async_restores($userid) {
        global $DB;

        $select = 'userid = ? AND execution = ? AND status < ? AND status > ? AND operation = ?';
        $params = array($userid, backup::EXECUTION_DELAYED, backup::STATUS_FINISHED_ERR, backup::STATUS_NEED_PRECHECK, 'restore');
        $restores = $DB->get_records_select(
            'backup_controllers',
            $select,
            $params,
            'timecreated DESC',
            'id, backupid, status, itemid, timecreated');

            return $restores;
    }