4 * @file src/Model/Register.php
7 namespace Friendica\Model;
9 use Friendica\Database\DBA;
10 use Friendica\Util\DateTimeFormat;
11 use Friendica\Util\Strings;
14 * Class interacting with the register database table
16 * @author Hypolite Petovan <mrpetovan@gmail.com>
21 * Return the list of pending registrations
26 public static function getPending()
29 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
31 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
32 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
35 return DBA::toArray($stmt);
39 * Returns the pending registration count
44 public static function getPendingCount()
46 $register = DBA::fetchFirst(
47 "SELECT COUNT(*) AS `count`
49 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
52 return $register['count'];
56 * Returns the register record associated with the provided hash
62 public static function getByHash($hash)
64 return DBA::selectFirst('register', [], ['hash' => $hash]);
68 * Returns true if a register record exists with the provided hash
74 public static function existsByHash($hash)
76 return DBA::exists('register', ['hash' => $hash]);
80 * Creates a register record for an invitation and returns the auto-generated code for it
85 public static function createForInvitation()
87 $code = Strings::getRandomName(8) . random_int(1000, 9999);
91 'created' => DateTimeFormat::utcNow()
94 DBA::insert('register', $fields);
100 * Creates a register record for approval and returns the success of the database insert
101 * Checks for the existence of the provided user id
103 * @param integer $uid The ID of the user needing approval
104 * @param string $language The registration language
105 * @param string $note An additional message from the user
109 public static function createForApproval($uid, $language, $note = '')
111 $hash = Strings::getRandomHex();
113 if (!User::exists($uid)) {
119 'created' => DateTimeFormat::utcNow(),
121 'password' => '', // Obsolete, slated for deletion
122 'language' => $language,
126 return DBA::insert('register', $fields);
130 * Deletes a register record by the provided hash and returns the success of the database deletion
132 * @param string $hash
136 public static function deleteByHash($hash)
138 return DBA::delete('register', ['hash' => $hash]);