Ejemplo n.º 1
0
 public function beforeSave()
 {
     $user =& $this->object;
     if ($this->getProperty('use_captcha') && !$user->SocialProfiles) {
         $this->checkCaptcha();
     }
     $ok = parent::beforeSave();
     if ($ok !== true) {
         return $ok;
     }
     $profile =& $this->profile;
     $profile->fromArray(array("fullname" => $this->getProperty('fullname')));
     // else
     $validator = new modWebSocietyUsersValidator($this);
     $ok = $validator->validate();
     if ($ok !== true) {
         return $ok;
     }
     # print '<pre>';
     // Добавляем сразу все типы уведомлений
     $notices = array();
     foreach ($this->modx->getCollection('SocietyNoticeType', ["active" => '1']) as $noticeType) {
         $notice = $this->modx->newObject('SocietyNoticeUser');
         $notice->NoticeType = $noticeType;
         # print_r($notice->toArray());
         $notices[] = $notice;
     }
     $user->Notices = $notices;
     # print_r($user->toArray());
     #
     # return "Ведутся работы";
     /*
             
             print_r($this->properties);
             
             print $activate_link;
     */
     # return "Debug";
     return true;
 }
Ejemplo n.º 2
0
 public function beforeSave()
 {
     $user =& $this->object;
     $this->profile->fromArray($this->getProperties());
     if ($new_password = trim($this->getProperty('new_password'))) {
         $password_min_length = $this->modx->getOption('password_min_length', null, 6);
         if (mb_strlen($new_password, 'utf-8') < $password_min_length) {
             $error = "Пароль должен быть не менее {$password_min_length} символов";
             $this->addFieldError('new_password', $error);
         } else {
             $user->set('password', $new_password);
         }
     }
     $validator = new modWebSocietyUsersValidator($this);
     $ok = $validator->validate();
     if ($ok !== true) {
         return $ok;
     }
     # print '<pre>';
     #
     # $test = $this->getProperty('dsfsdf', null);
     #
     # if(isset($test)){
     #     print "sdfsf";
     # }
     #
     # print_r($this->getProperties());
     # print_r($extended);
     #
     # exit;
     #
     # // Уведомления
     #
     # if($notices = (array)$this->getProperty('notices')){
     #     foreach($notices as $notice_id){
     #         if($notice = $this->modx->getObject('SocietyNoticeType', $notices)){
     #
     #         }
     #     }
     # }
     if ($notices = (array) $this->getProperty('notices', array())) {
         $notices = array_flip($notices);
     }
     // print_r($notices);
     $userNotices = (array) $user->Notices;
     foreach ($userNotices as &$userNotice) {
         if (array_key_exists($userNotice->notice_id, $notices)) {
             $userNotice->active = 1;
             unset($notices[$userNotice->notice_id]);
         } else {
             $userNotice->active = 0;
         }
         // print_r($userNotice->toArray());
     }
     # print_r($notices);
     foreach ($notices as $notice_id => $val) {
         if ($notice = $this->modx->getObject('SocietyNoticeType', $notice_id)) {
             $newUserNotice = $this->modx->newObject('SocietyNoticeUser', array("active" => 1));
             $newUserNotice->User = $user;
             $newUserNotice->NoticeType = $notice;
             $userNotices[] = $newUserNotice;
             # print_r($newUserNotice->NoticeType->toArray());
             #
             # return;
         }
         # else{
         #     print "Error";
         #     exit;
         # }
     }
     $user->Notices = $userNotices;
     # exit;
     # foreach($userNotices as $userNotice2){
     #     print_r($userNotice2->toArray());
     # }
     # return;
     ####################################
     # return 'Debug';
     return parent::beforeSave();
 }