Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773887
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 2, 11:54 PM
Size
9 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 11:54 PM (1 h, 45 m)
Engine
blob
Format
Raw Data
Handle
557045
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/kernel/units/custom_values/custom_value_event_handler.php
===================================================================
--- trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 2070)
+++ trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 2071)
@@ -1,96 +1,96 @@
<?php
class CustomValuesEventHandler extends InpDBEventHandler {
-
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
- $top_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
- $item_type = $this->Application->getUnitOption($top_prefix, 'ItemType');
+ $parent_info = $object->getLinkedInfo();
+ // $top_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
+ $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
$item_resource_id = $this->GetParentResourceId($event);
// there is no ResourceId when creating new item, but we need some id for SQL to work
if (!$item_resource_id) $item_resource_id = 0;
$sql = str_replace('#ITEM_RESOURCE_ID#',$item_resource_id,$object->SelectClause);
$object->setSelectSQL($sql);
$object->removeFilter('parent_filter');
$object->addFilter('itemtype_filter', 'Type = '.$item_type);
if ($event->Special=='general') $object->addFilter('generaltab_filter','OnGeneralTab = 1');
$object->SetPerPage(-1);
}
/**
* Enter description here...
*
* @param kEvent $event
* @return unknown
*/
function GetParentResourceId(&$event)
{
$object = &$event->getObject();
$top_object = $this->Application->RecallObject( $this->Application->GetTopmostPrefix($event->Prefix) );
return $top_object->GetDBField('ResourceId');
}
function OnPreSave(&$event)
{
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
$lang_id = $this->Application->GetVar('m_lang');
foreach($items_info as $custom_field_id => $values)
{
$set_values = Array(
'CustomFieldId' => $custom_field_id,
'l'.$lang_id.'_Value' => $values['l'.$lang_id.'_Value'],
'ResourceId' => $values['ResourceId'] != 0 ? $values['ResourceId'] : $this->GetParentResourceId($event),
);
// ResourceId will be -1 if we are creating new product, then we get ID directly,
// because it should be already set by parent' event, as we are in hAFTER hook
$id = $values['CustomDataId'];
if ($id) { //if it's already existing custom field record - update id
$object->SetDefaultValues();
$object->Load($id);
$object->SetFieldsFromHash($set_values);
if( $object->Update($id) )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFAIL;
$event->redirect=false;
break;
}
}
else { //new custom field record - create it and set temp id!
$object->SetDefaultValues();
$object->SetFieldsFromHash($set_values);
if( $object->Create(null, true) )
{
$object->setTempID();
$event->status=erSUCCESS;
}
}
}
}
// this is critical, as the object here is Item, but if something fails, the template could use the same name as grid
// the problem appeared on products general tab, when validation does not go through for product,
// and the templates is getting parsed
$this->Application->removeObject($event->Prefix_Special);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/custom_values/custom_value_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/kernel/units/custom_fields/custom_fields_event_handler.php
===================================================================
--- trunk/kernel/units/custom_fields/custom_fields_event_handler.php (revision 2070)
+++ trunk/kernel/units/custom_fields/custom_fields_event_handler.php (revision 2071)
@@ -1,69 +1,74 @@
<?php
class CustomFieldsEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$item_type=$this->Application->GetVar('cf_type');
+ /*if(!$item_type)
+ {
+ $parent_info = $object->getLinkedInfo();
+ $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
+ }*/
$object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type);
//$object->AddOrderField('DisplayOrder', 'ASC');
}
/**
* Prevents from duplicate item creation
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
$new_field_name=$items_info[0]['FieldName'];
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$found = $this->Conn->GetOne("SELECT count(*) FROM ".$table." WHERE FieldName='".$new_field_name."'");
if($found){
$event->status=erFAIL;
$object->FieldErrors['FieldName']['pseudo'] = $this->Application->Phrase('la_error_CustomExists');
}
else {
- $item_type=$this->Application->GetVar('cf_type');
+ $item_type = $this->Application->GetVar('cf_type');
$object->SetDBField('Type', $this->Application->GetVar('cf_type'));
}
}
/**
* Occurse after deleting item, id of deleted item
* is stored as 'id' param of event
*
* @param kEvent $event
* @access public
*/
function OnAfterItemDelete(&$event)
{
$object =& $event->getObject();
$custom_field_id=$event->getEventParam('id');
$this->Application->SetVar('cf_id', '');
$sql='DELETE FROM '.TABLE_PREFIX.'CustomMetaData WHERE CustomFieldId = '.$custom_field_id;
$this->Conn->Query($sql);
}
function OnMassDelete(&$event)
{
parent::OnMassDelete($event);
$event->redirect_params = Array('opener' => 's');
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/custom_fields/custom_fields_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Index: trunk/core/units/custom_fields/custom_fields_event_handler.php
===================================================================
--- trunk/core/units/custom_fields/custom_fields_event_handler.php (revision 2070)
+++ trunk/core/units/custom_fields/custom_fields_event_handler.php (revision 2071)
@@ -1,69 +1,74 @@
<?php
class CustomFieldsEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$item_type=$this->Application->GetVar('cf_type');
+ /*if(!$item_type)
+ {
+ $parent_info = $object->getLinkedInfo();
+ $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
+ }*/
$object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type);
//$object->AddOrderField('DisplayOrder', 'ASC');
}
/**
* Prevents from duplicate item creation
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
$new_field_name=$items_info[0]['FieldName'];
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$found = $this->Conn->GetOne("SELECT count(*) FROM ".$table." WHERE FieldName='".$new_field_name."'");
if($found){
$event->status=erFAIL;
$object->FieldErrors['FieldName']['pseudo'] = $this->Application->Phrase('la_error_CustomExists');
}
else {
- $item_type=$this->Application->GetVar('cf_type');
+ $item_type = $this->Application->GetVar('cf_type');
$object->SetDBField('Type', $this->Application->GetVar('cf_type'));
}
}
/**
* Occurse after deleting item, id of deleted item
* is stored as 'id' param of event
*
* @param kEvent $event
* @access public
*/
function OnAfterItemDelete(&$event)
{
$object =& $event->getObject();
$custom_field_id=$event->getEventParam('id');
$this->Application->SetVar('cf_id', '');
$sql='DELETE FROM '.TABLE_PREFIX.'CustomMetaData WHERE CustomFieldId = '.$custom_field_id;
$this->Conn->Query($sql);
}
function OnMassDelete(&$event)
{
parent::OnMassDelete($event);
$event->redirect_params = Array('opener' => 's');
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/custom_fields/custom_fields_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Event Timeline
Log In to Comment