4 * @file src/Model/Register.php
6 namespace Friendica\Model;
8 use Friendica\Database\DBA;
9 use Friendica\Util\DateTimeFormat;
10 use Friendica\Util\Strings;
13 * Class interacting with the register database table
15 * @author Hypolite Petovan <mrpetovan@gmail.com>
20 * Return the list of pending registrations
25 public static function getPending()
28 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
30 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
31 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
34 return DBA::toArray($stmt);
38 * Returns the pending registration count
43 public static function getPendingCount()
45 $register = DBA::fetchFirst(
46 "SELECT COUNT(*) AS `count`
48 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
51 return $register['count'];
55 * Returns the register record associated with the provided hash
61 public static function getByHash($hash)
63 return DBA::selectFirst('register', [], ['hash' => $hash]);
67 * Returns true if a register record exists with the provided hash
73 public static function existsByHash($hash)
75 return DBA::exists('register', ['hash' => $hash]);
79 * Creates a register record for an invitation and returns the auto-generated code for it
84 public static function createForInvitation()
86 $code = Strings::getRandomName(8) . srand(1000, 9999);
90 'created' => DateTimeFormat::utcNow()
93 DBA::insert('register', $fields);
99 * Creates a register record for approval and returns the success of the database insert
100 * Checks for the existence of the provided user id
102 * @param integer $uid The ID of the user needing approval
103 * @param string $language The registration language
104 * @param string $note An additional message from the user
108 public static function createForApproval($uid, $language, $note = '')
110 $hash = Strings::getRandomHex();
112 if (!User::exists($uid)) {
118 'created' => DateTimeFormat::utcNow(),
120 'password' => '', // Obsolete, slated for deletion
121 'language' => $language,
125 return DBA::insert('register', $fields);
129 * Deletes a register record by the provided hash and returns the success of the database deletion
131 * @param string $hash
135 public static function deleteByHash($hash)
137 return DBA::delete('register', ['hash' => $hash]);