public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     $cg = $this->_getCommercialGroup($value, 'id');
     if ($cg === false) {
         return false;
     }
     if ($cg === NULL) {
         $this->_error(self::ERROR_COMMERCIAL_GROUP_NOT_EXISTS, $value);
         return false;
     }
     if ($this->getCheckRestrictions()) {
         $restricted = $cg->restricted;
         switch (\App::getOrgUserLogged()->getType()) {
             case OrgCustomerModel::ORG_TYPE:
                 if ($restricted) {
                     $this->_error(self::ERROR_COMMERCIAL_GROUP_RESTRICTED, $value);
                     return false;
                 }
         }
     }
     return true;
 }
 public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     if ($value == BusinessRule::CHANGE_COMMERCIAL_GROUP) {
         $type = App_Util_Array::getItem($context, '__parent.__parent.universeType');
         if ($type == AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP || $type == AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP) {
             $universeId = App_Util_Array::getItem($context, '__parent.__parent.universeId');
             $cg = $this->_getCommercialGroup($universeId, 'id');
             if ($cg === NULL) {
                 $this->_error(self::ERROR_COMMERCIAL_GROUP_NOT_EXISTS, $universeId);
                 return false;
             }
             $restricted = $cg->restricted;
             switch (\App::getOrgUserLogged()->getType()) {
                 case OrgCustomerModel::ORG_TYPE:
                     if ($restricted) {
                         $mss = "{$type} with commercial group id {$universeId}";
                         $this->_error(self::ERROR_UNIVERSE_TYPE_COMMERCIAL_GROUP_RESTRICTED, $mss);
                         return false;
                     }
             }
         }
     }
     return true;
 }
 public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     $filters = array();
     if (!empty($context['customerId'])) {
         $filters['customerId'] = $context['customerId'];
     }
     $cg = $this->_getCommercialGroup($value, 'name', $filters);
     if ($cg === false) {
         return false;
     }
     if ($cg === NULL) {
         return true;
     }
     if ($context['id'] && $context['id'] === $cg->getId()) {
         return true;
     }
     $this->_error(self::ERROR_COMMERCIAL_GROUP_EXISTS, $value);
     return false;
 }