Index: trunk/core/units/general/helpers/col_picker_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/col_picker_helper.php (revision 7391) +++ trunk/core/units/general/helpers/col_picker_helper.php (revision 0) @@ -1,147 +0,0 @@ -Application->RecallVar($prefix.'_current_view'); - $val = $this->Application->RecallPersistentVar($prefix.'_columns_.'.$view_name); - - if (!$val) { - $cols = $this->RebuildColumns($prefix); - } - else { - $cols = unserialize($val); - $current_cols = $this->GetColumns($prefix); - - if ($cols === false || $cols['crc'] != $current_cols['crc']) - { - $cols = $this->RebuildColumns($prefix, $cols); - } - } - return $cols; - } - - function ApplyPicker($prefix, &$fields, $grid_name) - { - $this->SetGridName($grid_name); - $this->PickerData = $this->LoadColumns($prefix); - - uksort($fields, array($this, 'CmpElems')); - $this->RemoveHiddenColumns($fields); - } - - function SetGridName($grid_name) - { - $this->GridName = $grid_name; - } - - function CmpElems($a, $b) - { - $a_index = array_search($a, $this->PickerData['order']); - $b_index = array_search($b, $this->PickerData['order']); - - if ($a_index == $b_index) { - return 0; - } - return ($a_index < $b_index) ? -1 : 1; - } - - function RebuildColumns($prefix, $current=null) - { - $cols = $this->GetColumns($prefix); - - if (is_array($current)) { - //get common fields both in db and xml - $common = array_intersect($current['order'], $cols['order']); - - //get added columns - present in xml, but not in db - $added = array_diff($cols['order'], $current['order']); - - $cols['order'] = array_merge($common, $added); - $cols['hidden_fields'] = array_intersect($current['order'], $current['hidden_fields']); - $this->SetCRC($cols); - } - $this->StoreCols($prefix, $cols); - - return $cols; - } - - function StoreCols($prefix, $cols) - { - $view_name = $this->Application->RecallVar($prefix.'_current_view'); - $this->Application->StorePersistentVar($prefix.'_columns_.'.$view_name, serialize($cols)); - } - - function GetColumns($prefix) - { - $splited = $this->Application->processPrefix($prefix); - $grids = $this->Application->getUnitOption($splited['prefix'], 'Grids'); - $conf_fields = $grids[$this->GridName]['Fields']; - - // we NEED to recall dummy here to apply fields changes imposed by formatters, - // such as replacing multilingual field titles etc. - $dummy =& $this->Application->recallObject($prefix, null, array('skip_autoload'=>1)); - - $counter = 0; - $hidden = array(); - $fields = array(); - $titles = array(); - foreach ($conf_fields as $name => $options) { - $fields[$counter] = $name; - $titles[$name] = $options['title']; - if (isset($options['hidden']) && $options['hidden']) - { - $hidden[$counter] = $name; - } - $counter++; - } - $sorted_fields = $fields; - sort($sorted_fields); - $cols = array( - 'order' => $fields, - 'titles' => $titles, - 'hidden_fields' => $hidden - ); - $this->SetCRC($cols); - return $cols; - } - - function SetCRC(&$cols) - { - $sorted_fields = $cols['order']; - $sorted_titles = $cols['titles']; - asort($sorted_fields); - asort($sorted_titles); - $cols['crc'] = crc32(implode(',', $sorted_fields).implode(',', $sorted_titles)); - } - - function RemoveHiddenColumns(&$fields) - { - $to_remove = array(); - foreach ($fields as $name => $options) { - if (array_search($name, $this->PickerData['hidden_fields']) !== false) { - $to_remove[] = $name; - } - } - foreach ($to_remove as $name) { - unset($fields[$name]); - } - } - - function SaveColumns($prefix, $picked, $hidden) - { - $order = $picked ? explode('|', $picked) : array(); - $hidden = $hidden ? explode('|', $hidden) : array(); - $order = array_merge($order, $hidden); - - $cols = array(); - $cols['order'] = $order; - $cols['hidden_fields'] = $hidden; - - $this->SetCRC($cols); - $this->StoreCols($prefix, $cols); - } -} \ No newline at end of file