Index: branches/RC/core/units/general/helpers/file_helper.php =================================================================== diff -u -N -r10720 -r11857 --- branches/RC/core/units/general/helpers/file_helper.php (.../file_helper.php) (revision 10720) +++ branches/RC/core/units/general/helpers/file_helper.php (.../file_helper.php) (revision 11857) @@ -159,7 +159,8 @@ if (preg_match('/^('.$field_prefix.'[\d]+|Primary'.$field_prefix.')$/', $field_name)) { $fields[$field_name] = $field_options; $virtual_fields[$field_name] = $field_options; - $virtual_fields['Delete'.$field_name] = Array ('type' => 'int', 'not_null' => 1, 'default' => 0); + $this->_createCustomFields($prefix, $field_name, $virtual_fields, $is_image); + $image_count++; } } @@ -185,6 +186,22 @@ } /** + * Adds ability to create more virtual fields associated with main image/file + * + * @param string $prefix + * @param string $field_name + * @param Array $virtual_fields + */ + function _createCustomFields($prefix, $field_name, &$virtual_fields, $is_image) + { + $virtual_fields['Delete' . $field_name] = Array ('type' => 'int', 'not_null' => 1, 'default' => 0); + + if ($is_image) { + $virtual_fields[$field_name . 'Alt'] = Array ('type' => 'string', 'default' => ''); + } + } + + /** * Downloads file to user * * @param string $filename 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 Index: branches/RC/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r11855 -r11857 --- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 11855) +++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 11857) @@ -912,18 +912,16 @@ } // linking existing images for item with virtual fields - if ($event->Prefix != 'cms') { - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ - $image_helper->LoadItemImages($object); + $image_helper->LoadItemImages($object); - // linking existing files for item with virtual fields - $file_helper =& $this->Application->recallObject('FileHelper'); - /* @var $file_helper FileHelper */ + // linking existing files for item with virtual fields + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ - $file_helper->LoadItemFiles($object); - } + $file_helper->LoadItemFiles($object); // set item's additional categories to virtual field (used in editing) $item_categories = $this->getItemCategories($object->GetDBField('ResourceId')); @@ -942,19 +940,17 @@ $object =& $event->getObject(); /* @var $object kDBItem */ - if ($event->Prefix != 'cms') { - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ - // process image upload in virtual fields - $image_helper->SaveItemImages($object); + // process image upload in virtual fields + $image_helper->SaveItemImages($object); - $file_helper =& $this->Application->recallObject('FileHelper'); - /* @var $file_helper FileHelper */ + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ - // process file upload in virtual fields - $file_helper->SaveItemFiles($object); - } + // process file upload in virtual fields + $file_helper->SaveItemFiles($object); if ($event->Special != '-item') { // don't touch categories during cloning @@ -978,19 +974,17 @@ $object =& $event->getObject(); /* @var $object kDBItem */ - if ($event->Prefix != 'cms') { - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ - // process image upload in virtual fields - $image_helper->SaveItemImages($object); + // process image upload in virtual fields + $image_helper->SaveItemImages($object); - $file_helper =& $this->Application->recallObject('FileHelper'); - /* @var $file_helper FileHelper */ + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ - // process file upload in virtual fields - $file_helper->SaveItemFiles($object); - } + // process file upload in virtual fields + $file_helper->SaveItemFiles($object); if ($event->Special != '-item') { // don't touch categories during cloning @@ -2473,9 +2467,7 @@ { $object =& $event->getObject(); if (!$object->isLoaded()) { - if ($object->Prefix != 'cms') { - $this->_errorNotFound($event); - } + $this->_errorNotFound($event); return true; } Index: branches/RC/core/install/upgrades.php =================================================================== diff -u -N -r11705 -r11857 --- branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11705) +++ branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11857) @@ -683,6 +683,7 @@ if ($mode == 'after') { $this->_fixSkinColors(); $this->_restructureCatalog(); + $this->_sortImages(); // $this->_sortConfigurationVariables('In-Portal', 'in-portal:configure_general'); // $this->_sortConfigurationVariables('In-Portal', 'in-portal:configure_advanced'); @@ -1098,4 +1099,35 @@ } } + /** + * Sort images in database (update Priority field) + * + */ + function _sortImages() + { + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'Images + ORDER BY ResourceId ASC , DefaultImg DESC , ImageId ASC'; + $images = $this->Conn->Query($sql); + + $priority = 0; + $last_resource_id = false; + + foreach ($images as $image) { + if ($image['ResourceId'] != $last_resource_id) { + // each item have own priorities among it's images + $priority = 0; + $last_resource_id = $image['ResourceId']; + } + + if (!$image['DefaultImg']) { + $priority--; + } + + $sql = 'UPDATE ' . TABLE_PREFIX . 'Images + SET Priority = ' . $priority . ' + WHERE ImageId = ' . $image['ImageId']; + $this->Conn->Query($sql); + } + } } \ No newline at end of file