Example #1
0
 private function getValueForDB($value)
 {
     $property = $this->property;
     if ($property['TYPE'] == 'FILE') {
         $value = Input\File::asMultiple($value);
         foreach ($value as $i => $file) {
             if (Input\File::isDeletedSingle($file)) {
                 unset($value[$i]);
             } else {
                 if (Input\File::isUploadedSingle($file) && ($fileId = \CFile::SaveFile(array('MODULE_ID' => 'sale') + $file, 'sale/order/properties')) && is_numeric($fileId)) {
                     $file = $fileId;
                 }
                 $value[$i] = Input\File::loadInfoSingle($file);
             }
         }
         $this->fields->set('VALUE', $value);
         $value = Input\File::getValue($property, $value);
         foreach (array_diff(Input\File::asMultiple(Input\File::getValue($property, $this->savedValue)), Input\File::asMultiple($value), Input\File::asMultiple(Input\File::getValue($property, $property['DEFAULT_VALUE']))) as $fileId) {
             \CFile::Delete($fileId);
         }
     }
     return $value;
 }
 }
 // insert/update database
 if (!$errors && ($_POST['save'] || $_POST['apply']) && $saleModulePermissions == 'W' && check_bitrix_sessid()) {
     // save uploaded files
     if ($property['TYPE'] == 'FILE') {
         $savedFiles = array();
         $files = Input\File::asMultiple($property['DEFAULT_VALUE']);
         foreach ($files as $i => $file) {
             if (Input\File::isDeletedSingle($file)) {
                 unset($files[$i]);
             } else {
                 if (Input\File::isUploadedSingle($file) && ($fileId = \CFile::SaveFile(array('MODULE_ID' => 'sale') + $file, 'sale/order/properties/default')) && is_numeric($fileId)) {
                     $file = $fileId;
                     $savedFiles[] = $fileId;
                 }
                 $files[$i] = Input\File::loadInfoSingle($file);
             }
         }
         $property['DEFAULT_VALUE'] = $files;
     }
     // prepare property for database & set defaults
     $propertyForDB = array();
     foreach ($commonSettings + $inputSettings + $stringSettings + $locationSettings as $name => $input) {
         $propertyForDB[$name] = Input\Manager::getValue($input, $property[$name]);
     }
     $propertyForDB['SETTINGS'] = array_intersect_key($propertyForDB, $inputSettings);
     $propertyForDB = array_diff_key($propertyForDB, $propertyForDB['SETTINGS']);
     // 1. update property
     if ($propertyId) {
         $update = OrderPropsTable::update($propertyId, array_diff_key($propertyForDB, array('ID' => 1)));
         if ($update->isSuccess()) {