4 * @file src/Model/Register.php
6 namespace Friendica\Model;
8 use Friendica\Database\DBA;
9 use Friendica\Util\DateTimeFormat;
12 * Class interacting with the register database table
14 * @author Hypolite Petovan <mrpetovan@gmail.com>
19 * Return the list of pending registrations
23 public static function getPending()
26 "SELECT `register`.*, `contact`.`name`, `user`.`email`
28 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
29 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
32 return DBA::toArray($stmt);
36 * Returns the pending registration count
40 public static function getPendingCount()
42 $register = DBA::fetchFirst(
43 "SELECT COUNT(*) AS `count`
45 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
48 return $register['count'];
52 * Returns the register record associated with the provided hash
57 public static function getByHash($hash)
59 return DBA::selectFirst('register', [], ['hash' => $hash]);
63 * Returns true if a register record exists with the provided hash
68 public static function existsByHash($hash)
70 return DBA::exists('register', ['hash' => $hash]);
74 * Creates a register record for an invitation and returns the auto-generated code for it
78 public static function createForInvitation()
80 $code = autoname(8) . srand(1000, 9999);
84 'created' => DateTimeFormat::utcNow()
87 DBA::insert('register', $fields);
93 * Creates a register record for approval and returns the success of the database insert
94 * Checks for the existence of the provided user id
96 * @param integer $uid The ID of the user needing approval
97 * @param string $language The registration language
98 * @param string $note An additional message from the user
101 public static function createForApproval($uid, $language, $note = '')
103 $hash = random_string();
105 if (!User::exists($uid)) {
111 'created' => DateTimeFormat::utcNow(),
113 'password' => '', // Obsolete, slated for deletion
114 'language' => $language,
118 return DBA::insert('register', $fields);
122 * Deletes a register record by the provided hash and returns the success of the database deletion
124 * @param string $hash
127 public static function deleteByHash($hash)
129 return DBA::delete('register', ['hash' => $hash]);