Index: branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/col_picker_helper.php =================================================================== diff -u -r6848 -r6889 --- branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/col_picker_helper.php (.../col_picker_helper.php) (revision 6848) +++ branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/col_picker_helper.php (.../col_picker_helper.php) (revision 6889) @@ -2,30 +2,30 @@ class kColumnPickerHelper extends kHelper { - function ApplyPicker() + function LoadColumns($prefix) { - $user_id = $this->Application->RecallVar('user_id'); - $var_name = 'new_'.$this->Prefix; - $q = "SELECT value FROM persistent_session WHERE var='$var_name' and user_id = $user_id"; - $conn =& $this->Application->GetADODBConnection(); - $val = $conn->GetOne($q); + $view_name = $this->Application->RecallVar($prefix.'_current_view'); + $val = $this->Application->RecallPersistentVar($prefix.'_columns_.'.$view_name); - if ($val == '') { - $this->PickerData = $this->RebuildColumns(); + if (!$val) { + $cols = $this->RebuildColumns($prefix); } else { $cols = unserialize($val); - $current_cols = $this->GetColumns(); + $current_cols = $this->GetColumns($prefix); if ($cols === false || $cols['crc'] != $current_cols['crc']) { - $this->PickerData = $this->RebuildColumns($cols); + $cols = $this->RebuildColumns($prefix, $cols); } - else { - $this->PickerData = $cols; - } } - $fields =& $this->Application->NConfig[ $this->Owner->NKey ]['Fields']; + return $cols; + } + + function ApplyPicker($prefix, &$fields) + { + $this->PickerData = $this->LoadColumns($prefix); + uksort($fields, array($this, 'CmpElems')); $this->RemoveHiddenColumns($fields); } @@ -41,9 +41,9 @@ return ($a_index < $b_index) ? -1 : 1; } - function RebuildColumns($current=null) + function RebuildColumns($prefix, $current=null) { - $cols = $this->GetColumns(); + $cols = $this->GetColumns($prefix); if (is_array($current)) { //get common fields both in db and xml @@ -56,22 +56,31 @@ $cols['hidden_fields'] = array_intersect($current['order'], $current['hidden_fields']); $this->SetCRC($cols); } + $this->StoreCols($prefix, $cols); - $conn =& $this->Application->GetADODBConnection(); - $user_id = $this->Application->RecallVar('user_id'); - $var_name = 'new_'.$this->Prefix; - $data = $conn->qstr(serialize($cols)); - $q = "REPLACE INTO persistent_session (user_id, var, value) VALUES ($user_id, '$var_name', $data)"; - $conn->Execute($q); return $cols; } - function GetColumns() + function StoreCols($prefix, $cols) { - $conf_fields = $this->Application->NConfig[ $this->Owner->NKey ]['Fields']; + $view_name = $this->Application->RecallVar($prefix.'_current_view'); + $this->Application->StorePersistentVar($prefix.'_columns_.'.$view_name, serialize($cols)); + } + function GetColumns($prefix, $grid_name='Default') + { + $splited = $this->Application->processPrefix($prefix); + $grids = $this->Application->getUnitOption($splited['prefix'], 'Grids'); + $conf_fields = $grids[$grid_name]['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']; @@ -113,4 +122,18 @@ 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