Exemple #1
0
 public function save(array $properties, $key = null, array $options = [])
 {
     global $core;
     if (!$key && empty($properties[User::PASSWORD])) {
         $properties[User::PASSWORD] = md5(uniqid());
     }
     #
     # If defined, the password is encrypted before we pass it to our super class.
     #
     unset($properties[User::PASSWORD_HASH]);
     if (!empty($properties[User::PASSWORD])) {
         $properties[User::PASSWORD_HASH] = User::hash_password($properties[User::PASSWORD]);
     }
     $rc = parent::save($properties, $key, $options);
     #
     # roles
     #
     if (isset($properties[User::ROLES])) {
         $has_many_roles = $core->models['users/has_many_roles'];
         if ($key) {
             $has_many_roles->filter_by_uid($key)->delete();
         }
         foreach ($properties[User::ROLES] as $rid) {
             if ($rid == 2) {
                 continue;
             }
             $has_many_roles->execute('INSERT {self} SET uid = ?, rid = ?', [$rc, $rid]);
         }
     }
     #
     # sites
     #
     if (isset($properties[User::RESTRICTED_SITES])) {
         $has_many_sites = $core->models['users/has_many_sites'];
         if ($key) {
             $has_many_sites->filter_by_uid($key)->delete();
         }
         foreach ($properties[User::RESTRICTED_SITES] as $siteid) {
             $has_many_sites->execute('INSERT {self} SET uid = ?, siteid = ?', [$rc, $siteid]);
         }
     }
     return $rc;
 }
Exemple #2
0
 /**
  * If the {@link Node::$updated_at} property is not defined it is set to the current datetime.
  *
  * If the {@link Node::$slug} property is empty but the {@link Node::$title} property is
  * defined its value is used.
  *
  * The {@link Node:$slug} property is always slugized.
  */
 public function save(array $properties, $key = null, array $options = [])
 {
     global $core;
     if (!$key) {
         if (!array_key_exists(Node::UID, $properties)) {
             $properties[Node::UID] = $core->user_id;
         }
         if (empty($properties[Node::UUID])) {
             $properties[Node::UUID] = $this->obtain_uuid();
         }
     }
     if (empty($properties[Node::SLUG]) && isset($properties[Node::TITLE])) {
         $properties[Node::SLUG] = $properties[Node::TITLE];
     }
     if (isset($properties[Node::SLUG])) {
         $properties[Node::SLUG] = slugize($properties[Node::SLUG], isset($properties[Node::LANGUAGE]) ? $properties[Node::LANGUAGE] : null);
     }
     return parent::save($properties, $key, $options);
 }