Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Fri, Nov 21, 3:25 PM

in-portal

Index: trunk/kernel/units/reviews/reviews_config.php
===================================================================
--- trunk/kernel/units/reviews/reviews_config.php (revision 8440)
+++ trunk/kernel/units/reviews/reviews_config.php (revision 8441)
@@ -1,156 +1,171 @@
<?php
$config = Array (
'Prefix' => 'rev',
-
+
'Clones' => Array (
'l-rev' => Array(
'ParentPrefix' => 'l',
'ConfigMapping' => Array (
'PerPage' => 'Perpage_LinkReviews',
'ShortListPerPage' => 'Perpage_LinkReviews_Short',
'DefaultSorting1Field' => 'Link_ReviewsSort',
'DefaultSorting2Field' => 'Link_ReviewsSort2',
'DefaultSorting1Dir' => 'Link_ReviewsOrder',
'DefaultSorting2Dir' => 'Link_ReviewsOrder2',
+
+ 'ReviewDelayInterval' => 'link_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'link_ReviewDelay_Value',
),
),
-
+
'n-rev' => Array (
'ParentPrefix' => 'n',
'ConfigMapping' => Array (
'PerPage' => 'Perpage_NewsReviews',
'ShortListPerPage' => 'Perpage_NewsReviews_Short',
'DefaultSorting1Field' => 'News_SortReviews',
'DefaultSorting2Field' => 'News_SortReviews2',
'DefaultSorting1Dir' => 'News_SortReviewsOrder',
'DefaultSorting2Dir' => 'News_SortReviewsOrder2',
+
+ 'ReviewDelayInterval' => 'News_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'News_ReviewDelay_Value',
),
),
-
- 'bb-rev'=> Array(
- 'ParentPrefix' => 'bb',
+
+ 'bb-rev' => Array (
+ 'ParentPrefix' => 'bb',
+
+ 'ReviewDelayInterval' => 'topic_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'topic_ReviewDelay_Value',
),
- /*'p-rev' => Array('ParentPrefix' => 'p'),*/
+
+ 'p-rev' => Array (
+ 'ParentPrefix' => 'p',
+
+ 'ReviewDelayInterval' => 'product_ReviewDelay_Value',
+ 'ReviewDelayValue' => 'product_ReviewDelay_Interval',
+ ),
),
-
+
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'ReviewsEventHandler','file'=>'reviews_event_handler.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'ReviewsTagProcessor','file'=>'reviews_tag_processor.php','build_event'=>'OnBuild'),
'AutoLoad' => true,
-
+
'QueryString' => Array (
1 => 'id',
2 => 'Page',
3 => 'event',
4 => 'mode',
),
-
+
'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too
-
+
'IDField' => 'ReviewId',
'StatusField' => Array('Status'), // field, that is affected by Approve/Decline events
'TableName' => TABLE_PREFIX.'ItemReview',
'ParentTableKey' => 'ResourceId', // linked field in master table
'ForeignKey' => 'ItemId', // linked field in subtable
-
+
'AutoDelete' => true,
'AutoClone' => true,
-
+
'TitlePresets' => Array (
'reviews_edit' => Array('format' => "!la_title_Editing_Review!"),
),
-
+
'FilterMenu' => Array (
'Groups' => Array(
Array('mode' => 'AND', 'filters' => Array('show_active','show_pending','show_disabled'), 'type' => WHERE_FILTER),
),
'Filters' => Array(
'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ),
'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => '%1$s.Status != 2' ),
'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ),
)
),
'CalculatedFields' => Array (
'' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
),
-
+
'products' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
'ItemName' => 'pr.l1_Name',
'ProductId' => 'pr.ProductId',
),
-
+
'product' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
'ItemName' => 'pr.l1_Name',
'ProductId' => 'pr.ProductId',
),
),
// 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',
'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'),
'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','not_null'=>1,'default'=>0),
+ '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(),
),
'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' ),
),
),
'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
Property changes on: trunk/kernel/units/reviews/reviews_config.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.10
\ No newline at end of property
+1.11
\ No newline at end of property
Index: trunk/kernel/units/reviews/reviews_tag_processor.php
===================================================================
--- trunk/kernel/units/reviews/reviews_tag_processor.php (revision 8440)
+++ trunk/kernel/units/reviews/reviews_tag_processor.php (revision 8441)
@@ -1,123 +1,96 @@
<?php
class ReviewsTagProcessor extends kDBTagProcessor
{
/**
* Returns a link for editing product
*
* @param Array $params
* @return string
*/
function ItemEditLink($params)
{
$item_prefix = $params['item_prefix'];
$id_field = $this->Application->getUnitOption($item_prefix,'IDField');
$object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$item_id = $object->GetDBField($id_field);
return $this->Application->HREF($params['edit_template'],'', Array(
'm_opener' => 'd',
$item_prefix.'_mode' => 't',
$item_prefix.'_event' => 'OnEdit',
$item_prefix.'_id' => $item_id,
'pass' => 'all,'.$item_prefix
), 'index.php');
}
/**
* Get's reuested field value
*
* @param Array $params
* @return string
* @access public
*/
function Field($params)
{
$field = $this->SelectParam($params, 'name,field');
$object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
if ($field == 'ReviewText') {
if ($object->GetDBField('TextFormat') == 1) {
$params['no_special'] = 'no_special';
}
else {
unset($params['no_special']);
}
}
return parent::Field($params);
-
}
function AlreadyReviewed($params)
{
- $user_id = $this->getUserID();
$object =& $this->getObject( Array('skip_autoload' => true) );
- $product_info = $object->getLinkedInfo();
+ $parent_info = $object->getLinkedInfo();
- $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
- WHERE ItemResourceId='.$product_info['ParentId'].'
- AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
- AND PortalUserId='.$user_id.'
- AND DataType="Review"';
- $res = $this->Conn->GetRow($sql);
- if($res['Expire'] > adodb_mktime())
- {
- $ret = 1;
- }
- else
- {
- $sql = 'DELETE FROM '.TABLE_PREFIX.'SpamControl
- WHERE ItemResourceId='.$product_info['ParentId'].'
- AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
- AND PortalUserId='.$user_id.'
- AND DataType="Review"';
- $this->Conn->Query($sql);
- $ret = 0;
- }
- return $ret;
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
+
+ return $spam_helper->InSpamControl();
}
function HasError($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
if (method_exists($object, 'GetErrorMsg')) {
return parent::HasError($params);
}
else {
return 0;
}
}
-
+
/**
- * Returns current user id for reviews, for logic ask Kostja T.
+ * Preserve main item id in subitem pagination url
*
- * @return int
+ * @param Array $params
+ * @return string
*/
- function getUserID()
- {
- $user_id = $this->Application->RecallVar('user_id');
-
- if ($user_id == 0) {
- $user_id = -2;
- }
-
- return $user_id;
- }
-
function PageLink($params)
{
$object =& $this->getObject($params);
/* @var kDBList */
-
+
$parent_info = $object->getLinkedInfo();
if ($parent_info['ParentId'] > 0) {
$params['pass'] = 'm,'.$this->getPrefixSpecial().','.$parent_info['ParentPrefix'];
}
return parent::PageLink($params);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/reviews/reviews_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.7
\ No newline at end of property
+1.8
\ No newline at end of property
Index: trunk/kernel/units/reviews/reviews_event_handler.php
===================================================================
--- trunk/kernel/units/reviews/reviews_event_handler.php (revision 8440)
+++ trunk/kernel/units/reviews/reviews_event_handler.php (revision 8441)
@@ -1,210 +1,349 @@
<?php
class ReviewsEventHandler extends kDBEventHandler
{
/**
- * Checks permissions of user
+ * Checks REVIEW/REVIEW.PENDING permission by main object primary category (not current category)
*
* @param kEvent $event
*/
function CheckPermission(&$event)
{
- if ($event->Name == 'OnAddReview') {
- $item_prefix = $this->getPermPrefix($event);
- $res = $this->Application->CheckPermission($item_prefix.'.REVIEW.PENDING', 0) || $this->Application->CheckPermission($item_prefix.'.REVIEW', 0);
+ if ($event->Name == 'OnAddReview' || $event->Name == 'OnCreate') {
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+
+ $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
+ $main_object =& $this->Application->recallObject($parent_prefix);
+ /* @var $main_object kCatDBItem */
+
+ $perm_name = $this->getPermPrefix($event).'.REVIEW';
+ $res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) ||
+ $this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'));
+
if (!$res) {
$event->status = erPERM_FAIL;
}
return $res;
}
return parent::CheckPermission($event);
}
/**
* Returns prefix for permissions
*
* @param kEvent $event
*/
function getPermPrefix(&$event)
{
$main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
// this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
$item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
return $item_prefix;
}
-
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
-
+
if (!$this->Application->IsAdmin()) {
$object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE);
}
-
+
switch ($event->Special)
{
case 'showall':
$object->clearFilters();
break;
case 'item':
$object->clearFilters();
$info = $object->getLinkedInfo();
$this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
$parent =& $this->Application->recallObject($info['ParentPrefix']);
$object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
break;
case 'products':
$object->removeFilter('parent_filter'); // this is important
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
break;
-
+
case 'product':
$object->clearFilters();
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
$this->Application->setUnitOption('p', 'AutoLoad', true);
$product =& $this->Application->recallObject('p');
$object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
break;
}
if ($event->getEventParam('type') == 'current_user') {
$user_id = $this->getUserID();
$ip = $_SERVER['REMOTE_ADDR'];
$object =& $event->getObject( Array('skip_autoload' => true) );
$product_info = $object->getLinkedInfo();
$object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
$object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
$object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
}
}
/**
* Adds review from front in case if user is logged in
*
* @param kEvent $event
*/
function OnAddReview(&$event)
{
$user_id = $this->getUserID();
$event->redirect_params = Array('pass' => 'all,p');
$object =& $event->getObject( Array('skip_autoload' => true) );
$parent_info = $object->getLinkedInfo();
$review_fields = $this->Application->GetVar($event->getPrefixSpecial(true));
$sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
WHERE ItemResourceId='.$parent_info['ParentId'].'
AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
AND PortalUserId='.$user_id.'
AND DataType="Review"';
$res = $this->Conn->GetRow($sql);
if( $res && $res['Expire'] < adodb_mktime() )
{
$sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
WHERE ItemResourceId='.$parent_info['ParentId'].'
AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
AND PortalUserId='.$user_id.'
AND DataType="Review"';
$this->Conn->Query($sql);
unset($res);
}
if(!$res)
{
$object->SetFieldsFromHash( array_shift($review_fields) );
$object->SetDBField('CreatedById', $user_id);
$object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
$object->SetDBField('CreatedOn', adodb_mktime());
$module_info = $this->Application->findModule('Var',$parent_info['ParentPrefix']);
$object->SetDBField('Module', $module_info['Name']);
if( $this->Application->CheckPermission( $this->getPermPrefix($event).'.REVIEW.PENDING', 0) )
{
$object->SetDBField('Status', 2);
$template_var = 'success_pending_template';
}
if( $this->Application->CheckPermission($this->getPermPrefix($event).'.REVIEW', 0) )
{
$object->SetDBField('Status', 1);
$template_var = 'success_template';
}
$object->SetDBField('ItemId', $parent_info['ParentId']);
$event->CallSubEvent('OnCreate');
if($event->status == erSUCCESS)
{
$parent =& $this->Application->recallObject($parent_info['ParentPrefix']);
$sql = ' SELECT COUNT(ReviewId)
FROM '.$object->TableName.'
WHERE ItemId='.$parent_info['ParentId'];
$review_qty = $this->Conn->GetOne($sql);
$parent->SetDBField('CachedReviewsQty', $review_qty);
$parent->Update();
$expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
$sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
(ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
VALUES ('.$parent_info['ParentId'].',
"'.$_SERVER['REMOTE_ADDR'].'",
'.$user_id.',
"Review",
'.$expire.')';
$this->Conn->Query($sql);
$event->redirect_params = Array('pass' => 'all,'.$parent_info['ParentPrefix']);
$event->redirect = $this->Application->GetVar($template_var);
}
}
else
{
// $this->Application->removeObject($event->getPrefixSpecial());
$event->status == erFAIL;
$event->redirect=false;
$object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
$object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
}
}
/**
- * Enter description here...
+ * Get new review status on user review permission
+ *
+ * @param kEvent $event
+ * @return int
+ */
+ function getReviewStatus(&$event)
+ {
+ $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
+ $main_object =& $this->Application->recallObject($parent_prefix);
+ /* @var $main_object kCatDBItem */
+
+ $ret = STATUS_DISABLED;
+ $perm_name = $this->getPermPrefix($event).'.REVIEW';
+ if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) {
+ $ret = STATUS_ACTIVE;
+ }
+ else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) {
+ $ret = STATUS_PENDING;
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Prefills all fields on front-end
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
+ if ($this->Application->IsAdmin()) {
+ return ;
+ }
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $parent_info = $object->getLinkedInfo();
+
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
+
+ if ($spam_helper->InSpamControl()) {
+ $event->status = erFAIL;
+ $object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate');
+ return ;
+ }
+
+ $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
+
+ $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'));
+ }
+
+ /**
+ * Updates item review counter
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $this->updateReviewsCounter($event);
+
+ if (!$this->Application->IsAdmin()) {
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $object =& $event->getObject();
+ $parent_info = $object->getLinkedInfo($event->Special);
+
+ $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
+ $review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval'];
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings);
+
+ $spam_helper->AddToSpamControl();
+ }
+ }
+
+ /**
+ * Updates total review counter
+ *
+ * @param kEvent $event
+ */
+ function updateReviewsCounter(&$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 */
+
+ if (!$main_object->isLoaded()) {
+ // deleting main item / cloning main item
+ return ;
+ }
+
+ $object =& $event->getObject(); // for temp tables
+
+ $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);
+ $main_object->Update();
+ }
+
+
+ /**
+ * Updates main item cached review counter
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemDelete(&$event)
+ {
+ $this->updateReviewsCounter($event);
+ }
+
+ /**
+ * Creates review & redirect to confirmation template
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ parent::OnCreate($event);
+
+ if ($event->status != erSUCCESS || $this->Application->IsAdmin()) {
+ return ;
+ }
+
$object =& $event->getObject();
- $object->SetDBField('Module', $this->Application->findModule('Var',$this->Application->getUnitOption($this->Prefix, 'ParentPrefix'), 'Name'));
+ $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template';
+ $event->redirect = $this->Application->GetVar($next_template);
+ $event->SetRedirectParam('opener', 's');
}
/**
* Returns current user id for reviews, for logic ask Kostja T.
*
* @return int
*/
function getUserID()
{
$user_id = $this->Application->RecallVar('user_id');
if ($user_id == 0) {
$user_id = -2;
}
return $user_id;
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/reviews/reviews_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property
Index: trunk/themes/default2007/platform/my_account/my_profile.tpl
===================================================================
--- trunk/themes/default2007/platform/my_account/my_profile.tpl (revision 8440)
+++ trunk/themes/default2007/platform/my_account/my_profile.tpl (revision 8441)
@@ -1,58 +1,58 @@
<inp2:m_DefineElement name="sidebar">
<inp2:m_RenderElements
elements="
platform/elements/side_boxes/login,
"
design="blue_box"/>
</inp2:m_DefineElement>
<inp2:m_DefineElement name="content">
<!-- my profile -->
<inp2:m_DefineElement name="users_content">
<inp2:m_DefineElement name="header">
<inp2:m_phrase name="lu_title_MyProfile"/>
</inp2:m_DefineElement>
<inp2:m_RenderElement name="header" strip_nl="2" result_to_var="header"/>
<inp2:m_if check="u_HasError" field="any">
- <span class="error">There is a problem with the form, please check the error messages below.</span><br />
+ <span class="error"><inp2:m_phrase name="lu_AProblemInForm"/></span><br />
</inp2:m_if>
<span class="error">*</span> <inp2:m_phrase name="lu_IndicatesRequired"/><br />
<form method="post" action="<inp2:m_FormAction/>">
<table class="form-data">
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Login" title="lu_fld_Login"/>
<inp2:m_if check="m_ConfigEquals" name="User_Password_Auto" value="0">
<inp2:m_RenderElement name="inp_edit_password" prefix="u" field="Password" title="lu_fld_Password"/>
<inp2:m_RenderElement name="inp_edit_password" prefix="u" field="VerifyPassword" title="lu_fld_VerifyPassword"/>
</inp2:m_if>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="FirstName" title="lu_fld_FirstName"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="LastName" title="lu_fld_LastName"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Company" title="lu_fld_Company"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Phone" title="lu_fld_Phone"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Fax" title="lu_fld_Fax"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Email" title="lu_fld_Email"/>
<inp2:m_RenderElement name="inp_edit_date" prefix="u" field="dob" title="lu_fld_BirthDate"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Street" title="lu_fld_AddressLine1"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Street2" title="lu_fld_AddressLine2"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="City" title="lu_fld_City"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="State" title="lu_fld_State"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Zip" title="lu_fld_Zip"/>
<inp2:m_RenderElement name="inp_edit_options" prefix="u" field="Country" title="lu_fld_Country"/>
<tr>
<td colspan="3" valign="bottom" height="35">
<input class="button" type="submit" name="events[u][OnUpdate]" value="<inp2:m_Phrase label="lu_btn_Update"/>"/>
</td>
</tr>
</table>
</form>
</inp2:m_DefineElement>
<inp2:m_RenderElement name="users_content" design="content_box"/>
<!-- // my profile -->
</inp2:m_DefineElement>
<inp2:m_include template="platform/designs/default_design" pass_params="1"/>
\ No newline at end of file
Property changes on: trunk/themes/default2007/platform/my_account/my_profile.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/themes/default2007/platform/login/register.tpl
===================================================================
--- trunk/themes/default2007/platform/login/register.tpl (revision 8440)
+++ trunk/themes/default2007/platform/login/register.tpl (revision 8441)
@@ -1,63 +1,63 @@
<inp2:m_DefineElement name="sidebar">
- <inp2:m_RenderElements
+ <inp2:m_RenderElements
elements="
platform/elements/side_boxes/login,
"
design="blue_box"/>
</inp2:m_DefineElement>
<inp2:m_DefineElement name="content">
<!-- phrases -->
<inp2:m_DefineElement name="users_content">
<inp2:m_DefineElement name="header">
<inp2:m_phrase name="lu_title_UserRegistration"/>
</inp2:m_DefineElement>
<inp2:m_RenderElement name="header" strip_nl="2" result_to_var="header"/>
-
- <inp2:u_PresetFormFields/>
+
+ <inp2:u_PresetFormFields/>
<inp2:m_if check="u_HasError" field="any">
- <span class="error">There is a problem with the form, please check the error messages below.</span><br />
+ <span class="error"><inp2:m_phrase name="lu_AProblemInForm"/></span><br />
</inp2:m_if>
<span class="error">*</span> <inp2:m_phrase name="lu_IndicatesRequired"/><br />
<form method="post" action="<inp2:m_FormAction/>">
<table class="form-data">
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Login" title="lu_fld_Login"/>
-
+
<inp2:m_if check="m_ConfigEquals" name="User_Password_Auto" value="0">
- <inp2:m_RenderElement name="inp_edit_password" prefix="u" field="Password" title="lu_fld_Password"/>
- <inp2:m_RenderElement name="inp_edit_password" prefix="u" field="VerifyPassword" title="lu_fld_VerifyPassword"/>
+ <inp2:m_RenderElement name="inp_edit_password" prefix="u" field="Password" title="lu_fld_Password"/>
+ <inp2:m_RenderElement name="inp_edit_password" prefix="u" field="VerifyPassword" title="lu_fld_VerifyPassword"/>
</inp2:m_if>
-
+
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="FirstName" title="lu_fld_FirstName"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="LastName" title="lu_fld_LastName"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Company" title="lu_fld_Company"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Phone" title="lu_fld_Phone"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Fax" title="lu_fld_Fax"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Email" title="lu_fld_Email"/>
<inp2:m_RenderElement name="inp_edit_date" prefix="u" field="dob" title="lu_fld_BirthDate"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Street" title="lu_fld_AddressLine1"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Street2" title="lu_fld_AddressLine2"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="City" title="lu_fld_City"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="State" title="lu_fld_State"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Zip" title="lu_fld_Zip"/>
<inp2:m_RenderElement name="inp_edit_options" prefix="u" field="Country" title="lu_fld_Country"/>
-
+
<tr>
<td colspan="3" valign="bottom" height="35">
<input type="hidden" name="next_template" value="<inp2:m_get var="next_template"/>" />
<input type="hidden" name="registration_confirm_template" value="platform/login/register_confirm" />
<input type="hidden" name="registration_confirm_pending_template" value="platform/login/register_confirm_pending" />
<input class="button" type="submit" name="events[u][OnCreate]" value="<inp2:m_Phrase label="lu_btn_Create"/>"/>
</td>
</tr>
</table>
</form>
</inp2:m_DefineElement>
-
+
<inp2:m_RenderElement name="users_content" design="content_box"/>
<!-- // phrases -->
</inp2:m_DefineElement>
<inp2:m_include template="platform/designs/default_design" pass_params="1"/>
\ No newline at end of file
Property changes on: trunk/themes/default2007/platform/login/register.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/themes/default2007/phrases_edit.tpl
===================================================================
--- trunk/themes/default2007/phrases_edit.tpl (revision 8440)
+++ trunk/themes/default2007/phrases_edit.tpl (revision 8441)
@@ -1,47 +1,47 @@
<inp2:m_DefineElement name="sidebar">
- <inp2:m_RenderElements
+ <inp2:m_RenderElements
elements="
platform/elements/side_boxes/login,
platform/elements/side_boxes/search,
"
design="blue_box"/>
</inp2:m_DefineElement>
<inp2:m_DefineElement name="content">
<!-- phrases -->
<inp2:m_DefineElement name="pharses_content">
<inp2:m_DefineElement name="header1">
<inp2:m_phrase name="lu_title_MissingPhraseAdding"/>
</inp2:m_DefineElement>
<inp2:m_RenderElement name="header1" strip_nl="2" result_to_var="header"/>
-
+
<inp2:m_if check="phrases_HasError" field="any">
- <span class="error">There is a problem with the form, please check the error messages below.</span><br />
+ <span class="error"><inp2:m_phrase name="lu_AProblemInForm"/></span><br />
</inp2:m_if>
<span class="error">*</span> <inp2:m_phrase name="lu_IndicatesRequired"/><br />
<form method="post" action="<inp2:m_FormAction/>">
<table class="form-data">
<inp2:m_RenderElement name="inp_label" prefix="phrases" field="PrimaryTranslation" title="lu_fld_primary_translation"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="phrases" field="Phrase" title="lu_fld_phrase" style="width: 300px;"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="phrases" field="Translation" title="lu_fld_translation" style="width: 300px;"/>
<inp2:m_RenderElement name="inp_edit_options" prefix="phrases" field="Module" title="lu_fld_module"/>
-
+
<tr>
<td colspan="3" valign="bottom" height="35">
<input type="hidden" id="phrases_label" name="phrases_label" value="<inp2:m_get var="phrases_label"/>" />
<input type="hidden" name="<inp2:phrases_InputName field="LanguageId"/>" value="<inp2:phrases_Field name="LanguageId"/>" />
<input type="hidden" name="<inp2:phrases_InputName field="PhraseType"/>" value="0" />
-
+
<input class="button" type="submit" name="events[phrases][OnCreate]" value="<inp2:m_Phrase label="lu_btn_Create"/>"/>
</td>
</tr>
</table>
</form>
</inp2:m_DefineElement>
-
+
<inp2:m_RenderElement name="pharses_content" design="content_box"/>
<!-- // phrases -->
</inp2:m_DefineElement>
<inp2:m_include template="platform/designs/default_design" pass_params="1"/>
\ No newline at end of file
Property changes on: trunk/themes/default2007/phrases_edit.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/kernel/db/db_connection.php
===================================================================
--- trunk/core/kernel/db/db_connection.php (revision 8440)
+++ trunk/core/kernel/db/db_connection.php (revision 8441)
@@ -1,598 +1,599 @@
<?php
/**
* Multi database connection class
*
*/
class kDBConnection {
/**
* Current database type
*
* @var string
* @access private
*/
var $dbType = 'mysql';
/**
* Created connection handle
*
* @var resource
* @access private
*/
var $connectionID = null;
/**
* Handle of currenty processed recordset
*
* @var resource
* @access private
*/
var $queryID = null;
/**
* DB type specific function mappings
*
* @var Array
* @access private
*/
var $metaFunctions = Array();
/**
* Function to handle sql errors
*
* @var string
* @access private
*/
var $errorHandler = '';
/**
* Error code
*
* @var int
* @access private
*/
var $errorCode = 0;
/**
* Error message
*
* @var string
* @access private
*/
var $errorMessage = '';
/**
* Defines if database connection
* operations should generate debug
* information
*
* @var bool
*/
var $debugMode = false;
/**
* Last query to database
*
* @var string
*/
var $lastQuery = '';
/**
* Initializes connection class with
* db type to used in future
*
* @param string $dbType
* @return DBConnection
* @access public
*/
function kDBConnection($dbType, $errorHandler = '')
{
$this->dbType = $dbType;
// $this->initMetaFunctions();
if (!$errorHandler) {
$this->errorHandler = Array(&$this, 'handleError');
}
else {
$this->errorHandler = $errorHandler;
}
}
/**
* Set's custom error
*
* @param int $code
* @param string $msg
* @access public
*/
function setError($code, $msg)
{
$this->errorCode = $code;
$this->errorMessage = $msg;
}
/**
* Checks if previous query execution
* raised an error.
*
* @return bool
* @access public
*/
function hasError()
{
return !($this->errorCode == 0);
}
/**
* Caches function specific to requested
* db type
*
* @access private
*/
function initMetaFunctions()
{
$ret = Array();
switch ($this->dbType)
{
case 'mysql':
$ret = Array(); // only define functions, that name differs from "dbType_<meta_name>"
break;
}
$this->metaFunctions = $ret;
}
/**
* Get's function for specific db type
* based on it's meta name
*
* @param string $name
* @return string
* @access private
*/
function getMetaFunction($name)
{
/*if (!isset($this->metaFunctions[$name])) {
$this->metaFunctions[$name] = $name;
}*/
return $this->dbType.'_'.$name;
}
/**
* Try to connect to database server
* using specified parameters and set
* database to $db if connection made
*
* @param string $host
* @param string $user
* @param string $pass
* @param string $db
* @access public
*/
function Connect($host, $user, $pass, $db, $force_new = false)
{
$func = $this->getMetaFunction('connect');
$this->connectionID = $func($host, $user, $pass, $force_new) or trigger_error("Database connection failed, please check your connection settings", E_USER_ERROR);
if ($this->connectionID) {
if (defined('DBG_SQL_MODE')) {
$this->Query('SET sql_mode = \''.DBG_SQL_MODE.'\'');
}
$this->setDB($db);
$this->showError();
}
}
function ReConnect($host, $user, $pass, $db, $force_new = false)
{
$func = $this->getMetaFunction('close');
$func($this->connectionID);
$this->Connect($host, $user, $pass, $db, $force_new);
}
/**
* Shows error message from previous operation
* if it failed
*
* @access private
*/
function showError($sql = '')
{
$this->setError(0, ''); // reset error
if ($this->connectionID) {
$func = $this->getMetaFunction('errno'); $this->errorCode = $func($this->connectionID);
if ($this->hasError()) {
$func = $this->getMetaFunction('error'); $this->errorMessage = $func($this->connectionID);
if (is_array($this->errorHandler)) {
$func = $this->errorHandler[1];
$ret = $this->errorHandler[0]->$func($this->errorCode, $this->errorMessage, $sql);
}
else {
$func = $this->errorHandler;
$ret = $func($this->errorCode,$this->errorMessage,$sql);
}
if (!$ret) exit;
}
}
}
/**
* Default error handler for sql errors
*
* @param int $code
* @param string $msg
* @param string $sql
* @return bool
* @access private
*/
function handleError($code, $msg, $sql)
{
echo '<b>Processing SQL</b>: '.$sql.'<br>';
echo '<b>Error ('.$code.'):</b> '.$msg.'<br>';
return false;
}
/**
* Set's database name for connection
* to $new_name
*
* @param string $new_name
* @return bool
* @access public
*/
function setDB($new_name)
{
if (!$this->connectionID) return false;
$func = $this->getMetaFunction('select_db');
return $func($new_name, $this->connectionID);
}
/**
* Returns first field of first line
* of recordset if query ok or false
* otherwise
*
* @param string $sql
* @param int $offset
* @return string
* @access public
*/
function GetOne($sql, $offset = 0)
{
$row = $this->GetRow($sql, $offset);
if(!$row) return false;
return array_shift($row);
}
/**
* Returns first row of recordset
* if query ok, false otherwise
*
* @param stirng $sql
* @param int $offset
* @return Array
* @access public
*/
function GetRow($sql, $offset = 0)
{
$sql .= ' '.$this->getLimitClause($offset, 1);
$ret = $this->Query($sql);
if(!$ret) return false;
return array_shift($ret);
}
/**
* Returns 1st column of recordset as
* one-dimensional array or false otherwise
* Optional parameter $key_field can be used
* to set field name to be used as resulting
* array key
*
* @param string $sql
* @param string $key_field
* @return Array
* @access public
*/
function GetCol($sql, $key_field = null)
{
$rows = $this->Query($sql);
if (!$rows) return $rows;
$i = 0; $row_count = count($rows);
$ret = Array();
if (isset($key_field)) {
while ($i < $row_count) {
$ret[$rows[$i][$key_field]] = array_shift($rows[$i]);
$i++;
}
}
else {
while ($i < $row_count) {
$ret[] = array_shift($rows[$i]);
$i++;
}
}
return $ret;
}
/**
* Queries db with $sql query supplied
* and returns rows selected if any, false
* otherwise. Optional parameter $key_field
* allows to set one of the query fields
* value as key in string array.
*
* @param string $sql
* @param string $key_field
* @return Array
*/
function Query($sql, $key_field = null)
{
$this->lastQuery = $sql;
if ($this->debugMode) return $this->debugQuery($sql,$key_field);
$query_func = $this->getMetaFunction('query');
$this->queryID = $query_func($sql,$this->connectionID);
if (is_resource($this->queryID)) {
$ret = Array();
$fetch_func = $this->getMetaFunction('fetch_assoc');
if (isset($key_field)) {
while (($row = $fetch_func($this->queryID))) {
$ret[$row[$key_field]] = $row;
}
}
else {
while (($row = $fetch_func($this->queryID))) {
$ret[] = $row;
}
}
$this->Destroy();
return $ret;
}
$this->showError($sql);
return false;
}
function ChangeQuery($sql)
{
$this->Query($sql);
return $this->errorCode == 0 ? true : false;
}
function debugQuery($sql, $key_field = null)
{
global $debugger;
$query_func = $this->getMetaFunction('query');
// set 1st checkpoint: begin
$isSkipTable = true;
$profileSQLs = defined('DBG_SQL_PROFILE') && DBG_SQL_PROFILE;
if ($profileSQLs) {
$isSkipTable = isSkipTable($sql);
if (!$isSkipTable) {
$queryID = $debugger->generateID();
$debugger->profileStart('sql_'.$queryID, $debugger->formatSQL($sql));
}
}
// set 1st checkpoint: end
$this->queryID = $query_func($sql, $this->connectionID);
if( is_resource($this->queryID) )
{
$ret = Array();
$fetch_func = $this->getMetaFunction('fetch_assoc');
if( isset($key_field) )
{
while( ($row = $fetch_func($this->queryID)) )
{
$ret[$row[$key_field]] = $row;
}
}
else
{
while( ($row = $fetch_func($this->queryID)) )
{
$ret[] = $row;
}
}
// set 2nd checkpoint: begin
if(!$isSkipTable) {
- $first_cell = count($ret) == 1 && count($ret[0]) == 1 ? current($ret[0]) : null;
+ $first_cell = count($ret) == 1 && count(current($ret)) == 1 ? current(current($ret)) : null;
+
$debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows(), $first_cell);
$debugger->profilerAddTotal('sql', 'sql_'.$queryID);
}
$this->Destroy();
// set 2nd checkpoint: end
return $ret;
}
else {
// set 2nd checkpoint: begin
if(!$isSkipTable) {
$debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows());
$debugger->profilerAddTotal('sql', 'sql_'.$queryID);
}
// set 2nd checkpoint: end
}
$this->showError($sql);
return false;
}
/**
* Free memory used to hold recordset handle
*
* @access private
*/
function Destroy()
{
if($this->queryID)
{
$free_func = $this->getMetaFunction('free_result');
$free_func($this->queryID);
$this->queryID = null;
}
}
/**
* Returns auto increment field value from
* insert like operation if any, zero otherwise
*
* @return int
* @access public
*/
function getInsertID()
{
$func = $this->getMetaFunction('insert_id');
return $func($this->connectionID);
}
/**
* Returns row count affected by last query
*
* @return int
* @access public
*/
function getAffectedRows()
{
$func = $this->getMetaFunction('affected_rows');
return $func($this->connectionID);
}
/**
* Returns LIMIT sql clause part for specific db
*
* @param int $offset
* @param int $rows
* @return string
* @access private
*/
function getLimitClause($offset, $rows)
{
if(!($rows > 0)) return '';
switch ($this->dbType) {
default:
return 'LIMIT '.$offset.','.$rows;
break;
}
}
/**
* Correctly quotes a string so that all strings are escaped. We prefix and append
* to the string single-quotes.
* An example is $db->qstr("Don't bother",magic_quotes_runtime());
*
* @param s the string to quote
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
* This undoes the stupidity of magic quotes for GPC.
*
* @return quoted string to be sent back to database
*/
function qstr($s,$magic_quotes=false)
{
$replaceQuote = "\\'";
if (!$magic_quotes)
{
if ($replaceQuote[0] == '\\')
{
// only since php 4.0.5
$s = str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
//$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
}
return "'".str_replace("'",$replaceQuote,$s)."'";
}
// undo magic quotes for "
$s = str_replace('\\"','"',$s);
if($replaceQuote == "\\'") // ' already quoted, no need to change anything
{
return "'$s'";
}
else // change \' to '' for sybase/mssql
{
$s = str_replace('\\\\','\\',$s);
return "'".str_replace("\\'",$replaceQuote,$s)."'";
}
}
/**
* Returns last error code occured
*
* @return int
*/
function getErrorCode()
{
return $this->errorCode;
}
/**
* Returns last error message
*
* @return string
* @access public
*/
function getErrorMsg()
{
return $this->errorMessage;
}
function doInsert($fields_hash, $table, $type = 'INSERT')
{
$fields_sql = '';
$values_sql = '';
foreach ($fields_hash as $field_name => $field_value) {
$fields_sql .= '`'.$field_name.'`,';
$values_sql .= $this->qstr($field_value).',';
}
$fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql);
$values_sql = preg_replace('/(.*),$/', '\\1', $values_sql);
$sql = strtoupper($type).' INTO `'.$table.'` ('.$fields_sql.') VALUES ('.$values_sql.')';
return $this->ChangeQuery($sql);
}
function doUpdate($fields_hash, $table, $key_clause)
{
if (!$fields_hash) return true;
$fields_sql = '';
foreach ($fields_hash as $field_name => $field_value) {
$fields_sql .= '`'.$field_name.'` = '.$this->qstr($field_value).',';
}
$fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql);
$sql = 'UPDATE `'.$table.'` SET '.$fields_sql.' WHERE '.$key_clause;
return $this->ChangeQuery($sql);
}
/**
* Allows to detect table's presense in database
*
* @param string $table_name
* @return bool
*/
function TableFound($table_name)
{
static $table_found = Array();
if (!preg_match('/^'.preg_quote(TABLE_PREFIX, '/').'(.*)/', $table_name)) {
$table_name = TABLE_PREFIX.$table_name;
}
if (!isset($table_found[$table_name])) {
$table_found[$table_name] = $this->Query('SHOW TABLES LIKE "'.$table_name.'"');
}
return $table_found[$table_name];
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_connection.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.21
\ No newline at end of property
+1.22
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_config.php
===================================================================
--- trunk/core/units/reviews/reviews_config.php (revision 8440)
+++ trunk/core/units/reviews/reviews_config.php (revision 8441)
@@ -1,156 +1,171 @@
<?php
$config = Array (
'Prefix' => 'rev',
-
+
'Clones' => Array (
'l-rev' => Array(
'ParentPrefix' => 'l',
'ConfigMapping' => Array (
'PerPage' => 'Perpage_LinkReviews',
'ShortListPerPage' => 'Perpage_LinkReviews_Short',
'DefaultSorting1Field' => 'Link_ReviewsSort',
'DefaultSorting2Field' => 'Link_ReviewsSort2',
'DefaultSorting1Dir' => 'Link_ReviewsOrder',
'DefaultSorting2Dir' => 'Link_ReviewsOrder2',
+
+ 'ReviewDelayInterval' => 'link_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'link_ReviewDelay_Value',
),
),
-
+
'n-rev' => Array (
'ParentPrefix' => 'n',
'ConfigMapping' => Array (
'PerPage' => 'Perpage_NewsReviews',
'ShortListPerPage' => 'Perpage_NewsReviews_Short',
'DefaultSorting1Field' => 'News_SortReviews',
'DefaultSorting2Field' => 'News_SortReviews2',
'DefaultSorting1Dir' => 'News_SortReviewsOrder',
'DefaultSorting2Dir' => 'News_SortReviewsOrder2',
+
+ 'ReviewDelayInterval' => 'News_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'News_ReviewDelay_Value',
),
),
-
- 'bb-rev'=> Array(
- 'ParentPrefix' => 'bb',
+
+ 'bb-rev' => Array (
+ 'ParentPrefix' => 'bb',
+
+ 'ReviewDelayInterval' => 'topic_ReviewDelay_Interval',
+ 'ReviewDelayValue' => 'topic_ReviewDelay_Value',
),
- /*'p-rev' => Array('ParentPrefix' => 'p'),*/
+
+ 'p-rev' => Array (
+ 'ParentPrefix' => 'p',
+
+ 'ReviewDelayInterval' => 'product_ReviewDelay_Value',
+ 'ReviewDelayValue' => 'product_ReviewDelay_Interval',
+ ),
),
-
+
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'ReviewsEventHandler','file'=>'reviews_event_handler.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'ReviewsTagProcessor','file'=>'reviews_tag_processor.php','build_event'=>'OnBuild'),
'AutoLoad' => true,
-
+
'QueryString' => Array (
1 => 'id',
2 => 'Page',
3 => 'event',
4 => 'mode',
),
-
+
'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too
-
+
'IDField' => 'ReviewId',
'StatusField' => Array('Status'), // field, that is affected by Approve/Decline events
'TableName' => TABLE_PREFIX.'ItemReview',
'ParentTableKey' => 'ResourceId', // linked field in master table
'ForeignKey' => 'ItemId', // linked field in subtable
-
+
'AutoDelete' => true,
'AutoClone' => true,
-
+
'TitlePresets' => Array (
'reviews_edit' => Array('format' => "!la_title_Editing_Review!"),
),
-
+
'FilterMenu' => Array (
'Groups' => Array(
Array('mode' => 'AND', 'filters' => Array('show_active','show_pending','show_disabled'), 'type' => WHERE_FILTER),
),
'Filters' => Array(
'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ),
'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => '%1$s.Status != 2' ),
'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ),
)
),
'CalculatedFields' => Array (
'' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
),
-
+
'products' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
'ItemName' => 'pr.l1_Name',
'ProductId' => 'pr.ProductId',
),
-
+
'product' => Array (
'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
'ItemName' => 'pr.l1_Name',
'ProductId' => 'pr.ProductId',
),
),
// 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',
'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'),
'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','not_null'=>1,'default'=>0),
+ '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(),
),
'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' ),
),
),
'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
Property changes on: trunk/core/units/reviews/reviews_config.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.10
\ No newline at end of property
+1.11
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_tag_processor.php
===================================================================
--- trunk/core/units/reviews/reviews_tag_processor.php (revision 8440)
+++ trunk/core/units/reviews/reviews_tag_processor.php (revision 8441)
@@ -1,123 +1,96 @@
<?php
class ReviewsTagProcessor extends kDBTagProcessor
{
/**
* Returns a link for editing product
*
* @param Array $params
* @return string
*/
function ItemEditLink($params)
{
$item_prefix = $params['item_prefix'];
$id_field = $this->Application->getUnitOption($item_prefix,'IDField');
$object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$item_id = $object->GetDBField($id_field);
return $this->Application->HREF($params['edit_template'],'', Array(
'm_opener' => 'd',
$item_prefix.'_mode' => 't',
$item_prefix.'_event' => 'OnEdit',
$item_prefix.'_id' => $item_id,
'pass' => 'all,'.$item_prefix
), 'index.php');
}
/**
* Get's reuested field value
*
* @param Array $params
* @return string
* @access public
*/
function Field($params)
{
$field = $this->SelectParam($params, 'name,field');
$object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
if ($field == 'ReviewText') {
if ($object->GetDBField('TextFormat') == 1) {
$params['no_special'] = 'no_special';
}
else {
unset($params['no_special']);
}
}
return parent::Field($params);
-
}
function AlreadyReviewed($params)
{
- $user_id = $this->getUserID();
$object =& $this->getObject( Array('skip_autoload' => true) );
- $product_info = $object->getLinkedInfo();
+ $parent_info = $object->getLinkedInfo();
- $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
- WHERE ItemResourceId='.$product_info['ParentId'].'
- AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
- AND PortalUserId='.$user_id.'
- AND DataType="Review"';
- $res = $this->Conn->GetRow($sql);
- if($res['Expire'] > adodb_mktime())
- {
- $ret = 1;
- }
- else
- {
- $sql = 'DELETE FROM '.TABLE_PREFIX.'SpamControl
- WHERE ItemResourceId='.$product_info['ParentId'].'
- AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
- AND PortalUserId='.$user_id.'
- AND DataType="Review"';
- $this->Conn->Query($sql);
- $ret = 0;
- }
- return $ret;
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
+
+ return $spam_helper->InSpamControl();
}
function HasError($params)
{
$object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
if (method_exists($object, 'GetErrorMsg')) {
return parent::HasError($params);
}
else {
return 0;
}
}
-
+
/**
- * Returns current user id for reviews, for logic ask Kostja T.
+ * Preserve main item id in subitem pagination url
*
- * @return int
+ * @param Array $params
+ * @return string
*/
- function getUserID()
- {
- $user_id = $this->Application->RecallVar('user_id');
-
- if ($user_id == 0) {
- $user_id = -2;
- }
-
- return $user_id;
- }
-
function PageLink($params)
{
$object =& $this->getObject($params);
/* @var kDBList */
-
+
$parent_info = $object->getLinkedInfo();
if ($parent_info['ParentId'] > 0) {
$params['pass'] = 'm,'.$this->getPrefixSpecial().','.$parent_info['ParentPrefix'];
}
return parent::PageLink($params);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/reviews/reviews_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.7
\ No newline at end of property
+1.8
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_event_handler.php
===================================================================
--- trunk/core/units/reviews/reviews_event_handler.php (revision 8440)
+++ trunk/core/units/reviews/reviews_event_handler.php (revision 8441)
@@ -1,210 +1,349 @@
<?php
class ReviewsEventHandler extends kDBEventHandler
{
/**
- * Checks permissions of user
+ * Checks REVIEW/REVIEW.PENDING permission by main object primary category (not current category)
*
* @param kEvent $event
*/
function CheckPermission(&$event)
{
- if ($event->Name == 'OnAddReview') {
- $item_prefix = $this->getPermPrefix($event);
- $res = $this->Application->CheckPermission($item_prefix.'.REVIEW.PENDING', 0) || $this->Application->CheckPermission($item_prefix.'.REVIEW', 0);
+ if ($event->Name == 'OnAddReview' || $event->Name == 'OnCreate') {
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+
+ $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
+ $main_object =& $this->Application->recallObject($parent_prefix);
+ /* @var $main_object kCatDBItem */
+
+ $perm_name = $this->getPermPrefix($event).'.REVIEW';
+ $res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) ||
+ $this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'));
+
if (!$res) {
$event->status = erPERM_FAIL;
}
return $res;
}
return parent::CheckPermission($event);
}
/**
* Returns prefix for permissions
*
* @param kEvent $event
*/
function getPermPrefix(&$event)
{
$main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
// this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
$item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
return $item_prefix;
}
-
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
-
+
if (!$this->Application->IsAdmin()) {
$object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE);
}
-
+
switch ($event->Special)
{
case 'showall':
$object->clearFilters();
break;
case 'item':
$object->clearFilters();
$info = $object->getLinkedInfo();
$this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
$parent =& $this->Application->recallObject($info['ParentPrefix']);
$object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
break;
case 'products':
$object->removeFilter('parent_filter'); // this is important
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
break;
-
+
case 'product':
$object->clearFilters();
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
$this->Application->setUnitOption('p', 'AutoLoad', true);
$product =& $this->Application->recallObject('p');
$object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
break;
}
if ($event->getEventParam('type') == 'current_user') {
$user_id = $this->getUserID();
$ip = $_SERVER['REMOTE_ADDR'];
$object =& $event->getObject( Array('skip_autoload' => true) );
$product_info = $object->getLinkedInfo();
$object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
$object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
$object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
}
}
/**
* Adds review from front in case if user is logged in
*
* @param kEvent $event
*/
function OnAddReview(&$event)
{
$user_id = $this->getUserID();
$event->redirect_params = Array('pass' => 'all,p');
$object =& $event->getObject( Array('skip_autoload' => true) );
$parent_info = $object->getLinkedInfo();
$review_fields = $this->Application->GetVar($event->getPrefixSpecial(true));
$sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
WHERE ItemResourceId='.$parent_info['ParentId'].'
AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
AND PortalUserId='.$user_id.'
AND DataType="Review"';
$res = $this->Conn->GetRow($sql);
if( $res && $res['Expire'] < adodb_mktime() )
{
$sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
WHERE ItemResourceId='.$parent_info['ParentId'].'
AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
AND PortalUserId='.$user_id.'
AND DataType="Review"';
$this->Conn->Query($sql);
unset($res);
}
if(!$res)
{
$object->SetFieldsFromHash( array_shift($review_fields) );
$object->SetDBField('CreatedById', $user_id);
$object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
$object->SetDBField('CreatedOn', adodb_mktime());
$module_info = $this->Application->findModule('Var',$parent_info['ParentPrefix']);
$object->SetDBField('Module', $module_info['Name']);
if( $this->Application->CheckPermission( $this->getPermPrefix($event).'.REVIEW.PENDING', 0) )
{
$object->SetDBField('Status', 2);
$template_var = 'success_pending_template';
}
if( $this->Application->CheckPermission($this->getPermPrefix($event).'.REVIEW', 0) )
{
$object->SetDBField('Status', 1);
$template_var = 'success_template';
}
$object->SetDBField('ItemId', $parent_info['ParentId']);
$event->CallSubEvent('OnCreate');
if($event->status == erSUCCESS)
{
$parent =& $this->Application->recallObject($parent_info['ParentPrefix']);
$sql = ' SELECT COUNT(ReviewId)
FROM '.$object->TableName.'
WHERE ItemId='.$parent_info['ParentId'];
$review_qty = $this->Conn->GetOne($sql);
$parent->SetDBField('CachedReviewsQty', $review_qty);
$parent->Update();
$expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
$sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
(ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
VALUES ('.$parent_info['ParentId'].',
"'.$_SERVER['REMOTE_ADDR'].'",
'.$user_id.',
"Review",
'.$expire.')';
$this->Conn->Query($sql);
$event->redirect_params = Array('pass' => 'all,'.$parent_info['ParentPrefix']);
$event->redirect = $this->Application->GetVar($template_var);
}
}
else
{
// $this->Application->removeObject($event->getPrefixSpecial());
$event->status == erFAIL;
$event->redirect=false;
$object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
$object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
}
}
/**
- * Enter description here...
+ * Get new review status on user review permission
+ *
+ * @param kEvent $event
+ * @return int
+ */
+ function getReviewStatus(&$event)
+ {
+ $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
+ $main_object =& $this->Application->recallObject($parent_prefix);
+ /* @var $main_object kCatDBItem */
+
+ $ret = STATUS_DISABLED;
+ $perm_name = $this->getPermPrefix($event).'.REVIEW';
+ if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) {
+ $ret = STATUS_ACTIVE;
+ }
+ else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) {
+ $ret = STATUS_PENDING;
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Prefills all fields on front-end
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
+ if ($this->Application->IsAdmin()) {
+ return ;
+ }
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $parent_info = $object->getLinkedInfo();
+
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
+
+ if ($spam_helper->InSpamControl()) {
+ $event->status = erFAIL;
+ $object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate');
+ return ;
+ }
+
+ $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
+
+ $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'));
+ }
+
+ /**
+ * Updates item review counter
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $this->updateReviewsCounter($event);
+
+ if (!$this->Application->IsAdmin()) {
+ $spam_helper =& $this->Application->recallObject('SpamHelper');
+ /* @var $spam_helper SpamHelper */
+
+ $object =& $event->getObject();
+ $parent_info = $object->getLinkedInfo($event->Special);
+
+ $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
+ $review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval'];
+ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings);
+
+ $spam_helper->AddToSpamControl();
+ }
+ }
+
+ /**
+ * Updates total review counter
+ *
+ * @param kEvent $event
+ */
+ function updateReviewsCounter(&$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 */
+
+ if (!$main_object->isLoaded()) {
+ // deleting main item / cloning main item
+ return ;
+ }
+
+ $object =& $event->getObject(); // for temp tables
+
+ $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);
+ $main_object->Update();
+ }
+
+
+ /**
+ * Updates main item cached review counter
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemDelete(&$event)
+ {
+ $this->updateReviewsCounter($event);
+ }
+
+ /**
+ * Creates review & redirect to confirmation template
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ parent::OnCreate($event);
+
+ if ($event->status != erSUCCESS || $this->Application->IsAdmin()) {
+ return ;
+ }
+
$object =& $event->getObject();
- $object->SetDBField('Module', $this->Application->findModule('Var',$this->Application->getUnitOption($this->Prefix, 'ParentPrefix'), 'Name'));
+ $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template';
+ $event->redirect = $this->Application->GetVar($next_template);
+ $event->SetRedirectParam('opener', 's');
}
/**
* Returns current user id for reviews, for logic ask Kostja T.
*
* @return int
*/
function getUserID()
{
$user_id = $this->Application->RecallVar('user_id');
if ($user_id == 0) {
$user_id = -2;
}
return $user_id;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/reviews/reviews_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property

Event Timeline