Beispiel #1
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     if ($result instanceof Entity\AddResult) {
         if (isset($data['REAL_OBJECT_ID']) && isset($data['FILE_ID']) && !empty($data['REAL_OBJECT_ID']) && !empty($data['FILE_ID']) && $data['REAL_OBJECT_ID'] != $data['ID']) {
             $field = static::getEntity()->getField('FILE_ID');
             $result->addError(new FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_LINK_FILE_ID", array("#FIELD#" => $field->getTitle()))));
         }
         if (isset($data['FILE_ID']) && empty($data['REAL_OBJECT_ID']) && empty($data['FILE_ID'])) {
             $field = static::getEntity()->getField('FILE_ID');
             $result->addError(new FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_REQUIRED_FILE_ID", array("#FIELD#" => $field->getTitle()))));
         }
     }
     parent::checkFields($result, $primary, $data);
 }
Beispiel #2
0
 /**
  * @param Order $order
  * @param Payment $payment
  * @param $operation
  * @return Result
  * @throws \Exception
  */
 public static function createOperation(Order &$order, Payment &$payment, $operation)
 {
     $result = new Result();
     $paymentSum = $payment->getSum();
     if ($operation == self::OPERATION_DEBIT) {
         $userBudget = UserBudgetPool::getUserBudgetByOrder($order);
         if ($userBudget >= $paymentSum) {
             UserBudgetPool::addPoolItem($order, $paymentSum * -1, UserBudgetPool::BUDGET_TYPE_ORDER_PAY, $payment);
             //				$payment->setField('PAID', 'Y');
         } else {
             $result->addError(new EntityError(Loc::getMessage('ORDER_PS_INNER_ERROR_INSUFFICIENT_MONEY')));
         }
     } elseif ($operation == self::OPERATION_CREDIT) {
         UserBudgetPool::addPoolItem($order, $paymentSum, UserBudgetPool::BUDGET_TYPE_ORDER_UNPAY, $payment);
         //			$payment->setField('PAID', 'N');
     } elseif ($operation == self::OPERATION_RETURN) {
         $sumPaid = $order->getSumPaid();
         $sumTrans = UserBudgetPool::getUserBudgetTransForOrder($order);
         $finalSumPaid = $paymentSum + $sumTrans;
         if ($finalSumPaid > 0) {
             $paymentSum = $paymentSum - $finalSumPaid;
         }
         //			Internals\UserBudgetPool::addPoolItem($order->getUserId(), ( $paymentSum ), UserBudgetPool::BUDGET_TYPE_CANCEL_RETURN, $order, $payment);
         //			$payment->setField('PAID', 'N');
         $payment->setField('IS_RETURN', 'Y');
     } else {
         throw new InvalidOperationException('Wrong operation type!');
     }
     return $result;
 }
Beispiel #3
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     if ($result instanceof DeleteResult) {
         if (!ObjectPathTable::isLeaf($primary)) {
             $result->addError(new EntityError(Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_DELETE_NODE")));
         }
     }
     parent::checkFields($result, $primary, $data);
 }
Beispiel #4
0
 public function validateValue($value, $primary, $row, Result $result)
 {
     $validators = $this->getValidators();
     foreach ($validators as $validator) {
         if (is_object($validator)) {
             $vResult = $validator->validate($value, $primary, $row, $this);
         } else {
             $vResult = call_user_func_array($validator, array($value, $primary, $row, $this));
         }
         if ($vResult !== true) {
             $result->addError(new FieldError($this, $vResult, FieldError::INVALID_VALUE));
             break;
         }
     }
 }
 /**
  * Check data for create one or more coupons.
  *
  * @param array $data				Coupon data.
  * @param bool $newDiscount			New discount flag.
  * @return Main\Entity\Result
  */
 public static function checkPacket(array $data, $newDiscount = false)
 {
     $result = new Main\Entity\Result();
     $newDiscount = $newDiscount === true;
     if (empty($data) || !is_array($data)) {
         $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_PACKET_EMPTY'), 'COUPON_PACKET'));
     } else {
         if (empty($data['TYPE']) || !in_array((int) $data['TYPE'], self::getCouponTypes(false))) {
             $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_TYPE'), 'COUPON_PACKET'));
         }
         if (!$newDiscount && empty($data['DISCOUNT_ID'])) {
             $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_DISCOUNT_ID'), 'COUPON_PACKET'));
         }
         if (isset($data['ACTIVE_FROM']) && !$data['ACTIVE_FROM'] instanceof Main\Type\DateTime || isset($data['ACTIVE_TO']) && !$data['ACTIVE_TO'] instanceof Main\Type\DateTime) {
             $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_PERIOD'), 'COUPON_PACKET'));
         }
     }
     return $result;
 }
 /**
  * Checks data fields before saving to DB. Result stores in $result object
  *
  * @param Result $result
  * @param array $data
  * @param null $id
  * @throws \Exception
  */
 public static function checkFields(Result $result, $primary, array $data)
 {
     //checks required fields
     foreach (static::getEntity()->getFields() as $field) {
         if ($field instanceof ScalarField && $field->isRequired()) {
             $fieldName = $field->getName();
             if ($id === null && (!isset($data[$fieldName]) || $data[$fieldName] == '') || $id !== null && isset($data[$fieldName]) && $data[$fieldName] == '') {
                 $result->addError(new FieldError($field, getMessage("MAIN_ENTITY_FIELD_REQUIRED", array("#FIELD#" => $field->getTitle())), FieldError::EMPTY_REQUIRED));
             }
         }
     }
     // checks data - fieldname & type & strlen etc.
     foreach ($data as $k => $v) {
         if (static::getEntity()->hasField($k) && static::getEntity()->getField($k) instanceof ScalarField) {
             $field = static::getEntity()->getField($k);
         } elseif (static::getEntity()->hasUField($k)) {
             // should be continue
             // checking is inside uf manager
             $field = static::getEntity()->getUField($k);
         } else {
             throw new \Exception(sprintf('Field `%s` not found in entity when trying to query %s row.', $k, static::getEntity()->getName()));
         }
         $field->validateValue($v, $primary, $data, $result);
     }
 }
Beispiel #7
0
 public static function checkFieldsChain(\Bitrix\Main\Entity\Result $result, $primary = null, array $fields)
 {
     $id = $primary;
     $errorList = array();
     $errorCurrentNumber = 0;
     foreach ($fields as $item) {
         $errorCurrentNumber++;
         $chainFields = array('MAILING_ID' => $id ? $id : 1, 'ID' => $item['ID'], 'REITERATE' => 'Y', 'IS_TRIGGER' => 'Y', 'EMAIL_FROM' => $item['EMAIL_FROM'], 'SUBJECT' => $item['SUBJECT'], 'MESSAGE' => $item['MESSAGE'], 'TIME_SHIFT' => intval($item['TIME_SHIFT']));
         $chainId = 0;
         if (!empty($item['ID'])) {
             $chainId = $item['ID'];
         }
         if ($chainId > 0) {
             $chain = \Bitrix\Sender\MailingChainTable::getRowById(array('ID' => $chainId));
             if ($chain && $chain['STATUS'] != \Bitrix\Sender\MailingChainTable::STATUS_WAIT) {
                 $chainFields['STATUS'] = $chain['STATUS'];
             }
         }
         if (empty($chainFields['STATUS'])) {
             $chainFields['STATUS'] = \Bitrix\Sender\MailingChainTable::STATUS_WAIT;
         }
         $chainFields['ID'] = $chainId;
         $resultItem = new \Bitrix\Main\Entity\Result();
         \Bitrix\Sender\MailingChainTable::checkFields($resultItem, null, $chainFields);
         if ($resultItem->isSuccess()) {
         } else {
             $errorList[$errorCurrentNumber] = $resultItem->getErrors();
         }
     }
     $delimiter = '';
     foreach ($errorList as $number => $errors) {
         /* @var \Bitrix\Main\Entity\FieldError[] $errors*/
         foreach ($errors as $error) {
             $result->addError(new Entity\FieldError($error->getField(), $delimiter . Loc::getMessage('SENDER_ENTITY_MAILING_CHAIN_ITEM_NUMBER') . $number . ': ' . $error->getMessage(), $error->getCode()));
             $delimiter = '';
         }
         $delimiter = "\n";
     }
     return $result;
 }
Beispiel #8
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     if ($result instanceof Entity\UpdateResult) {
         if (isset($data['STORAGE_ID'])) {
             $field = static::getEntity()->getField('STORAGE_ID');
             $result->addError(new Entity\FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_UPDATE_STORAGE_ID", array("#FIELD#" => $field->getTitle()))));
         }
         if (isset($data['PARENT_ID'])) {
             $field = static::getEntity()->getField('PARENT_ID');
             $result->addError(new Entity\FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_UPDATE_PARENT_ID", array("#FIELD#" => $field->getTitle()))));
         }
     }
     if (!empty($data['NAME']) && (!IO\Path::validateFilename($data['NAME']) || strpos($data['NAME'], '%') !== false)) {
         $field = static::getEntity()->getField('NAME');
         $result->addError(new Entity\FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_FIELD_NAME_HAS_INVALID_CHARS", array("#FIELD#" => $field->getTitle()))));
     }
     parent::checkFields($result, $primary, $data);
 }
Beispiel #9
0
 /**
  * @param        $value
  * @param        $primary
  * @param        $row
  * @param Result $result
  *
  * @return Result
  * @throws SystemException
  */
 public function validateValue($value, $primary, $row, Result $result)
 {
     if ($value instanceof SqlExpression) {
         return $result;
     }
     $validators = $this->getValidators();
     foreach ($validators as $validator) {
         if ($validator instanceof IValidator) {
             $vResult = $validator->validate($value, $primary, $row, $this);
         } else {
             $vResult = call_user_func_array($validator, array($value, $primary, $row, $this));
         }
         if ($vResult !== true) {
             if ($vResult instanceof EntityError) {
                 $result->addError($vResult);
             } else {
                 $result->addError(new FieldError($this, $vResult, FieldError::INVALID_VALUE));
             }
         }
     }
     return $result;
 }
Beispiel #10
0
 public static function checkFields(Entity\Result $result, $primary, array $data)
 {
     // check data - fieldname & type & strlen etc.
     foreach ($data as $k => $v) {
         if (!(static::getEntity()->hasField($k) && static::getEntity()->getField($k) instanceof \Bitrix\Main\Entity\ScalarField)) {
             throw new \Exception(sprintf('Field `%s` not found in entity when trying to query %s row.', $k, static::getEntity()->getName()));
         }
     }
     // check by uf manager
     $entityName = static::getEntity()->getName();
     $hlblock = HighloadBlockTable::getList(array('select' => array('ID'), 'filter' => array('=NAME' => $entityName)))->fetch();
     $fields = $GLOBALS['USER_FIELD_MANAGER']->getUserFields('HLBLOCK_' . $hlblock['ID']);
     // dear uf manager, please go f**k yourself and don't touch unchanged files
     foreach ($data as $k => $v) {
         // hide them from him
         $arUserField = $fields[$k];
         if ($arUserField["USER_TYPE"]["BASE_TYPE"] == 'file' && !is_array($v)) {
             //unset($data[$k]);
         }
     }
     if (!$GLOBALS["USER_FIELD_MANAGER"]->checkFields('HLBLOCK_' . $hlblock['ID'], null, $data)) {
         if (is_object($GLOBALS['APPLICATION']) && $GLOBALS['APPLICATION']->getException()) {
             $e = $GLOBALS['APPLICATION']->getException();
             $result->addError(new Entity\EntityError($e->getString()));
             $GLOBALS['APPLICATION']->resetException();
         } else {
             $result->addError(new Entity\EntityError("Unknown error."));
         }
     }
 }
 /**
  * Извлечение данных для связей
  */
 protected function collectReferencesData()
 {
     $result = new Entity\Result();
     $references = $this->getReferences();
     // Извлечение данных управляемых связей
     foreach ($references as $fieldName => $reference) {
         if (array_key_exists($fieldName, $this->data)) {
             if (!is_array($this->data[$fieldName])) {
                 $result->addError(new Entity\EntityError('Связь должна быть множественным полем'));
                 return $result;
             }
             // Извлечение данных для связи
             $this->referencesData[$fieldName] = $this->data[$fieldName];
             unset($this->data[$fieldName]);
         }
     }
     return $result;
 }
Beispiel #12
0
 public static function saveProfileData($profileId, Order $order, array $formData)
 {
     $result = new Result();
     $errors = array();
     if (!($profileName = $order->getPropertyCollection()->getProfileName())) {
         $result->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_PROFILE_ERROR_NAME")));
         return $result;
     }
     $res = \CSaleOrderUserProps::DoSaveUserProfile($order->getUserId(), $profileId, $profileName->getValue(), $order->getPersonTypeId(), $propCollection = $formData["PROPERTIES"], $errors);
     if ($res === false) {
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $result->addError(new EntityError($error . "<br>\n"));
             }
         } else {
             $result->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_PROFILE_ERROR_SAVE")));
         }
     }
     return $result;
 }