Index: branches/5.2.x/core/units/reviews/reviews_tag_processor.php =================================================================== diff -u -N -r14652 -r14769 --- branches/5.2.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 14652) +++ branches/5.2.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 14769) @@ -1,6 +1,6 @@ getObject($params); + /* @var $object kDBItem */ + + $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); + + $main_object =& $this->Application->recallObject($parent_prefix); + /* @var $main_object kCatDBItem */ + + if ( !isset($cache) ) { + $sql = 'SELECT COUNT(*), Rating + FROM ' . $object->TableName . ' + WHERE ItemId = ' . $main_object->GetDBField('ResourceId') . ' + GROUP BY Rating'; + $cache = $this->Conn->GetCol($sql, 'Rating'); + } + + $ratings = array_reverse( array_keys( $object->GetFieldOption('Rating', 'options') ) ); + + if ( !isset($params['show_none']) || !$params['show_none'] ) { + $none_index = array_search(0, $ratings); + + if ( $none_index !== false ) { + unset($ratings[$none_index]); + } + } + + $ret = ''; + $total = array_sum($cache); + $block_params = $this->prepareTagParams($params); + $block_params['name'] = $params['render_as']; + $block_params['strip_nl'] = 2; + + foreach ($ratings as $rating) { + $block_params['rating'] = $rating; + $block_params['count'] = isset($cache[$rating]) ? $cache[$rating] : 0; + $block_params['percent'] = round(($block_params['count'] / $total) * 100); + + $ret .= $this->Application->ParseBlock($block_params); + } + + return $ret; + } + + /** + * Returns requested field value + * + * @param Array $params + * @return string * @access public */ function Field($params) { $field = $this->SelectParam($params, 'name,field'); - + $object =& $this->getObject($params); /* @var $object kDBItem */ @@ -118,9 +171,11 @@ /* @var kDBList */ $parent_info = $object->getLinkedInfo(); + if ($parent_info['ParentId'] > 0) { $params['pass'] = 'm,'.$this->getPrefixSpecial().','.$parent_info['ParentPrefix']; } + return parent::PageLink($params); } Index: branches/5.2.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -N -r14753 -r14769 --- branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14753) +++ branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14769) @@ -1,6 +1,6 @@ Application->recallObject('kRewriteUrlProcessor'); + /* @var $rewrite_processor kRewriteUrlProcessor */ + + $ret = ''; + list ($prefix) = explode('.', $prefix_special); + $processed_params = $rewrite_processor->getProcessedParams($prefix_special, $params, $keep_events); + + if ($processed_params === false) { + return ''; + } + + if (!array_key_exists($prefix, $default_per_page)) { + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $default_per_page[$prefix] = $list_helper->getDefaultPerPage($prefix); + } + + if ($processed_params[$prefix_special . '_id']) { + return false; + } + else { + if ($processed_params[$prefix_special . '_Page'] == 1) { + // when printing category items and we are on the 1st page -> there is no information about + // category item prefix and $params['pass_category'] will not be added automatically + $params['pass_category'] = true; + } + elseif ($processed_params[$prefix_special . '_Page'] > 1) { + // $ret .= $processed_params[$prefix_special . '_Page'] . '/'; + $params['page'] = $processed_params[$prefix_special . '_Page']; + } + + $per_page = $processed_params[$prefix_special . '_PerPage']; + + if ($per_page && ($per_page != $default_per_page[$prefix])) { + $params['per_page'] = $processed_params[$prefix_special . '_PerPage']; + } + } + + return mb_strtolower( rtrim($ret, '/') ); + } + + /** * Returns item's filename that corresponds id passed. If possible, then get it from cache * * @param string $prefix Index: branches/5.2.x/core/units/reviews/reviews_config.php =================================================================== diff -u -N -r14726 -r14769 --- branches/5.2.x/core/units/reviews/reviews_config.php (.../reviews_config.php) (revision 14726) +++ branches/5.2.x/core/units/reviews/reviews_config.php (.../reviews_config.php) (revision 14769) @@ -1,6 +1,6 @@ 'mode', ), + 'RewriteListener' => 'CategoryItemRewrite:ReviewRewriteListener', + 'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too 'ConfigMapping' => Array ( 'PerPage' => 'Comm_Perpage_Reviews', @@ -58,17 +60,17 @@ 'CalculatedFields' => Array ( '' => Array ( - 'ReviewedBy' => 'IF( ISNULL(pu.Username), IF (%1$s.CreatedById = ' . USER_ROOT . ', \'root\', IF (%1$s.CreatedById = ' . USER_GUEST . ', \'Guest\', \'n/a\')), pu.Username )', + 'ReviewedBy' => 'CASE %1$s.CreatedById WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(pu.FirstName, pu.LastName) <> "", CONCAT(pu.FirstName, " ", pu.LastName), pu.Username) END', ), 'products' => Array ( - 'ReviewedBy' => 'IF( ISNULL(pu.Username), IF (%1$s.CreatedById = ' . USER_ROOT . ', \'root\', IF (%1$s.CreatedById = ' . USER_GUEST . ', \'Guest\', \'n/a\')), pu.Username )', + 'ReviewedBy' => 'CASE %1$s.CreatedById WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(pu.FirstName, pu.LastName) <> "", CONCAT(pu.FirstName, " ", pu.LastName), pu.Username) END', 'ItemName' => 'pr.l1_Name', 'ProductId' => 'pr.ProductId', ), 'product' => Array ( - 'ReviewedBy' => 'IF( ISNULL(pu.Username), IF (%1$s.CreatedById = ' . USER_ROOT . ', \'root\', IF (%1$s.CreatedById = ' . USER_GUEST . ', \'Guest\', \'n/a\')), pu.Username )', + 'ReviewedBy' => 'CASE %1$s.CreatedById WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(pu.FirstName, pu.LastName) <> "", CONCAT(pu.FirstName, " ", pu.LastName), pu.Username) END', 'ItemName' => 'pr.l1_Name', 'ProductId' => 'pr.ProductId', ), @@ -96,7 +98,7 @@ 'ListSortings' => Array ( '' => Array ( 'ForcedSorting' => Array ('Priority' => 'desc'), - 'Sorting' => Array ('CreatedOn' => 'desc'), + 'Sorting' => Array ('ReviewId' => 'desc'), ) ), Index: branches/5.2.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r14757 -r14769 --- branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14757) +++ branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 14769) @@ -1,6 +1,6 @@ Convert($value, 'PRIMARY', $iso); } - function AddCurrencySymbol($value, $iso) + function AddCurrencySymbol($value, $iso, $decimal_tag = '') { + static $decimal_separator = false; + $cache_key = 'iso_masks[%CurrSerial%]'; $iso_masks = $this->Application->getCache($cache_key); @@ -833,6 +835,18 @@ $this->Application->setCache($cache_key, $iso_masks); } + if ( $decimal_tag ) { + if ( $decimal_separator === false ) { + $language =& $this->Application->recallObject('lang.current'); + /* @var $language LanguagesItem */ + + $decimal_separator = $language->GetDBField('DecimalPoint'); + } + + list ($integer_part, $decimal_part) = explode($decimal_separator, $value); + $value = $integer_part . $decimal_separator . '<' . $decimal_tag . '>' . $decimal_part . ''; + } + $iso = strtolower($iso); return array_key_exists($iso, $iso_masks) ? sprintf($iso_masks[$iso], $value) : $value; @@ -886,7 +900,8 @@ } if (array_key_exists('currency', $params) && $params['currency']) { - $value = $this->AddCurrencySymbol($value, $iso); + $decimal_tag = isset($params['decimal_tag']) ? $params['decimal_tag'] : ''; + $value = $this->AddCurrencySymbol($value, $iso, $decimal_tag); $params['no_special'] = 1; } } Index: branches/5.2.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r14628 -r14769 --- branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14628) +++ branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14769) @@ -1,6 +1,6 @@ clearFilters(); $parent_info = $object->getLinkedInfo(); - + $parent =& $this->Application->recallObject($parent_info['ParentPrefix']); /* @var $parent kDBItem */ @@ -505,17 +505,36 @@ { parent::OnCreate($event); - if ($event->status != kEvent::erSUCCESS || $this->Application->isAdmin) { - return ; + if ( $event->status != kEvent::erSUCCESS || $this->Application->isAdmin ) { + return; } $object =& $event->getObject(); - $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template'; - $event->redirect = $this->Application->GetVar($next_template); - $event->SetRedirectParam('opener', 's'); + /* @var $object kDBItem */ - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $event->SetRedirectParam('pass', 'm,'.$parent_prefix); + if ( $this->Application->GetVar('ajax') == 'yes' ) { + $ajax_form_helper =& $this->Application->recallObject('AjaxFormHelper'); + /* @var $ajax_form_helper AjaxFormHelper */ + + $params = Array ('status' => 'OK'); + + if ( $event->status != kEvent::erSUCCESS ) { + $ajax_form_helper->prepareJSONErrors($event, $params); + } + + // let FormManager decide what template to show + $params['review_status'] = $object->GetDBField('Status'); + + $ajax_form_helper->sendResponse($event, $params); + } + else { + $event->SetRedirectParam('opener', 's'); + $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template'; + $event->redirect = $this->Application->GetVar($next_template); + + $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $event->SetRedirectParam('pass', 'm,'.$parent_prefix); + } } /** @@ -567,16 +586,16 @@ } return $title_field; } - + /** * Set's new perpage for Category Item Reviews (used on Front-end) * * @param kEvent $event */ function OnSetPerPage(&$event) { - parent::OnSetPerPage($event); - + parent::OnSetPerPage($event); + $parent_prefix = $event->Application->getUnitOption($event->Prefix, 'ParentPrefix'); $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial() . ',' . $parent_prefix); }