Index: branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/helpers_config.php =================================================================== diff -u -r7652 -r7781 --- branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 7652) +++ branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 7781) @@ -17,5 +17,6 @@ Array('pseudo'=>'ColumnPickerHelper','class'=>'kColumnPickerHelper','file'=>'col_picker_helper.php','build_event'=>'','require_classes'=>'kHelper'), Array('pseudo'=>'ThemesHelper','class'=>'kThemesHelper','file'=>'themes_helper.php','build_event'=>'','require_classes'=>'kHelper'), Array('pseudo'=>'CaptchaHelper','class'=>'kCaptchaHelper','file'=>'captcha_helper.php','build_event'=>'','require_classes'=>'kHelper'), + Array('pseudo'=>'PriorityHelper','class'=>'kPriorityHelper','file'=>'priority_helper.php','build_event'=>'','require_classes'=>'kHelper'), ), ); \ No newline at end of file Index: branches/unlabeled/unlabeled-1.5.2/core/units/general/helpers/recursive_helper.php =================================================================== diff -u -r7656 -r7781 --- branches/unlabeled/unlabeled-1.5.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 7656) +++ branches/unlabeled/unlabeled-1.5.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 7781) @@ -90,7 +90,7 @@ $this->Conn->Query($sql); } } - + /** * Complete cloning or category with subcategories and subitems * @@ -99,14 +99,14 @@ function PasteCategory($category_id, $prefix = 'c') { $backup_category_id = $this->Application->GetVar('m_cat_id'); - + // 1. clone category $temp_handler =& $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler*/ $temp_handler->BuildTables($prefix, Array($category_id)); $new_category_id = array_pop( $temp_handler->CloneItems($prefix, '', Array($category_id)) ); $this->Application->SetVar('m_cat_id', $new_category_id); - + $id_field = $this->Application->getUnitOption($prefix, 'IDField'); $table_name = $this->Application->getUnitOption($prefix, 'TableName'); Index: branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/priority_helper.php =================================================================== diff -u --- branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/priority_helper.php (revision 0) +++ branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/priority_helper.php (revision 7781) @@ -0,0 +1,132 @@ +getObject(); + + $field_options = $object->GetFieldOptions('Priority'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + $sql = 'SELECT COUNT(*) + FROM '.$table_name; + if ($constrain) { + $sql .= ' WHERE '.$constrain; + + } + + $items_count = $this->Conn->GetOne($sql); + if ($is_new) { + // add new item to the end of list + $items_count++; + $object->SetDBField('Priority', -$items_count); + $object->SetDBField('OldPriority', -$items_count); + } + + for ($i = 1; $i <= $items_count; $i++) { + $field_options['options'][-$i] = $i; + } + + $object->SetFieldOptions('Priority', $field_options); + } + + /** + * Updates priorities for changed items + * + * @param kEvent $event + * @param Array $changes = Array (CategoryID => Array ('parent' => ..., 'new' => ..., 'old' => ...), ...) + * @param Array $new_ids = Array (temp_id => live_id) + * @param string $constrain + */ + function updatePriorities(&$event, $changes, $new_ids, $constrain = '') + { + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + $not_processed = array_keys($changes); + + foreach ($changes as $id => $pair) { + $constrain = 'ParentId = '.$pair['parent'].' AND '; + + if ($pair['old'] == 'new') { + // replace 0 with newly created item id (from $new_ids mapping) + $not_processed[ array_search($id, $not_processed) ] = $new_ids[$id]; + $id = $new_ids[$id]; + + $sql = 'SELECT MIN(Priority) + FROM '.$table_name.' + WHERE '.$constrain.' CategoryId NOT IN ('.implode(',', $not_processed).')'; + $min_priority = (int)$this->Conn->GetOne($sql) - 1; + + if ($pair['new'] < $min_priority) { + $pair['new'] = $min_priority; + } + $pair['old'] = $min_priority; + } + + if ($pair['new'] < $pair['old']) { + $q = ' SET Priority = Priority + 1 + WHERE '.$constrain.' + Priority >= '.$pair['new'].' + AND + Priority < '.$pair['old'].' + AND + CategoryId NOT IN ('.implode(',', $not_processed).')'; + } + elseif ($pair['new'] > $pair['old']) { + $q = ' SET Priority = Priority - 1 + WHERE '.$constrain.' + Priority > '.$pair['old'].' + AND + Priority <= '.$pair['new'].' + AND + CategoryId NOT IN ('.implode(',', $not_processed).')'; + } + else { + $q = 'SET Priority = '.$pair['new'].' WHERE '.$id_field.' = '.$id; + } + $q = 'UPDATE '.$table_name.' '.$q; + $this->Conn->Query($q); + + unset( $not_processed[array_search($id, $not_processed)] ); + } + } + + /** + * Recalculates priorities + * + * @param kEvent $event + * @param string $constrain + */ + function recalculatePriorities(&$event, $constrain = '') + { + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + $sql = 'SELECT '.$id_field.' + FROM '.$table_name. + ($constrain ? ' WHERE '.$constrain : '').' + ORDER BY Priority DESC'; + + $items = $this->Conn->GetCol($sql); + + foreach ($items as $item_number => $item_id) { + $sql = 'UPDATE '.$table_name.' + SET Priority = '.-($item_number + 1).' + WHERE '.$id_field.' = '.$item_id; + $this->Conn->Query($sql); + } + } + + } +?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.170.2/core/kernel/application.php =================================================================== diff -u -r7774 -r7781 --- branches/unlabeled/unlabeled-1.170.2/core/kernel/application.php (.../application.php) (revision 7774) +++ branches/unlabeled/unlabeled-1.170.2/core/kernel/application.php (.../application.php) (revision 7781) @@ -1915,8 +1915,7 @@ function isDebugMode($check_debugger = true) { $debug_mode = defined('DEBUG_MODE') && DEBUG_MODE; - if($check_debugger) - { + if ($check_debugger) { $debug_mode = $debug_mode && is_object($this->Debugger); } return $debug_mode;