Example #1
0
 public function fn_syncfromwp($location, $params = array())
 {
     if (!$this->checkPermission(__FUNCTION__)) {
         return false;
     }
     //remove all
     QdUser::delete_all();
     //copy all from WP
     $users = get_users();
     $count = 0;
     foreach ($users as $user) {
         $tmp = new QdUser();
         $tmp->id = $user->ID;
         $tmp->username = $user->user_login;
         $tmp->displayname = $user->display_name;
         $tmp->status = $user->user_status;
         $tmp->email = $user->user_email;
         $location .= sprintf('|%s|%s', $this->getCalledClassName(), 'fn_syncfromwp');
         if ($tmp->save($location)) {
             $count++;
         }
     }
     $this->pushValidateError('', 'Total Users: ' . $count, 'info');
     return $count > 0;
 }
 protected function usergroupidOnValidate($field_name)
 {
     $u = QdUser::GET(get_current_user_id());
     if ($u != null) {
         $g = $u->getUserGroupObj();
         if ($g != null) {
             if ($g->id == $this->{$field_name}) {
                 $this->pushValidateError($field_name, 'You can not set Permission by your self!', 'error');
             }
         }
     }
 }
 protected function useridOnValidate($field_name)
 {
     $u = QdUser::GET($this->{$field_name});
     $c = new QdUserPersonalization();
     $c->SETRANGE('userid', $this->{$field_name});
     $c = $c->GETLIST();
     $c = empty($c) ? null : $c[0];
     if ($u == null) {
         $this->pushValidateError($field_name, $field_name . ' không tồn tại trong QdUser', 'error');
     } else {
         if ($this->is_new_record() && $c != null || $c != null && $c->id != $this->id) {
             $this->pushValidateError('userid', 'UserID đã tồn tại trong bảng', 'error');
             return false;
         }
         $this->username = $u->username;
         $this->pushValidateError('username', 'UserName tự động gán từ QdUser', 'info');
     }
 }
Example #4
0
 public static function getCurrentUser()
 {
     $key = static::getUserCacheKey();
     $obj = get_transient($key);
     if ($obj == null) {
         $obj = QdUser::GET(get_current_user_id());
         $obj->getPermissions();
         set_transient($key, $obj);
     }
     return $obj;
 }