PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Models / User.php

User.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.3, at app/Models/User.php

62 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Models;
4
5
6 use FluentCart\App\Services\Permission\PermissionManager;
7
8 class User extends Model
9 {
10 protected $table = 'users';
11
12 /**
13 * The primary key for the model.
14 *
15 * @var string
16 */
17 protected $primaryKey = 'ID';
18
19 protected $guarded = ['password'];
20
21
22 /**
23 * Check if the user has a specific permission.
24 * @param string|array $permission
25 * @return bool
26 */
27 public function userCan($permission): bool
28 {
29 return PermissionManager::hasPermission($permission, $this->ID);
30 }
31
32 /**
33 * Check if the user has a specific permission.
34 * @param string|array $permission
35 * @return bool
36 */
37 public function userCanAny($permission): bool
38 {
39 return PermissionManager::hasAnyPermission($permission, $this->ID);
40 }
41
42 /**
43 * @todo: Move this to Pro Plugin's Controller
44 */
45 public function setStoreRole($role)
46 {
47 $wpUser = get_user_by('ID', $this->ID);
48
49 if (user_can($wpUser, 'manage_options')) {
50 return new \WP_Error('super_admin', __('The user already have all the accesses as part of Administrator Role', 'fluent-cart'));
51 }
52
53 return update_user_meta($this->ID, '_fluent_cart_admin_role', $role);
54 }
55
56 public function customer(): \FluentCart\Framework\Database\Orm\Relations\HasOne
57 {
58 return $this->hasOne(Customer::class, 'user_id');
59 }
60
61 }
62