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
24 public static function getPending()
27 "SELECT `register`.*, `contact`.`name`, `user`.`email`
29 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
30 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
33 return DBA::toArray($stmt);
37 * Returns the pending registration count
41 public static function getPendingCount()
43 $register = DBA::fetchFirst(
44 "SELECT COUNT(*) AS `count`
46 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
49 return $register['count'];
53 * Returns the register record associated with the provided hash
58 public static function getByHash($hash)
60 return DBA::selectFirst('register', [], ['hash' => $hash]);
64 * Returns true if a register record exists with the provided hash
69 public static function existsByHash($hash)
71 return DBA::exists('register', ['hash' => $hash]);
75 * Creates a register record for an invitation and returns the auto-generated code for it
79 public static function createForInvitation()
81 $code = autoname(8) . srand(1000, 9999);
85 'created' => DateTimeFormat::utcNow()
88 DBA::insert('register', $fields);
94 * Creates a register record for approval and returns the success of the database insert
95 * Checks for the existence of the provided user id
97 * @param integer $uid The ID of the user needing approval
98 * @param string $language The registration language
99 * @param string $note An additional message from the user
102 public static function createForApproval($uid, $language, $note = '')
104 $hash = Strings::getRandomHex();
106 if (!User::exists($uid)) {
112 'created' => DateTimeFormat::utcNow(),
114 'password' => '', // Obsolete, slated for deletion
115 'language' => $language,
119 return DBA::insert('register', $fields);
123 * Deletes a register record by the provided hash and returns the success of the database deletion
125 * @param string $hash
128 public static function deleteByHash($hash)
130 return DBA::delete('register', ['hash' => $hash]);