Index: branches/RC/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r11721 -r11857 --- branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11721) +++ branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11857) @@ -301,8 +301,8 @@ $sql = 'SELECT * FROM '.TABLE_PREFIX.'Images WHERE ResourceId = '.$object->GetDBField('ResourceId').' - ORDER BY ImageId ASC - LIMIT 0, '.(int)$max_image_count; + ORDER BY Priority DESC + LIMIT 0, ' . (int)$max_image_count; $item_images = $this->Conn->Query($sql); $image_counter = 1; @@ -314,14 +314,23 @@ $object->SetDBField('PrimaryImage', $image_path); $object->SetOriginalField('PrimaryImage', $image_path); $object->Fields['PrimaryImage']['original_field'] = $item_image['Name']; + + $this->_loadCustomFields($object, $item_image, 0); } continue; } + if (abs($item_image['Priority'])) { + // use Priority as image counter, when specified + $image_counter = abs($item_image['Priority']); + } + if (array_key_exists('Image'.$image_counter, $object->Fields)) { $object->SetDBField('Image'.$image_counter, $image_path); $object->SetOriginalField('Image'.$image_counter, $image_path); $object->Fields['Image'.$image_counter]['original_field'] = $item_image['Name']; + + $this->_loadCustomFields($object, $item_image, $image_counter); } $image_counter++; } @@ -368,6 +377,7 @@ $fields_hash = Array ( 'ThumbPath' => $image_src, ); + $this->_saveCustomFields($object, $fields_hash, $i); $this->Conn->doUpdate($fields_hash, $table_name, $key_clause); } @@ -382,6 +392,7 @@ 'DefaultImg' => $i ? 0 : 1, // first image is primary, others not primary 'ThumbPath' => $image_src, ); + $this->_saveCustomFields($object, $fields_hash, $i); $this->Conn->doInsert($fields_hash, $table_name); $field_options['original_field'] = $field; @@ -391,6 +402,34 @@ $i++; } } + + /** + * Adds ability to load custom fields along with main image field + * + * @param kCatDBItem $object + * @param Array $fields_hash + * @param int $counter 0 - primary image, other number - additional image number + */ + function _loadCustomFields(&$object, $fields_hash, $counter) + { + $field_name = $counter ? 'Image' . $counter . 'Alt' : 'PrimaryImageAlt'; + + $object->SetDBField($field_name, $fields_hash['AltName']); + } + + /** + * Adds ability to save custom field along with main image save + * + * @param kCatDBItem $object + * @param Array $fields_hash + * @param int $counter 0 - primary image, other number - additional image number + */ + function _saveCustomFields(&$object, &$fields_hash, $counter) + { + $field_name = $counter ? 'Image' . $counter . 'Alt' : 'PrimaryImageAlt'; + + $fields_hash['AltName'] = $object->GetDBField($field_name); + } } ?> \ No newline at end of file