Exemplo n.º 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;
 }
Exemplo n.º 2
0
 function setValuesFromPost($post, $files)
 {
     $post = Input\File::getPostWithFiles($post, $files);
     $result = new Result();
     /** @var PropertyValue $property */
     foreach ($this->collection as $property) {
         $r = $property->setValueFromPost($post);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     return $result;
 }
Exemplo n.º 3
0
     if ($insert->isSuccess()) {
         $propertyId = $property['ID'] = $insert->getId();
     } else {
         $errors[] = loc::getMessage('ERROR_ADD_PROP') . ': ' . implode(', ', $insert->getErrorMessages());
     }
 }
 // cleanup files
 if ($errors) {
     if (isset($savedFiles)) {
         $filesToDelete = $savedFiles;
     }
 } else {
     if ($existentProperty && $existentProperty['TYPE'] == 'FILE') {
         $filesToDelete = Input\File::asMultiple(Input\File::getValue($existentProperty, $existentProperty['DEFAULT_VALUE']));
         if (isset($files)) {
             $filesToDelete = array_diff($filesToDelete, Input\File::asMultiple(Input\File::getValue($property, $files)));
         }
     }
 }
 if (isset($filesToDelete)) {
     foreach ($filesToDelete as $fileId) {
         if (is_numeric($fileId)) {
             \CFile::Delete($fileId);
         }
     }
 }
 //		$filesToDelete = array();
 //
 //		if ($v = $property['DEFAULT_VALUE'])
 //			$filesToDelete = is_array($v) ? $v : array($v);
 //