Index: branches/5.3.x/core/units/helpers/file_helper.php =================================================================== diff -u -N -r15677 -r15698 --- branches/5.3.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 15677) +++ branches/5.3.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 15698) @@ -1,6 +1,6 @@ Application->getUnitOption('#file', 'TableName'); - $max_file_count = $this->Application->getUnitOption($object->Prefix, 'FileCount'); // $this->Application->ConfigValue($object->Prefix.'_MaxImageCount'); + $table_name = $this->Application->getUnitConfig('#file')->getTableName(); + $max_file_count = $object->getUnitConfig()->getFileCount(); +// $max_file_count = $this->Application->ConfigValue($object->Prefix . '_MaxImageCount'); $this->CheckFolder(FULL_PATH . ITEM_FILES_PATH); @@ -159,13 +160,9 @@ */ public function createUploadFields($prefix, $fields_values, $is_image = false) { - $field_options = Array ( - 'type' => 'string', - 'max_len' => 240, - 'default' => '', - ); + $field_options = Array ('type' => 'string', 'max_len' => 240, 'default' => '',); - if ($is_image) { + if ( $is_image ) { $field_options['formatter'] = 'kPictureFormatter'; $field_options['include_path'] = 1; $field_options['allowed_types'] = Array ('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', 'image/bmp'); @@ -178,29 +175,28 @@ $field_prefix = 'File'; } - $fields = $this->Application->getUnitOption($prefix, 'Fields'); - $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields'); - $image_count = 0; + $config = $this->Application->getUnitConfig($prefix); + foreach ($fields_values as $field_name => $field_value) { - if (preg_match('/^('.$field_prefix.'[\d]+|Primary'.$field_prefix.')$/', $field_name)) { - $fields[$field_name] = $field_options; - $virtual_fields[$field_name] = $field_options; - $this->_createCustomFields($prefix, $field_name, $virtual_fields, $is_image); + if ( preg_match('/^(' . $field_prefix . '[\d]+|Primary' . $field_prefix . ')$/', $field_name) ) { + $config->addFields($field_options, $field_name); + $config->addVirtualFields($field_options, $field_name); + $this->_createCustomFields($prefix, $field_name, $config, $is_image); $image_count++; } } - if (!$image_count) { + if ( !$image_count ) { // no images found in POST -> create default image fields - $image_count = $this->Application->ConfigValue($prefix.'_MaxImageCount'); + $image_count = $this->Application->ConfigValue($prefix . '_MaxImageCount'); - if ($is_image) { + if ( $is_image ) { $created_count = 1; $image_names = Array ('Primary' . $field_prefix => ''); - while ($created_count < $image_count) { + while ( $created_count < $image_count ) { $image_names[$field_prefix . $created_count] = ''; $created_count++; } @@ -209,40 +205,38 @@ $created_count = 0; $image_names = Array (); - while ($created_count < $image_count) { + while ( $created_count < $image_count ) { $image_names[$field_prefix . ($created_count + 1)] = ''; $created_count++; } } - if ($created_count) { + if ( $created_count ) { $this->createUploadFields($prefix, $image_names, $is_image); } - return ; + return; } - $this->Application->setUnitOption($prefix, $field_prefix.'Count', $image_count); - $this->Application->setUnitOption($prefix, 'Fields', $fields); - $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields); + $config->setSetting($field_prefix . 'Count', $image_count); } /** * Adds ability to create more virtual fields associated with main image/file * * @param string $prefix * @param string $field_name - * @param Array $virtual_fields + * @param kUnitConfig $config * @param bool $is_image * @return void * @access protected */ - protected function _createCustomFields($prefix, $field_name, &$virtual_fields, $is_image = false) + protected function _createCustomFields($prefix, $field_name, kUnitConfig $config, $is_image = false) { - $virtual_fields['Delete' . $field_name] = Array ('type' => 'int', 'default' => 0); + $config->addVirtualFields(Array ('type' => 'int', 'default' => 0), 'Delete' . $field_name); if ( $is_image ) { - $virtual_fields[$field_name . 'Alt'] = Array ('type' => 'string', 'default' => ''); + $config->addVirtualFields(Array ('type' => 'string', 'default' => ''), $field_name . 'Alt'); } }