Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r8474 -r8481 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8474) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8481) @@ -1903,6 +1903,12 @@ { return $this->Prefix == $this->Application->GetTopmostPrefix($this->Prefix); } + + function PerPageSelected($params) + { + $list =& $this->GetList($params); + return $list->PerPage == $params['per_page'] ? $params['selected'] : ''; + } } ?> \ No newline at end of file Index: trunk/kernel/units/reviews/reviews_config.php =================================================================== diff -u -N -r8444 -r8481 --- trunk/kernel/units/reviews/reviews_config.php (.../reviews_config.php) (revision 8444) +++ trunk/kernel/units/reviews/reviews_config.php (.../reviews_config.php) (revision 8481) @@ -118,66 +118,71 @@ ), ), - // key - special, value - list select sql - 'ListSQLs' => Array( ''=>'SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + // key - special, value - list select sql + 'ListSQLs' => Array ( + '' => ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - 'products' => ' SELECT %1$s.* %2$s - FROM %1$s, '.TABLE_PREFIX.'Products pr - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + 'products' => ' SELECT %1$s.* %2$s + FROM %1$s, '.TABLE_PREFIX.'Products pr + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - 'product' => ' SELECT %1$s.* %2$s - FROM %1$s, '.TABLE_PREFIX.'Products pr - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - ), + 'product' => ' SELECT %1$s.* %2$s + FROM %1$s, '.TABLE_PREFIX.'Products pr + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + ), - 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'), + 'ItemSQLs' => Array ('' => 'SELECT * FROM %s'), - 'ListSortings' => Array( - '' => Array( - 'ForcedSorting' => Array('Priority' => 'desc'), - 'Sorting' => Array('CreatedOn' => 'desc'), - ) - ), + 'ListSortings' => Array ( + '' => Array( + 'ForcedSorting' => Array('Priority' => 'desc'), + 'Sorting' => Array('CreatedOn' => 'desc'), + ) + ), - 'Fields' => Array( - 'ReviewId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), - 'CreatedOn' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'default'=>'#NOW#'), - 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''), - 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''), - 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'CreatedById' => Array('type' => 'int', 'formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1), - 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>2 ), - 'TextFormat' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_text', 1 => 'la_html'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), - 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''), - ), - 'VirtualFields' => Array( - 'ReviewedBy' => Array(), - ), + 'Fields' => Array ( + 'ReviewId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + 'CreatedOn' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'default'=>'#NOW#'), + 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''), + 'Rating' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'lu_None', 1 => 'lu_Rating_1', 2 => 'lu_Rating_2', 3 => 'lu_Rating_3', 4 => 'lu_Rating_4', 5 => 'lu_Rating_5'), 'use_phrases' => 1, 'min_value_inc' => 0, 'max_value_inc' => 5, 'default' => 0), + 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''), + 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'CreatedById' => Array('type' => 'int', 'formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1), + 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>2 ), + 'TextFormat' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_text', 1 => 'la_html'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), + 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''), + ), - 'Grids' => Array( - 'Default' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), - 'Fields' => Array( - 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'), - 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), - 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), - 'Status' => Array( 'title'=>'la_col_Status' ), - ), + 'VirtualFields' => Array ( + 'ReviewedBy' => Array('type' => 'string', 'default' => ''), + ), - ), + 'Grids' => Array ( + 'Default' => Array ( + 'Icons' => Array ('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), + 'Fields' => Array ( + 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'), + 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), + 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), + 'Status' => Array( 'title'=>'la_col_Status' ), + 'Rating' => Array( 'title'=>'la_col_Rating' ), + ), + ), - 'ReviewsSection' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), - 'Fields' => Array( - 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'), - 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), - 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), - 'Status' => Array( 'title'=>'la_col_Status' ), - ), - - ), - ), + 'ReviewsSection' => Array ( + 'Icons' => Array ('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), + 'Fields' => Array ( + 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'), + 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), + 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), + 'Status' => Array( 'title'=>'la_col_Status' ), + ), + ), + ), ); ?> \ No newline at end of file Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r8428 -r8481 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8428) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8481) @@ -24,6 +24,14 @@ */ var $DirtyFieldValues = Array(); + /** + * Holds item values after loading (not affected by submit) + * + * @var Array + * @access private + */ + var $OriginalFieldValues = Array (); + var $FieldErrors; var $ErrorMsgs = Array(); @@ -69,6 +77,11 @@ return $this->DirtyFieldValues[$field_name]; } + function GetOriginalField($field_name) + { + return $this->OriginalFieldValues[$field_name]; + } + /** * Set's default values for all fields * @@ -288,9 +301,9 @@ if($field_values) { $this->FieldValues = array_merge_recursive2($this->FieldValues, $field_values); + $this->OriginalFieldValues = $this->FieldValues; } - else - { + else { return $this->Clear(); } @@ -944,6 +957,7 @@ $this->setID($new_id); $this->Loaded = false; $this->FieldValues = Array(); + $this->OriginalFieldValues = Array (); $this->SetDefaultValues(); $this->FieldErrors = Array(); return $this->Loaded; Index: trunk/admin/install/upgrades/inportal_upgrade_v4.1.1.sql =================================================================== diff -u -N --- trunk/admin/install/upgrades/inportal_upgrade_v4.1.1.sql (revision 0) +++ trunk/admin/install/upgrades/inportal_upgrade_v4.1.1.sql (revision 8481) @@ -0,0 +1,3 @@ +ALTER TABLE ItemReview ADD Rating TINYINT UNSIGNED AFTER ReviewText; + +UPDATE Modules SET Version = '4.1.1' WHERE Name = 'In-Portal'; \ No newline at end of file Index: trunk/admin/install/inportal_schema.sql =================================================================== diff -u -N -r8029 -r8481 --- trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 8029) +++ trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 8481) @@ -75,6 +75,7 @@ ReviewId int(11) NOT NULL auto_increment, CreatedOn INT UNSIGNED NULL DEFAULT NULL, ReviewText longtext NOT NULL, + Rating tinyint(3) unsigned default NULL, IPAddress varchar(255) NOT NULL default '', ItemId int(11) NOT NULL default '0', CreatedById int(11) NOT NULL default '-1', Index: trunk/kernel/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r8444 -r8481 --- trunk/kernel/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8444) +++ trunk/kernel/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8481) @@ -101,7 +101,7 @@ } if ($event->getEventParam('type') == 'current_user') { - $object->removeFilter('active'); +// $object->removeFilter('active'); $object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id')); $object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"'); } @@ -148,15 +148,20 @@ */ function OnBeforeItemCreate(&$event) { - if ($this->Application->IsAdmin()) { - return ; - } - $object =& $event->getObject(); /* @var $object kDBItem */ $parent_info = $object->getLinkedInfo(); + $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); + $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); + $object->SetDBField('ItemType', $item_type); + $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); + + if ($this->Application->IsAdmin()) { + return ; + } + $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ @@ -168,25 +173,41 @@ return ; } - $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); + $rating = $object->GetDBField('Rating'); + if ($rating < 1 || $rating > 5) { + $object->SetDBField('Rating', null); + } - $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); $object->SetDBField('ItemId', $parent_info['ParentId']); // ResourceId $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); - $object->SetDBField('ItemType', $item_type); + $object->SetDBField('Status', $this->getReviewStatus($event)); $object->SetDBField('TextFormat', 0); // set plain text format directly - $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); } /** + * Sets correct rating value + * + * @param kEvent $event + */ + function OnBeforeItemUpdate(&$event) + { + $object =& $event->getObject(); + + $rating = $object->GetDBField('Rating'); + if (!$rating) { + $object->SetDBField('Rating', null); + } + } + + /** * Updates item review counter * * @param kEvent $event */ function OnAfterItemCreate(&$event) { - $this->updateReviewsCounter($event); + $this->updateSubitemCounters($event); if (!$this->Application->IsAdmin()) { $spam_helper =& $this->Application->recallObject('SpamHelper'); @@ -203,13 +224,24 @@ } } + /** - * Updates total review counter + * Updates item review counter * * @param kEvent $event */ - function updateReviewsCounter(&$event) + function OnAfterItemUpdate(&$event) { + $this->updateSubitemCounters($event); + } + + /** + * Updates total review counter, cached rating, votes count + * + * @param kEvent $event + */ + function updateSubitemCounters(&$event) + { $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); $main_object =& $this->Application->recallObject($parent_prefix, null, Array ('raise_warnings' => 0)); /* @var $main_object kCatDBItem */ @@ -220,24 +252,72 @@ } $object =& $event->getObject(); // for temp tables + /* @var $object kDBItem */ + // 1. update review counter $sql = 'SELECT COUNT(ReviewId) FROM '.$object->TableName.' WHERE ItemId = '.$main_object->GetDBField('ResourceId'); $review_count = $this->Conn->GetOne($sql); $main_object->SetDBField('CachedReviewsQty', $review_count); + + // 2. update votes counter + rating + $rating = $object->GetDBField('Rating'); + $avg_rating = $main_object->GetDBField('CachedRating'); + $votes_count = $main_object->GetDBField('CachedVotesQty'); + + switch ($event->Name) { + case 'OnAfterItemCreate': // adding new review with rating + $this->changeRating($avg_rating, $votes_count, $rating, '+'); + break; + + case 'OnAfterItemDelete': + $this->changeRating($avg_rating, $votes_count, $rating, '-'); + break; + + case 'OnAfterItemUpdate': + $this->changeRating($avg_rating, $votes_count, $object->GetOriginalField('Rating'), '-'); + $this->changeRating($avg_rating, $votes_count, $rating, '+'); + break; + } + $main_object->SetDBField('CachedRating', $avg_rating); + $main_object->SetDBField('CachedVotesQty', $votes_count); $main_object->Update(); } + /** + * Changes average rating and votes count based on requested operation + * + * @param float $avg_rating average rating before new vote + * @param int $votes_count votes count before new vote + * @param int $rating new vote (from 1 to 5) + * @param string $operation requested operation (+ / -) + */ + function changeRating(&$avg_rating, &$votes_count, $rating, $operation) + { + if ($rating < 1 || $rating > 5) { + return ; + } + if ($operation == '+') { + $avg_rating = (($avg_rating * $votes_count) + $rating) / ($votes_count + 1); + ++$votes_count; + } + else { + $avg_rating = (($avg_rating * $votes_count) - $rating) / ($votes_count - 1); + --$votes_count; + } + } + + /** * Updates main item cached review counter * * @param kEvent $event */ function OnAfterItemDelete(&$event) { - $this->updateReviewsCounter($event); + $this->updateSubitemCounters($event); } /** Index: trunk/core/units/general/cat_tag_processor.php =================================================================== diff -u -N -r8472 -r8481 --- trunk/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 8472) +++ trunk/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 8481) @@ -317,12 +317,6 @@ if ($sorting == strtolower($params['sorting'])) return $params['selected']; } - function PerPageSelected($params) - { - $list =& $this->GetList($params); - return $list->PerPage == $params['per_page'] ? $params['selected'] : ''; - } - /** * Prepares name for field with event in it (used only on front-end) * Index: trunk/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N -r8478 -r8481 --- trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 8478) +++ trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 8481) @@ -587,12 +587,6 @@ return $perm_helper->TagPermissionCheck($params, $this->getPrefixSpecial().'_HasPermission'); } - function PerPageSelected($params) - { - $list =& $this->GetList($params); - return $list->PerPage == $params['per_page'] ? $params['selected'] : ''; - } - /** * Prepares name for field with event in it (used only on front-end) * Index: trunk/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r8444 -r8481 --- trunk/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8444) +++ trunk/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8481) @@ -101,7 +101,7 @@ } if ($event->getEventParam('type') == 'current_user') { - $object->removeFilter('active'); +// $object->removeFilter('active'); $object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id')); $object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"'); } @@ -148,15 +148,20 @@ */ function OnBeforeItemCreate(&$event) { - if ($this->Application->IsAdmin()) { - return ; - } - $object =& $event->getObject(); /* @var $object kDBItem */ $parent_info = $object->getLinkedInfo(); + $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); + $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); + $object->SetDBField('ItemType', $item_type); + $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); + + if ($this->Application->IsAdmin()) { + return ; + } + $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ @@ -168,25 +173,41 @@ return ; } - $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); + $rating = $object->GetDBField('Rating'); + if ($rating < 1 || $rating > 5) { + $object->SetDBField('Rating', null); + } - $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); $object->SetDBField('ItemId', $parent_info['ParentId']); // ResourceId $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); - $object->SetDBField('ItemType', $item_type); + $object->SetDBField('Status', $this->getReviewStatus($event)); $object->SetDBField('TextFormat', 0); // set plain text format directly - $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); } /** + * Sets correct rating value + * + * @param kEvent $event + */ + function OnBeforeItemUpdate(&$event) + { + $object =& $event->getObject(); + + $rating = $object->GetDBField('Rating'); + if (!$rating) { + $object->SetDBField('Rating', null); + } + } + + /** * Updates item review counter * * @param kEvent $event */ function OnAfterItemCreate(&$event) { - $this->updateReviewsCounter($event); + $this->updateSubitemCounters($event); if (!$this->Application->IsAdmin()) { $spam_helper =& $this->Application->recallObject('SpamHelper'); @@ -203,13 +224,24 @@ } } + /** - * Updates total review counter + * Updates item review counter * * @param kEvent $event */ - function updateReviewsCounter(&$event) + function OnAfterItemUpdate(&$event) { + $this->updateSubitemCounters($event); + } + + /** + * Updates total review counter, cached rating, votes count + * + * @param kEvent $event + */ + function updateSubitemCounters(&$event) + { $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); $main_object =& $this->Application->recallObject($parent_prefix, null, Array ('raise_warnings' => 0)); /* @var $main_object kCatDBItem */ @@ -220,24 +252,72 @@ } $object =& $event->getObject(); // for temp tables + /* @var $object kDBItem */ + // 1. update review counter $sql = 'SELECT COUNT(ReviewId) FROM '.$object->TableName.' WHERE ItemId = '.$main_object->GetDBField('ResourceId'); $review_count = $this->Conn->GetOne($sql); $main_object->SetDBField('CachedReviewsQty', $review_count); + + // 2. update votes counter + rating + $rating = $object->GetDBField('Rating'); + $avg_rating = $main_object->GetDBField('CachedRating'); + $votes_count = $main_object->GetDBField('CachedVotesQty'); + + switch ($event->Name) { + case 'OnAfterItemCreate': // adding new review with rating + $this->changeRating($avg_rating, $votes_count, $rating, '+'); + break; + + case 'OnAfterItemDelete': + $this->changeRating($avg_rating, $votes_count, $rating, '-'); + break; + + case 'OnAfterItemUpdate': + $this->changeRating($avg_rating, $votes_count, $object->GetOriginalField('Rating'), '-'); + $this->changeRating($avg_rating, $votes_count, $rating, '+'); + break; + } + $main_object->SetDBField('CachedRating', $avg_rating); + $main_object->SetDBField('CachedVotesQty', $votes_count); $main_object->Update(); } + /** + * Changes average rating and votes count based on requested operation + * + * @param float $avg_rating average rating before new vote + * @param int $votes_count votes count before new vote + * @param int $rating new vote (from 1 to 5) + * @param string $operation requested operation (+ / -) + */ + function changeRating(&$avg_rating, &$votes_count, $rating, $operation) + { + if ($rating < 1 || $rating > 5) { + return ; + } + if ($operation == '+') { + $avg_rating = (($avg_rating * $votes_count) + $rating) / ($votes_count + 1); + ++$votes_count; + } + else { + $avg_rating = (($avg_rating * $votes_count) - $rating) / ($votes_count - 1); + --$votes_count; + } + } + + /** * Updates main item cached review counter * * @param kEvent $event */ function OnAfterItemDelete(&$event) { - $this->updateReviewsCounter($event); + $this->updateSubitemCounters($event); } /** Index: trunk/core/units/reviews/reviews_config.php =================================================================== diff -u -N -r8444 -r8481 --- trunk/core/units/reviews/reviews_config.php (.../reviews_config.php) (revision 8444) +++ trunk/core/units/reviews/reviews_config.php (.../reviews_config.php) (revision 8481) @@ -118,66 +118,71 @@ ), ), - // key - special, value - list select sql - 'ListSQLs' => Array( ''=>'SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + // key - special, value - list select sql + 'ListSQLs' => Array ( + '' => ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - 'products' => ' SELECT %1$s.* %2$s - FROM %1$s, '.TABLE_PREFIX.'Products pr - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + 'products' => ' SELECT %1$s.* %2$s + FROM %1$s, '.TABLE_PREFIX.'Products pr + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - 'product' => ' SELECT %1$s.* %2$s - FROM %1$s, '.TABLE_PREFIX.'Products pr - LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', - ), + 'product' => ' SELECT %1$s.* %2$s + FROM %1$s, '.TABLE_PREFIX.'Products pr + LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById', + ), - 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'), + 'ItemSQLs' => Array ('' => 'SELECT * FROM %s'), - 'ListSortings' => Array( - '' => Array( - 'ForcedSorting' => Array('Priority' => 'desc'), - 'Sorting' => Array('CreatedOn' => 'desc'), - ) - ), + 'ListSortings' => Array ( + '' => Array( + 'ForcedSorting' => Array('Priority' => 'desc'), + 'Sorting' => Array('CreatedOn' => 'desc'), + ) + ), - 'Fields' => Array( - 'ReviewId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), - 'CreatedOn' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'default'=>'#NOW#'), - 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''), - 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''), - 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'CreatedById' => Array('type' => 'int', 'formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1), - 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0), - 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>2 ), - 'TextFormat' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_text', 1 => 'la_html'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), - 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''), - ), - 'VirtualFields' => Array( - 'ReviewedBy' => Array(), - ), + 'Fields' => Array ( + 'ReviewId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + 'CreatedOn' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'default'=>'#NOW#'), + 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''), + 'Rating' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'lu_None', 1 => 'lu_Rating_1', 2 => 'lu_Rating_2', 3 => 'lu_Rating_3', 4 => 'lu_Rating_4', 5 => 'lu_Rating_5'), 'use_phrases' => 1, 'min_value_inc' => 0, 'max_value_inc' => 5, 'default' => 0), + 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''), + 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'CreatedById' => Array('type' => 'int', 'formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1), + 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>2 ), + 'TextFormat' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_text', 1 => 'la_html'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), + 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''), + ), - 'Grids' => Array( - 'Default' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), - 'Fields' => Array( - 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'), - 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), - 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), - 'Status' => Array( 'title'=>'la_col_Status' ), - ), + 'VirtualFields' => Array ( + 'ReviewedBy' => Array('type' => 'string', 'default' => ''), + ), - ), + 'Grids' => Array ( + 'Default' => Array ( + 'Icons' => Array ('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), + 'Fields' => Array ( + 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'), + 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), + 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), + 'Status' => Array( 'title'=>'la_col_Status' ), + 'Rating' => Array( 'title'=>'la_col_Rating' ), + ), + ), - 'ReviewsSection' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), - 'Fields' => Array( - 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'), - 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), - 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), - 'Status' => Array( 'title'=>'la_col_Status' ), - ), - - ), - ), + 'ReviewsSection' => Array ( + 'Icons' => Array ('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'), + 'Fields' => Array ( + 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'), + 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ), + 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ), + 'Status' => Array( 'title'=>'la_col_Status' ), + ), + ), + ), ); ?> \ No newline at end of file