Пример #1
0
 protected function doSave($con = null)
 {
     parent::doSave($con);
     if ($this->getValue('unlimitedCredit') == true) {
         $this->getObject()->setCredit(null);
         $this->getObject()->save();
     }
 }
 protected function doSave($con = null)
 {
     parent::doSave($con);
     if ($this->getValue('unlimitedCredit') == true) {
         $this->getObject()->setCredit(null);
         $this->getObject()->save();
     }
     $usergroup = $this->getObject()->getUsergroup();
     $zonesId = $this->getValue('Zone_id');
     $activitiesId = $this->getValue('Activity_id');
     foreach ($zonesId as $zoneId) {
         $this->getObject()->setZoneId($zoneId);
         foreach ($activitiesId as $activityId) {
             $this->getObject()->setActivityId($activityId);
             if (!is_null($usergroup)) {
                 $userType = $this->getValue('User_type');
                 $createRule = $this->getValue('Create_rule');
                 switch ($userType) {
                     case self::EVERYBODY:
                         $users = $usergroup->getUsers();
                         break;
                     case self::LEADERS:
                         $users = $usergroup->getLeaders();
                         break;
                     case self::MEMBERS:
                         $users = $usergroup->getMembers();
                         break;
                     case self::NONMEMBERS:
                         $users = $usergroup->getNonMembers();
                         break;
                 }
                 switch ($createRule) {
                     case self::ADD:
                         foreach ($users as $user) {
                             $subscription = $this->getObject()->copy();
                             $subscription->setUser($user);
                             $subscription->save();
                         }
                         break;
                     case self::REPLACE:
                         foreach ($users as $user) {
                             $user->removeSubscriptionForUsergroup($usergroup->getId(), $zoneId, $activityId);
                             $subscription = $this->getObject()->copy();
                             $subscription->setUser($user);
                             $subscription->save();
                         }
                         break;
                     case self::FILL:
                         foreach ($users as $user) {
                             if ($user->countSubscriptionForUsergroup($usergroup->getId(), $zoneId, $activityId) == 0) {
                                 $subscription = $this->getObject()->copy();
                                 $subscription->setUser($user);
                                 $subscription->save();
                             }
                         }
                         break;
                     case self::DELETE:
                         foreach ($users as $user) {
                             $user->removeSubscriptionForUsergroup($usergroup->getId(), $zoneId, $activityId);
                         }
                         break;
                 }
             }
         }
     }
     $this->getObject()->delete();
 }