1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Icybee\Modules\Users\Roles;
13
14 use ICanBoogie\ActiveRecord;
15
16 use Icybee\Modules\Users\User;
17
18 class Hooks
19 {
20 /**
21 * Resolves a user permission according to the roles managed by the module.
22 *
23 * @param User $user
24 * @param string $permission
25 * @param string $target
26 *
27 * @return mixed The resolved permission
28 */
29 static public function resolve_user_permission(User $user, $permission, $target=null)
30 {
31 return $user->role->has_permission($permission, $target);
32 }
33
34 /**
35 * Resolves the user ownership.
36 *
37 * @param ActiveRecord $record
38 *
39 * @return boolean `true` if the user has the ownership of the record.
40 */
41 static public function resolve_user_ownership(User $user, ActiveRecord $record)
42 {
43 $module = $record->model_id; // TODO-20140223: implement a better module resolver
44
45 if (Module::PERMISSION_ADMINISTER == $user->has_permission(Module::PERMISSION_MAINTAIN, $module))
46 {
47 return true;
48 }
49 }
50 }