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\Exception;
15 use ICanBoogie\I18n;
16
17 /**
18 * Primary model of the Roles module (users.roles).
19 */
20 class Model extends \ICanBoogie\ActiveRecord\Model
21 {
22 /**
23 * If defined, the property {@link Role::PERMS} is serialized using the {@link json_encode()}
24 * function to set the property {@link Role::SERIALIZED_PERMS}.
25 */
26 public function save(array $properties, $key=null, array $options=array())
27 {
28 if (isset($properties[Role::PERMS]))
29 {
30 $properties[Role::SERIALIZED_PERMS] = json_encode($properties[Role::PERMS]);
31 }
32
33 return parent::save($properties, $key, $options);
34 }
35
36 /**
37 * @throws Exception when on tries to delete the role with identifier "1".
38 */
39 public function delete($rid)
40 {
41 if ($rid == 1)
42 {
43 throw new Exception('The role %role (%rid) cannot be deleted.', array('%role' => I18n\t('Visitor'), '%rid' => $rid));
44 }
45
46 // FIXME-20110709: deleted role is not removed from users records.
47
48 return parent::delete($rid);
49 }
50 }
51