Index: branches/5.2.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r14585 -r14596 --- branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14596) @@ -1,6 +1,6 @@ getCurrentRecord(); } - function MoreLink($params) + /** + * Renders given block name, when there there is more data in list, then are displayed right now + * + * @param Array $params + * @return string + * @access protected + */ + protected function MoreLink($params) { $per_page = $this->SelectParam($params, 'per_page,max_items'); - if ($per_page !== false) { + if ( $per_page !== false ) { $params['per_page'] = $per_page; } @@ -620,13 +629,13 @@ $has_next_page = $list->GetPerPage() < $list->GetRecordsCount(); } - if ($has_next_page) { - $block_params = Array ( - 'name' => $this->SelectParam($params, 'render_as,block'), - ); + if ( $has_next_page ) { + $block_params = Array ('name' => $this->SelectParam($params, 'render_as,block')); return $this->Application->ParseBlock($block_params); } + + return ''; } function PageLink($params) @@ -755,12 +764,19 @@ return $iso; } + /** + * Convert primary currency to selected (if they are the same, converter will just return) + * + * @param float $value + * @param string $iso + * @return float + */ function ConvertCurrency($value, $iso) { $converter =& $this->Application->recallObject('kCurrencyRates'); - // convery primary currency to selected (if they are the same, converter will just return) - $value = $converter->Convert($value, 'PRIMARY', $iso); - return $value; + /* @var $converter kCurrencyRates */ + + return $converter->Convert($value, 'PRIMARY', $iso); } function AddCurrencySymbol($value, $iso) @@ -973,10 +989,14 @@ // $object =& $this->getObject($params); - $dst_field = $this->SelectParam($params, 'name,field'); + /* @var $object kDBItem */ + $dst_field = $this->SelectParam($params, 'name,field'); list($prefix_special, $src_field) = explode(':', $params['src']); + $src_object =& $this->Application->recallObject($prefix_special); + /* @var $src_object kDBItem */ + $object->SetDBField($dst_field, $src_object->GetDBField($src_field)); } @@ -996,61 +1016,77 @@ function Error($params) { - $field = $this->SelectParam($params, 'name,field'); $object =& $this->getObject($params); - $msg = $object->GetErrorMsg($field, false); - return $msg; + /* @var $object kDBItem */ + + $field = $this->SelectParam($params, 'name,field'); + + return $object->GetErrorMsg($field, false); } function HasError($params) { - if ($params['field'] == 'any') - { + if ($params['field'] == 'any') { $object =& $this->getObject($params); + /* @var $object kDBItem */ $skip_fields = array_key_exists('except', $params) ? $params['except'] : false; $skip_fields = $skip_fields ? explode(',', $skip_fields) : Array(); return $object->HasErrors($skip_fields); } - else - { - $fields = $this->SelectParam($params, 'field,fields'); - $fields = explode(',', $fields); + else { $res = false; - foreach($fields as $field) - { + $fields = explode(',', $this->SelectParam($params, 'field,fields')); + + foreach ($fields as $field) { + // call kDBTagProcessor::Error instead of kDBItem::GetErrorPseudo to have ability to override Error tag $params['field'] = $field; $res = $res || ($this->Error($params) != ''); } + return $res; } } - function ErrorWarning($params) + /** + * Renders error message block, when there are errors on a form + * + * @param Array $params + * @return string + * @access protected + */ + protected function ErrorWarning($params) { - if (!isset($params['field'])) { + if ( !isset($params['field']) ) { $params['field'] = 'any'; } - if ($this->HasError($params)) { + + if ( $this->HasError($params) ) { $params['prefix'] = $this->getPrefixSpecial(); + return $this->Application->ParseBlock($params); } + + return ''; } function IsRequired($params) { - $field = $params['field']; $object =& $this->getObject($params); + /* @var $object kDBItem */ + $field = $params['field']; $formatter_class = $object->GetFieldOption($field, 'formatter'); - if ($formatter_class == 'kMultiLanguage') - { + + if ( $formatter_class == 'kMultiLanguage' ) { $formatter =& $this->Application->recallObject($formatter_class); + /* @var $formatter kMultiLanguage */ + $field = $formatter->LangFieldName($field); } - return $object->GetFieldOption($field, 'required'); + return $object->isRequired($field); } function FieldOption($params) @@ -1062,10 +1098,18 @@ return $ret; } - function PredefinedOptions($params) + /** + * Prints list a all possible field options + * + * @param Array $params + * @return string + * @access protected + */ + protected function PredefinedOptions($params) { $object =& $this->getObject($params); - + /* @var $object kDBList */ + $field = $params['field']; $value = array_key_exists('value', $params) ? $params['value'] : $object->GetDBField($field); $field_options = $object->GetFieldOptions($field); @@ -1151,21 +1195,23 @@ $object =& $this->getObject($params); $options = $object->GetFieldOptions($field); - - $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ]; - + $format = $options[$this->SelectParam($params, 'input_format') ? 'input_format' : 'format']; $formatter_class = array_key_exists('formatter', $options) ? $options['formatter'] : false; - if ($formatter_class) { + if ( $formatter_class ) { $formatter =& $this->Application->recallObject($formatter_class); + /* @var $formatter kFormatter */ + $human_format = array_key_exists('human', $params) ? $params['human'] : false; $edit_size = array_key_exists('edit_size', $params) ? $params['edit_size'] : false; $sample = array_key_exists('sample', $params) ? $params['sample'] : false; - if ($sample) { + + if ( $sample ) { return $formatter->GetSample($field, $options, $object); } - elseif ($human_format || $edit_size) { + elseif ( $human_format || $edit_size ) { $format = $formatter->HumanFormat($format); + return $edit_size ? strlen($format) : $format; } } @@ -1380,7 +1426,7 @@ { $object =& $this->getObject($params); /* @var $object kDBItem */ - + $field = $this->SelectParam($params, 'name,field'); $formatter_class = $object->GetFieldOption($field, 'formatter'); @@ -1518,38 +1564,53 @@ } /** - * Get's information of sorting field at "pos" position, + * Gets information of sorting field at "pos" position, * like sorting field name (type="field") or sorting direction (type="direction") * * @param Array $params - * @return mixed + * @return string + * @access protected */ - function OrderInfo($params) + protected function OrderInfo($params) { $user_sorting_start = $this->getUserSortIndex() + --$params['pos']; $list =& $this->GetList($params); - if($params['type'] == 'field') return $list->GetOrderField($user_sorting_start); - if($params['type'] == 'direction') return $list->GetOrderDirection($user_sorting_start); + if ( $params['type'] == 'field' ) { + return $list->GetOrderField($user_sorting_start); + } + + if ( $params['type'] == 'direction' ) { + return $list->GetOrderDirection($user_sorting_start); + } + + return ''; } /** * Checks if sorting field/direction matches passed field/direction parameter * * @param Array $params * @return bool + * @access protected */ - function IsOrder($params) + protected function IsOrder($params) { $params['type'] = isset($params['field']) ? 'field' : 'direction'; $value = $this->OrderInfo($params); - if( isset($params['field']) ) return $params['field'] == $value; - if( isset($params['direction']) ) return $params['direction'] == $value; + if ( isset($params['field']) ) { + return $params['field'] == $value; + } + elseif ( isset($params['direction']) ) { + return $params['direction'] == $value; + } + + return false; } /** - * Returns list perpage + * Returns list per-page * * @param Array $params * @return int @@ -1693,20 +1754,22 @@ $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); $grid = $grids[ $params['grid'] ]; - if (!array_key_exists('Icons', $grid)) { + if ( !isset($grid['Icons']) ) { return ''; } $icons = $grid['Icons']; - if (array_key_exists('name', $params)) { + if ( isset($params['name']) ) { $icon_name = $params['name']; - return array_key_exists($icon_name, $icons) ? $icons[$icon_name] : ''; + + return isset($icons[$icon_name]) ? $icons[$icon_name] : ''; } - $status_fields = $this->Application->getUnitOption($this->Prefix, 'StatusField'); + $status_fields = $this->Application->getUnitOption($this->Prefix, 'StatusField', Array ()); + /* @var $status_fields Array */ - if (!$status_fields) { + if ( !$status_fields ) { return $icons['default']; } @@ -1721,7 +1784,7 @@ $icon = rtrim($icon, '_'); - return array_key_exists($icon, $icons) ? $icons[$icon] : $icons['default']; + return isset($icons[$icon]) ? $icons[$icon] : $icons['default']; } /** @@ -1758,9 +1821,10 @@ $prefixes = array_key_exists('prefixes', $title_info) ? $title_info['prefixes'] : false; $all_tag_params = array_key_exists('tag_params', $title_info) ? $title_info['tag_params'] : false; - + /* @var $prefixes Array */ + if ($prefixes) { - // extract tag_perams passed directly to SectionTitle tag for specific prefix + // extract tag_params passed directly to SectionTitle tag for specific prefix foreach ($params as $tp_name => $tp_value) { if (preg_match('/(.*)\[(.*)\]/', $tp_name, $regs)) { $all_tag_params[ $regs[1] ][ $regs[2] ] = $tp_value; @@ -1845,24 +1909,33 @@ return $title; } - function getInfo(&$object, $info_type) + /** + * Returns information about list + * + * @param kDBList $object + * @param string $info_type + * @return string + * @access protected + */ + protected function getInfo(&$object, $info_type) { - switch ($info_type) - { + switch ( $info_type ) { case 'titlefield': - $field = $this->Application->getUnitOption($object->Prefix,'TitleField'); + $field = $this->Application->getUnitOption($object->Prefix, 'TitleField'); return $field !== false ? $object->GetField($field) : 'TitleField Missing'; break; case 'recordcount': - $of_phrase = $this->Application->Phrase('la_of'); - return $object->GetRecordsCount(false) != $object->GetRecordsCount() ? $object->GetRecordsCount().' '.$of_phrase.' '.$object->GetRecordsCount(false) : $object->GetRecordsCount(); + if ( $object->GetRecordsCount(false) != $object->GetRecordsCount() ) { + $of_phrase = $this->Application->Phrase('la_of'); + return $object->GetRecordsCount() . ' ' . $of_phrase . ' ' . $object->GetRecordsCount(false); + } + + return $object->GetRecordsCount(); break; - - default: - return $object->GetField($info_type); - break; } + + return $object->GetField($info_type); } function GridInfo($params) @@ -2013,34 +2086,35 @@ } /** - * If data was modfied & is in TempTables mode, then parse block with name passed; + * If data was modified & is in TempTables mode, then parse block with name passed; * remove modification mark if not in TempTables mode * * @param Array $params * @return string - * @access public - * @author Alexey + * @access protected */ - function SaveWarning($params) + protected function SaveWarning($params) { $main_prefix = array_key_exists('main_prefix', $params) ? $params['main_prefix'] : false; - if ($main_prefix) { + + if ( $main_prefix ) { $top_prefix = $main_prefix; } else { $top_prefix = $this->Application->GetTopmostPrefix($this->Prefix); } - $temp_tables = substr($this->Application->GetVar($top_prefix.'_mode'), 0, 1) == 't'; - $modified = $this->Application->RecallVar($top_prefix.'_modified'); + $temp_tables = substr($this->Application->GetVar($top_prefix . '_mode'), 0, 1) == 't'; + $modified = $this->Application->RecallVar($top_prefix . '_modified'); - if ($temp_tables && $modified) { + if ( $temp_tables && $modified ) { $block_params = $this->prepareTagParams($params); $block_params['name'] = $this->SelectParam($params, 'render_as,name'); $block_params['edit_mode'] = $temp_tables ? 1 : 0; return $this->Application->ParseBlock($block_params); } - $this->Application->RemoveVar($top_prefix.'_modified'); + + $this->Application->RemoveVar($top_prefix . '_modified'); return ''; } @@ -2081,36 +2155,35 @@ * * @param Array $params * @return string + * @access protected */ - function SearchField($params) // RangeValue + protected function SearchField($params) // RangeValue { $field = $this->SelectParam($params, 'field,name'); - $view_name = $this->Application->RecallVar($this->getPrefixSpecial().'_current_view'); - $custom_filter = $this->Application->RecallPersistentVar($this->getPrefixSpecial().'_custom_filter.'.$view_name/*, ALLOW_DEFAULT_SETTINGS*/); - $custom_filter = $custom_filter ? unserialize($custom_filter) : Array(); + $view_name = $this->Application->RecallVar($this->getPrefixSpecial() . '_current_view'); + $custom_filter = $this->Application->RecallPersistentVar($this->getPrefixSpecial() . '_custom_filter.' . $view_name /*, ALLOW_DEFAULT_SETTINGS*/); + $custom_filter = $custom_filter ? unserialize($custom_filter) : Array (); - if (isset($custom_filter[ $params['grid'] ][$field])) { - $ret = $custom_filter[ $params['grid'] ][$field][ $params['filter_type'] ]['submit_value']; - if (isset($params['type'])) { - $ret = $ret[ $params['type'] ]; + if ( isset($custom_filter[$params['grid']][$field]) ) { + $ret = $custom_filter[$params['grid']][$field][$params['filter_type']]['submit_value']; + if ( isset($params['type']) ) { + $ret = $ret[$params['type']]; } - if (array_key_exists('formatted', $params) && $params['formatted']) { + if ( array_key_exists('formatted', $params) && $params['formatted'] ) { $object =& $this->GetList($params); - $field_options = $object->GetFieldOptions($field); + $formatter_class = $object->GetFieldOption($field, 'formatter'); - if (array_key_exists('formatter', $field_options)) { - $formatter_class = $field_options['formatter']; - + if ( $formatter_class ) { $formatter =& $this->Application->recallObject($formatter_class); /* @var $formatter kFormatter */ $ret = $formatter->Format($ret, $field, $object); } } - if (!array_key_exists('no_special', $params) || !$params['no_special']) { + if ( !array_key_exists('no_special', $params) || !$params['no_special'] ) { $ret = htmlspecialchars($ret); } @@ -2151,6 +2224,8 @@ if ($formatter_class) { $formatter =& $this->Application->recallObject($formatter_class); + /* @var $formatter kFormatter */ + $human_format = array_key_exists('human', $params) ? $params['human'] : false; $edit_size = array_key_exists('edit_size', $params) ? $params['edit_size'] : false; $sample = array_key_exists('sample', $params) ? $params['sample'] : false; @@ -2170,20 +2245,21 @@ /** * Returns error of range field * - * @param unknown_type $params - * @return unknown + * @param Array $params + * @return string + * @access protected */ - function SearchError($params) + protected function SearchError($params) { $field = $this->SelectParam($params, 'field,name'); - $error_var_name = $this->getPrefixSpecial().'_'.$field.'_error'; + $error_var_name = $this->getPrefixSpecial() . '_' . $field . '_error'; $pseudo = $this->Application->RecallVar($error_var_name); - if ($pseudo) { + if ( $pseudo ) { $this->Application->RemoveVar($error_var_name); } - $object =& $this->Application->recallObject($this->Prefix.'.'.$this->Special.'-item', null, Array('skip_autoload' => true)); + $object =& $this->Application->recallObject($this->Prefix . '.' . $this->Special . '-item', null, Array ('skip_autoload' => true)); /* @var $object kDBItem */ $object->SetError($field, $pseudo); @@ -2253,7 +2329,8 @@ function ExportStatus($params) { $export_object =& $this->Application->recallObject('CatItemExportHelper'); - + /* @var $export_object kCatDBItemExportHelper */ + $event = new kEvent($this->getPrefixSpecial().':OnDummy'); $action_method = 'perform'.ucfirst($this->Special); @@ -2283,16 +2360,19 @@ * Returns path where exported category items should be saved * * @param Array $params + * @return string + * @access protected */ - function ExportPath($params) + protected function ExportPath($params) { - $export_options = unserialize($this->Application->RecallVar($this->getPrefixSpecial().'_options')); + $export_options = unserialize($this->Application->RecallVar($this->getPrefixSpecial() . '_options')); $extension = $export_options['ExportFormat'] == 1 ? 'csv' : 'xml'; $filename = preg_replace('/(.*)\.' . $extension . '$/', '\1', $export_options['ExportFilename']) . '.' . $extension; $path = EXPORT_PATH . '/'; - if (array_key_exists('as_url', $params) && $params['as_url']) { - $path = str_replace( FULL_PATH . '/', $this->Application->BaseURL(), $path); + + if ( array_key_exists('as_url', $params) && $params['as_url'] ) { + $path = str_replace(FULL_PATH . '/', $this->Application->BaseURL(), $path); } return $path . $filename; @@ -2444,19 +2524,20 @@ * * @param Array $params * @return string + * @access protected */ - function ItemLink($params) + protected function ItemLink($params) { $object =& $this->getObject($params); + /* @var $object kDBItem */ - if (!isset($params['pass'])) { + if ( !isset($params['pass']) ) { $params['pass'] = 'm'; } - $params[$object->getPrefixSpecial().'_id'] = $object->GetID(); + $params[ $object->getPrefixSpecial() . '_id' ] = $object->GetID(); - $m =& $this->Application->recallObject('m_TagProcessor'); - return $m->t($params); + return $this->Application->ProcessParsedTag('m', 'T', $params); } /** @@ -2467,8 +2548,8 @@ function PresetFormFields($params) { $prefix = $this->getPrefixSpecial(); - if (!$this->Application->GetVar($prefix.'_event')) { - $this->Application->HandleEvent(new kEvent($prefix.':OnNew')); + if ( !$this->Application->GetVar($prefix . '_event') ) { + $this->Application->HandleEvent(new kEvent($prefix . ':OnNew')); } } @@ -2574,12 +2655,13 @@ * * @param Array $params * @return string + * @access protected */ - function PrintEditTabs($params) + protected function PrintEditTabs($params) { $edit_tabs = $this->getEditTabs($params['preset_name']); - if (!$edit_tabs) { - return ; + if ( !$edit_tabs ) { + return ''; } usort($edit_tabs, Array (&$this, 'sortEditTabs')); @@ -2766,4 +2848,40 @@ return $value; } + + /** + * Returns/sets form name for current object + * + * @param Array $params + * @return string + */ + function FormName($params) + { + $form_name = $this->SelectParam($params, 'name,form,form_name'); + + if ( $form_name ) { + $prefix = $this->getPrefixSpecial(); + + if ( $this->Application->hasObject( $this->getPrefixSpecial() ) ) { + $object =& $this->getObject($params); + /* @var $object kDBItem */ + + if ( $object->getFormName() != $form_name ) { + trigger_error('Setting form to "' . $form_name . '" failed, since object "' . $this->getPrefixSpecial() . '" is created before FormName tag (e.g. in event or another tag).', E_USER_WARNING); + } + } + else { + $forms = $this->Application->GetVar('forms', Array ()); + $forms[ $this->getPrefixSpecial() ] = $form_name; + $this->Application->SetVar('forms', $forms); + } + + return ''; + } + + $object =& $this->getObject($params); + /* @var $object kDBItem */ + + return $object->getFormName(); + } } \ No newline at end of file