Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ActivateOperation
  • AvailableSitesBlock
  • ConfigBlock
  • ConfigOperation
  • DeactivateOperation
  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • IsUniqueOperation
  • LoginComboElement
  • LoginForm
  • LoginOperation
  • LogoutOperation
  • ManageBlock
  • Model
  • Module
  • OwnershipResolver
  • PermissionResolver
  • ProfileController
  • QueryOperationOperation
  • SaveOperation
  • UnlockLoginOperation
  • Update20131021
  • User
  • ViewProvider

Interfaces

  • OwnershipResolverInterface
  • PermissionResolverInterface

Traits

  • LoggedAtProperty

Exceptions

  • WebsiteAdminNotAccessible
 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;
13 
14 use ICanBoogie\DateTime;
15 
16 class Model extends \Icybee\ActiveRecord\Model\Constructor
17 {
18     public function save(array $properties, $key=null, array $options=[])
19     {
20         global $core;
21 
22         if (!$key)
23         {
24             if (empty($properties[User::PASSWORD]))
25             {
26                 $properties[User::PASSWORD] = md5(uniqid());
27             }
28 
29             if (empty($properties[User::CREATED_AT]) || DateTime::from($properties[User::CREATED_AT])->is_empty)
30             {
31                 $properties[User::CREATED_AT] = DateTime::now();
32             }
33         }
34 
35         #
36         # If defined, the password is encrypted before we pass it to our super class.
37         #
38 
39         unset($properties[User::PASSWORD_HASH]);
40 
41         if (!empty($properties[User::PASSWORD]))
42         {
43             $properties[User::PASSWORD_HASH] = User::hash_password($properties[User::PASSWORD]);
44         }
45 
46         $rc = parent::save($properties, $key, $options);
47 
48         #
49         # roles
50         #
51 
52         if (isset($properties[User::ROLES]))
53         {
54             $has_many_roles = $core->models['users/has_many_roles'];
55 
56             if ($key)
57             {
58                 $has_many_roles->filter_by_uid($key)->delete();
59             }
60 
61             foreach ($properties[User::ROLES] as $rid)
62             {
63                 if ($rid == 2)
64                 {
65                     continue;
66                 }
67 
68                 $has_many_roles->execute('INSERT {self} SET uid = ?, rid = ?', [ $rc, $rid ]);
69             }
70         }
71 
72         #
73         # sites
74         #
75 
76         if (isset($properties[User::RESTRICTED_SITES]))
77         {
78             $has_many_sites = $core->models['users/has_many_sites'];
79 
80             if ($key)
81             {
82                 $has_many_sites->filter_by_uid($key)->delete();
83             }
84 
85             foreach ($properties[User::RESTRICTED_SITES] as $siteid)
86             {
87                 $has_many_sites->execute('INSERT {self} SET uid = ?, siteid = ?', [ $rc, $siteid ]);
88             }
89         }
90 
91         return $rc;
92     }
93 }
Autodoc API documentation generated by ApiGen 2.8.0