1
0

user.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. use Carbon\CarbonImmutable;
  3. /**
  4. * Class User
  5. *
  6. * @property int $id
  7. * @property string $email
  8. * @property int $old_id
  9. * @property int $referrer_id
  10. * @property string $password
  11. * @property bool $activated
  12. * @property int $level
  13. * @property int $score
  14. * @property string $title
  15. * @property string $first_name
  16. * @property string $last_name
  17. * @property string $gender
  18. * @property string $date_of_birth
  19. * @property string $locale
  20. * @property bool $reported
  21. * @property string $reported_comment
  22. * @property bool $can_claim
  23. * @property string $phone
  24. * @property string $verify_token
  25. * @property string $reset_token
  26. * @property bool $terms_accepted
  27. * @property bool $newsletter_consent
  28. * @property int $preferred_payment_method
  29. * @property string $bank_name
  30. * @property string $bank_sort_code
  31. * @property string $bank_account_number
  32. * @property string $paypal_email
  33. * @property string $dts_registered
  34. * @property string $dts_last_seen
  35. * @property string $dts_verified
  36. * @property string $dts_deleted
  37. * @property int $verifier_id
  38. * @property string $verifier_notes
  39. */
  40. class User extends Model {
  41. protected static $table = "user";
  42. protected static $id_field = "id";
  43. protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "locale", "reported", "reported_comment", "can_claim", "phone", "verify_token", "reset_token", "terms_accepted", "newsletter_consent", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
  44. // Constants
  45. const LEVEL_BANNED = 0;
  46. const LEVEL_REGISTERED = 1;
  47. const LEVEL_UNVERIFIED = 2;
  48. const LEVEL_DEACTIVATED = 4;
  49. const LEVEL_TESTER = 8;
  50. const LEVEL_VENUE = 16;
  51. const LEVEL_CUSTOMER = 32;
  52. const LEVEL_TESTER_MANAGER = 48;
  53. const LEVEL_ADMIN = 64;
  54. const LEVEL_SUPERADMIN = 128;
  55. const LEVELS = [
  56. 0 => "Banned",
  57. 1 => "Registered",
  58. 2 => "Unverified",
  59. 4 => "Deactivated",
  60. 8 => "Tester",
  61. 16 => "Venue",
  62. 32 => "Customer",
  63. 48 => "Tester Manager",
  64. 64 => "Admin",
  65. 128 => "Super Admin",
  66. ];
  67. const PAYMENT_METHOD_BANK_TRANSFER = 1;
  68. const PAYMENT_METHOD_PAYPAL = 2;
  69. const PAYMENT_METHODS = [
  70. 1 => "Bank Transfer",
  71. 2 => "PayPal",
  72. ];
  73. // Static methods
  74. /**
  75. * @return array
  76. */
  77. public static function titles(): array {
  78. return [
  79. "Miss" => MISS,
  80. "Mr" => MR,
  81. "Ms" => MS,
  82. "Dr" => DR
  83. ];
  84. }
  85. /**
  86. * @return array
  87. */
  88. public static function genders(): array {
  89. return [
  90. "Female" => FEMALE,
  91. "Male" => MALE,
  92. "Unspecified" => UNSPECIFIED
  93. ];
  94. }
  95. /**
  96. * @param string $password
  97. * @return bool
  98. */
  99. public static function validatePassword(string $password): bool {
  100. $lowercase = preg_match("/[a-z]/", $password);
  101. $uppercase = preg_match("/[A-Z]/", $password);
  102. $number = preg_match("/[0-9]/", $password);
  103. $special = preg_match("/[^0-9a-zA-Z]/", $password);
  104. $length = strlen($password) >= 6;
  105. return ($lowercase && $uppercase && $number && $special && $length);
  106. }
  107. // Object methods
  108. /**
  109. * @return bool
  110. */
  111. public function hasValidPaymentMethod(): bool {
  112. switch($this->preferred_payment_method) {
  113. case User::PAYMENT_METHOD_BANK_TRANSFER: {
  114. if(empty($this->bank_name)) return false;
  115. if(empty($this->bank_sort_code)) return false;
  116. if(empty($this->bank_account_number)) return false;
  117. break;
  118. }
  119. case User::PAYMENT_METHOD_PAYPAL: {
  120. if(empty($this->paypal_email)) return false;
  121. break;
  122. }
  123. }
  124. return true;
  125. }
  126. /**
  127. * @return bool
  128. * @throws Exception
  129. */
  130. public function sendActivationEmail() {
  131. $this->verify_token = bin2hex(random_bytes(16));
  132. $this->commit();
  133. // Content
  134. $name = htmlspecialchars($this->first_name);
  135. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/verify-email/" . $this->verify_token);
  136. // Build
  137. $builder = new EmailBuilder;
  138. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  139. $builder->addLeadParagraph(__("Thanks for registering!"));
  140. $builder->addParagraph(sprintf(__("Welcome to %s! Before you can log in, you will need to verify your email address. You can do so by tapping the following link:"), APP_NAME));
  141. $builder->addParagraph("<a href=\"$link\">$link</a>");
  142. $content = $builder->build();
  143. // Send
  144. $mail = new Email;
  145. $mail->setHtmlContent($content);
  146. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  147. $mail->addAddress($this->email, $this->getDisplayName());
  148. $mail->setSubject(__("Verify your email address"));
  149. $mail->send();
  150. return true;
  151. }
  152. /**
  153. * @return bool
  154. * @throws Exception
  155. */
  156. public function sendWelcomeEmail() {
  157. // Content
  158. $name = htmlspecialchars($this->first_name);
  159. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/account/submit-id");
  160. // Build
  161. $builder = new EmailBuilder;
  162. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  163. $builder->addLeadParagraph(__("Thanks for verifying your email address!"));
  164. $builder->addParagraph(sprintf(__("Welcome to %s! Before you can take part in tests, you will need to provide us with some ID. You can do so by tapping the following link:"), APP_NAME));
  165. $builder->addParagraph("<a href=\"$link\">$link</a>");
  166. $content = $builder->build();
  167. // Send
  168. $mail = new Email;
  169. $mail->setHtmlContent($content);
  170. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  171. $mail->addAddress($this->email, $this->getDisplayName());
  172. $mail->setSubject(sprintf(__("Welcome to %s"), APP_NAME));
  173. $mail->send();
  174. return true;
  175. }
  176. /**
  177. * @return bool
  178. * @throws Exception
  179. */
  180. public function sendIDPassEmail() {
  181. // Content
  182. $name = htmlspecialchars($this->first_name);
  183. // Build
  184. $builder = new EmailBuilder;
  185. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  186. $builder->addLeadParagraph(__("Your application has been successful!"));
  187. $builder->addParagraph(sprintf(__("Welcome to %s! In order to get you a test as soon as possible, we need one final confirmation. Please log in to your account and have a quick read of the documents that explain what we need you to do during a test."), APP_NAME));
  188. $builder->addParagraph(__("When you're ready to try a Practice test, in your account and select the \"Practice\" option."));
  189. $builder->addParagraph(__("1. As it is a Practice test, you can reset and start over as many times as you like because it doesn't count but lets you see what the real thing is like."));
  190. $builder->addParagraph(sprintf(__("2. Email us at %s and let us know that you're ready."), "contact@" . DOMAIN));
  191. $builder->addParagraph(__("3. We will allocate a test to you as soon as possible."));
  192. $builder->addParagraph(__("Remember to check your online account for when tests become available."));
  193. $builder->addParagraph(__("Keep an eye out for emails inviting you to accept a test via the email or log in to your account where you can see your available tests."));
  194. $builder->addParagraph(__("If you accept to do a test within the agreed period (usually 7 days) please click Accept to confirm that you would like to do the test within the agreed period."));
  195. $builder->addParagraph(__("If you can't make it (it's too far or you'll be away), please Reject the test or email us with other suitable dates."));
  196. $builder->addParagraph(__("After you click Accept, you will be given the option to Begin the test whenever you want. Just log in to your account and click Begin on the test."));
  197. $builder->addParagraph(sprintf(__("Once again welcome to %s - Accept, Begin, Complete and get paid for up to 8 minutes work!"), APP_NAME));
  198. $content = $builder->build();
  199. // Send
  200. $mail = new Email;
  201. $mail->setHtmlContent($content);
  202. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  203. $mail->addAddress($this->email, $this->getDisplayName());
  204. $mail->setSubject(__("ID accepted and verified"));
  205. $mail->send();
  206. return true;
  207. }
  208. /**
  209. * @param string $reason
  210. * @return bool
  211. * @throws Exception
  212. */
  213. public function sendIDFailEmail($reason = "No reason given.") {
  214. // Content
  215. $name = htmlspecialchars($this->first_name);
  216. $reason = htmlspecialchars($reason);
  217. // Build
  218. $builder = new EmailBuilder;
  219. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  220. $builder->addLeadParagraph(__("Thank you for submitting your ID details."));
  221. $builder->addParagraph(__("Unfortunately we could not verify and accept your documents and/or image."));
  222. $builder->addParagraph(sprintf(__("The reason for this is: %s"), $reason));
  223. $builder->addParagraph(__("Please log in again, resubmit and we will try again."));
  224. $builder->addParagraph(__("We look forward to welcoming you onboard soon!"));
  225. $content = $builder->build();
  226. // Send
  227. $mail = new Email;
  228. $mail->setHtmlContent($content);
  229. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  230. $mail->addAddress($this->email, $this->getDisplayName());
  231. $mail->setSubject(__("We could not verify your ID details"));
  232. $mail->send();
  233. return true;
  234. }
  235. /**
  236. * @return bool
  237. * @throws Exception
  238. */
  239. public function sendPasswordResetEmail() {
  240. $this->reset_token = bin2hex(random_bytes(16));
  241. $this->commit();
  242. // Content
  243. $name = htmlspecialchars($this->first_name);
  244. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/reset-password/" . $this->reset_token);
  245. // Build
  246. $builder = new EmailBuilder;
  247. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  248. $builder->addLeadParagraph(__("A reset password request has been received."));
  249. $builder->addParagraph(__("To reset your password, please tap on the following link:"));
  250. $builder->addParagraph("<a href=\"$link\">$link</a>");
  251. $builder->addParagraph(sprintf(__("If you %sdid not%s request for your password to be reset, please ignore this email."), '<strong>', '</strong>'));
  252. $content = $builder->build();
  253. // Send
  254. $mail = new Email;
  255. $mail->setHtmlContent($content);
  256. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  257. $mail->addAddress($this->email, $this->getDisplayName());
  258. $mail->setSubject(__("Password reset instructions"));
  259. $mail->send();
  260. return true;
  261. }
  262. /**
  263. * @return bool
  264. * @throws Exception
  265. */
  266. public function sendDocumentationEmail(): bool {
  267. // Content
  268. $name = htmlspecialchars($this->first_name);
  269. // Build
  270. $builder = new EmailBuilder;
  271. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  272. $builder->addLeadParagraph(__("Thanks for registering with us!"));
  273. $builder->addParagraph(__("The good news is that we have tests for you straight away."));
  274. $builder->addParagraph(__("We are testing if you are asked for ID in a pubs and also in amusement arcades before playing a slot machine. I have attached two documents with the test protocol for you to read and we will assign you the tests. Take a look at the protocol and let us know when you are ready."));
  275. $content = $builder->build();
  276. // Send
  277. $mail = new Email;
  278. $mail->setHtmlContent($content);
  279. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  280. $mail->addAddress($this->email, $this->getDisplayName());
  281. $mail->addAttachment("public/files/testing_procedure_arcades.pdf", "Testing Procedure - Arcades.pdf");
  282. $mail->addAttachment("public/files/testing_procedure_pubs.pdf", "Testing Procedure - Pubs.pdf");
  283. $mail->setSubject(__("Documentation"));
  284. return $mail->send();
  285. }
  286. /**
  287. * @return bool
  288. */
  289. public function canAdmin() {
  290. return $this->isAdmin();
  291. }
  292. /**
  293. * @return User|null
  294. * @throws Exception
  295. */
  296. public function getReferrer(): ?User {
  297. return is_null($this->referrer_id) ? null : User::get($this->referrer_id);
  298. }
  299. public function getDirectory() {
  300. $directory = ROOT_DIR . "/files/users/" . $this->id;
  301. if(!file_exists($directory)) mkdir($directory, 0777, true);
  302. return $directory;
  303. }
  304. public function getLevelText() {
  305. return User::LEVELS[$this->level];
  306. }
  307. public function getLevelClass() {
  308. switch($this->level) {
  309. case User::LEVEL_BANNED: return "danger";
  310. case User::LEVEL_REGISTERED: return "secondary";
  311. case User::LEVEL_UNVERIFIED: return "warning";
  312. case User::LEVEL_DEACTIVATED: return "secondary";
  313. case User::LEVEL_TESTER: return "success";
  314. case User::LEVEL_VENUE: return "info";
  315. case User::LEVEL_CUSTOMER: return "info";
  316. case User::LEVEL_ADMIN: return "info";
  317. case User::LEVEL_SUPERADMIN: return "info";
  318. default:
  319. return "primary";
  320. }
  321. }
  322. public function isTesterManager(): bool {
  323. return $this->level >= User::LEVEL_TESTER_MANAGER;
  324. }
  325. public function isAdmin(): bool {
  326. return $this->level >= User::LEVEL_ADMIN;
  327. }
  328. public function isCustomer(): bool {
  329. return $this->level == User::LEVEL_CUSTOMER;
  330. }
  331. public function isTester(): bool {
  332. return $this->level == User::LEVEL_TESTER;
  333. }
  334. public function isDeactivated(): bool {
  335. return $this->level == User::LEVEL_DEACTIVATED;
  336. }
  337. public function getGenderText(): string {
  338. if($this->gender == "M") return MALE;
  339. if($this->gender == "F") return FEMALE;
  340. return "Unspecified";
  341. }
  342. /**
  343. * @return int|string
  344. * @throws Exception
  345. */
  346. public function getAge() {
  347. if(is_null($this->date_of_birth)) return __("N/A");
  348. $now = new DateTime("now");
  349. $dob = new DateTime($this->date_of_birth);
  350. return $dob->diff($now)->y;
  351. }
  352. public function getDisplayName() {
  353. if(empty($this->email)) return __("Deleted User");
  354. $parts = array_filter([$this->first_name, $this->last_name]);
  355. return implode(" ", $parts);
  356. }
  357. /**
  358. * @param $object
  359. * @return bool
  360. * @throws Exception
  361. */
  362. public function hasPermission($object): bool {
  363. if($this->canAccessLocations()) return true;
  364. $customers = $this->getCustomers();
  365. $customer_ids = array_column($customers, "id");
  366. if($object instanceof Customer) {
  367. return in_array($object->id, $customer_ids);
  368. }
  369. if($object instanceof Location) {
  370. return in_array($object->customer_id, $customer_ids);
  371. }
  372. if($object instanceof Project) {
  373. return in_array($object->customer_id, $customer_ids);
  374. }
  375. if($object instanceof Template) {
  376. return in_array($object->customer_id, $customer_ids);
  377. }
  378. return false;
  379. }
  380. /**
  381. * @return bool
  382. * @throws Exception
  383. */
  384. public function deactivate() {
  385. // Decline all pending tests
  386. $pending_tests = $this->getPendingTests();
  387. foreach($pending_tests as $test) {
  388. $test->decline();
  389. }
  390. // Set user level to Deactivated
  391. $this->level = User::LEVEL_DEACTIVATED;
  392. return $this->commit();
  393. }
  394. /**
  395. * @return bool
  396. * @throws Exception
  397. */
  398. public function softDelete(): bool {
  399. // Delete identification documents
  400. $this->deleteIDFiles();
  401. // Delete addresses
  402. $this->deleteAddresses();
  403. // Decline all pending tests
  404. $pending_tests = $this->getPendingTests();
  405. foreach($pending_tests as $test) {
  406. $test->decline();
  407. }
  408. // Delete personal information
  409. $this->email = null;
  410. $this->title = null;
  411. $this->first_name = null;
  412. $this->last_name = null;
  413. $this->phone = null;
  414. $this->bank_name = null;
  415. $this->bank_sort_code = null;
  416. $this->bank_account_number = null;
  417. $this->paypal_email = null;
  418. // Set deleted time
  419. $this->dts_deleted = Util::getDateTime();
  420. return $this->commit();
  421. }
  422. /**
  423. * @return bool
  424. * @throws Exception
  425. */
  426. public function deleteIDFiles(): bool {
  427. $files = UserFile::query([
  428. "user_id" => $this->id,
  429. "type" => [UserFile::TYPE_ID, UserFile::TYPE_PHOTO]
  430. ]);
  431. foreach($files as $file) {
  432. $path = $this->getDirectory() . "/" . $file->id . ".jpg";
  433. if(file_exists($path)) unlink($path);
  434. $file->delete();
  435. }
  436. return true;
  437. }
  438. /**
  439. * @return bool
  440. * @throws Exception
  441. */
  442. public function deleteAddresses(): bool {
  443. $addresses = $this->getAddresses();
  444. foreach($addresses as $address) {
  445. $address->delete();
  446. }
  447. return true;
  448. }
  449. /**
  450. * @return UserAddress[]
  451. * @throws Exception
  452. */
  453. public function getAddresses(): array {
  454. $addresses = UserAddress::query([
  455. "user_id" => $this->id,
  456. ], [
  457. "sort" => "name"
  458. ]);
  459. return $addresses;
  460. }
  461. /**
  462. * @return UserAddress|null
  463. * @throws Exception
  464. */
  465. public function getInvoiceAddress(): ?UserAddress {
  466. $addresses = UserAddress::query([
  467. "user_id" => $this->id,
  468. ]);
  469. foreach($addresses as $address) {
  470. if($address->invoice) return $address;
  471. }
  472. // If only one address in account, just return it
  473. if(count($addresses) == 1) return array_shift($addresses);
  474. return null;
  475. }
  476. /**
  477. * @return Customer[]
  478. * @throws Exception
  479. */
  480. public function getCustomers() {
  481. if($this->canAccessCustomers()) {
  482. return Customer::query([], ["sort" => "name"]);
  483. }
  484. if($this->isCustomer()) {
  485. $links = UserCustomer::query(["user_id" => $this->id]);
  486. return Customer::query([
  487. "id" => array_column($links, "customer_id")
  488. ], ["sort" => "name"]);
  489. }
  490. return [];
  491. }
  492. /**
  493. * @return Test[]
  494. * @throws Exception
  495. */
  496. public function getPendingTests(): array {
  497. return Test::query([
  498. "tester_id" => $this->id,
  499. "status" => [Test::STATUS_ASSIGNED, Test::STATUS_CONFIRMED, Test::STATUS_STARTED, Test::STATUS_PENDING_VERIFICATION],
  500. ], [
  501. "sort" => "dts_assigned",
  502. "order" => "desc"
  503. ]);
  504. }
  505. /**
  506. * @return Test[]
  507. * @throws Exception
  508. */
  509. public function getCompletedTests(): array {
  510. return Test::query([
  511. "tester_id" => $this->id,
  512. "status" => [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED],
  513. ], [
  514. "sort" => "dts_start",
  515. "order" => "desc"
  516. ]);
  517. }
  518. /**
  519. * @return User[]
  520. * @throws Exception
  521. */
  522. public function getReferrals(): array {
  523. return User::query([
  524. "referrer_id" => $this->id
  525. ]);
  526. }
  527. /**
  528. * @return string
  529. */
  530. public function getPreferredPaymentMethodText(): string {
  531. return User::PAYMENT_METHODS[$this->preferred_payment_method];
  532. }
  533. /**
  534. * @return string
  535. */
  536. public function getURL(): string {
  537. return "/account/users/{$this->id}";
  538. }
  539. public function isUnverified() {
  540. return $this->level == User::LEVEL_UNVERIFIED;
  541. }
  542. public function isRegistered() {
  543. return $this->level == User::LEVEL_REGISTERED;
  544. }
  545. public function isSuperAdmin(): bool {
  546. return $this->level == User::LEVEL_SUPERADMIN;
  547. }
  548. public function canAccessCustomers(): bool {
  549. return $this->level >= User::LEVEL_TESTER_MANAGER;
  550. }
  551. public function canAccessMapOverview(): bool {
  552. return $this->level >= User::LEVEL_TESTER_MANAGER;
  553. }
  554. public function canAccessUsers(): bool {
  555. return $this->level >= User::LEVEL_TESTER_MANAGER;
  556. }
  557. public function canAccessProjects(): bool {
  558. return $this->level >= User::LEVEL_TESTER_MANAGER;
  559. }
  560. public function canAccessTemplates(): bool {
  561. return $this->level >= User::LEVEL_ADMIN;
  562. }
  563. public function canAccessVenueTypes(): bool {
  564. return $this->level >= User::LEVEL_ADMIN;
  565. }
  566. public function canAccessInvoices(): bool {
  567. return $this->level >= User::LEVEL_ADMIN;
  568. }
  569. public function canAccessLog(): bool {
  570. return $this->level >= User::LEVEL_ADMIN;
  571. }
  572. public function canAccessLocations(): bool {
  573. return $this->level >= User::LEVEL_CUSTOMER;
  574. }
  575. public function canAccessReports(): bool {
  576. return $this->level >= User::LEVEL_CUSTOMER;
  577. }
  578. public function canAccessTestResults(): bool {
  579. return $this->level >= User::LEVEL_CUSTOMER;
  580. }
  581. public function canAccessTests(): bool {
  582. return $this->isTester() || $this->isTesterManager();
  583. }
  584. public function canAccessPractice(): bool {
  585. return $this->isTester() || $this->isAdmin() || $this->isUnverified() || $this->isRegistered();
  586. }
  587. public function canAccessAddresses(): bool {
  588. return $this->level == User::LEVEL_TESTER;
  589. }
  590. public function canAccessCompletedTests(): bool {
  591. return $this->level == User::LEVEL_TESTER;
  592. }
  593. public function canSubmitId(): bool {
  594. return $this->level == User::LEVEL_REGISTERED;
  595. }
  596. public function canDeactivate(): bool {
  597. return $this->level == User::LEVEL_TESTER;
  598. }
  599. public function canReactivate(): bool {
  600. return $this->level == User::LEVEL_DEACTIVATED;
  601. }
  602. public function canAccessAdminTestsList(): bool {
  603. return $this->isTesterManager();
  604. }
  605. public function canExportProjectCsv(): bool {
  606. return $this->isAdmin();
  607. }
  608. public function canVerifyTests(): bool {
  609. return $this->level >= User::LEVEL_TESTER_MANAGER;
  610. }
  611. public function canAccessTestResult(): bool {
  612. return $this->level >= User::LEVEL_VENUE;
  613. }
  614. public function canEditUsers(): bool {
  615. return $this->isTesterManager();
  616. }
  617. public function canSeeMissingData(): bool {
  618. return $this->level >= self::LEVEL_CUSTOMER;
  619. }
  620. public function getDateTimeDateOfBirth(): ?CarbonImmutable {
  621. if(!$this->date_of_birth) return null;
  622. return CarbonImmutable::parse($this->date_of_birth);
  623. }
  624. }