Attached Files |
ability_to_use_main_event_from_internal_events.patch [^] (3,492 bytes) 2011-08-24 07:39
[Show Content]
Index: kernel/db/db_event_handler.php
===================================================================
--- kernel/db/db_event_handler.php (revision 14476)
+++ kernel/db/db_event_handler.php (working copy)
@@ -426,6 +426,12 @@
$object->Configure( $event->getEventParam('populate_ml_fields') || $this->Application->getUnitOption($event->Prefix, 'PopulateMlFields') );
$this->PrepareObject($object, $event);
+ $parent_event = $event->getEventParam('parent_event'); // PHP5 only
+
+ if ( is_object($parent_event) ) {
+ $object->setParentEvent($parent_event);
+ }
+
// force live table if specified or is original item
$live_table = $event->getEventParam('live_table') || $event->Special == 'original';
@@ -1595,6 +1601,7 @@
function OnSave(&$event)
{
$event->CallSubEvent('OnPreSave');
+
if ($event->status == erSUCCESS) {
$skip_master = false;
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
Index: kernel/db/dbitem.php
===================================================================
--- kernel/db/dbitem.php (revision 14476)
+++ kernel/db/dbitem.php (working copy)
@@ -1087,18 +1087,21 @@
function raiseEvent($name, $id = null, $additional_params = Array())
{
- if( !isset($id) ) $id = $this->GetID();
- $event = new kEvent( Array('name'=>$name,'prefix'=>$this->Prefix,'special'=>$this->Special) );
- $event->setEventParam('id', $id);
+ $event = new kEvent( $this->getPrefixSpecial() . ':' . $name );
- if ($additional_params) {
- foreach ($additional_params as $ap_name => $ap_value) {
- $event->setEventParam($ap_name, $ap_value);
- }
+ if ( is_object($this->parentEvent) ) {
+ $event->MasterEvent =& $this->parentEvent;
}
+ $additional_params['id'] = isset($id) ? $id : $this->GetID();
+
+ foreach ($additional_params as $ap_name => $ap_value) {
+ $event->setEventParam($ap_name, $ap_value);
+ }
+
$this->Application->HandleEvent($event);
- return $event->status == erSUCCESS ? true : false;
+
+ return $event->status == erSUCCESS;
}
/**
Index: kernel/kbase.php
===================================================================
--- kernel/kbase.php (revision 14476)
+++ kernel/kbase.php (working copy)
@@ -235,6 +235,13 @@
*/
var $mode='';
+ /**
+ * Event, that was used to create this object
+ *
+ * @var kEvent
+ */
+ var $parentEvent = null;
+
function kDBBase()
{
parent::kBase();
@@ -242,6 +249,16 @@
}
/**
+ * Sets new parent event to the object
+ *
+ * @param kEvent $event
+ */
+ function setParentEvent(&$event)
+ {
+ $this->parentEvent =& $event;
+ }
+
+ /**
* Set current item' database table name
*
* @access public
Index: kernel/utility/event.php
===================================================================
--- kernel/utility/event.php (revision 14476)
+++ kernel/utility/event.php (working copy)
@@ -212,7 +212,19 @@
*/
function &getObject($params = Array())
{
+ if ( !$this->Application->hasObject($this->Prefix_Special) ) {
+ $top_event =& $this;
+
+ // when OnSave calls OnPreSave in first line, then this would make sure OnSave is used
+ while ( is_object($top_event->MasterEvent) ) {
+ $top_event =& $top_event->MasterEvent;
+ }
+
+ $params['parent_event'] =& $top_event;
+ }
+
$object =& $this->Application->recallObject($this->Prefix_Special, $this->pseudoClass, $params);
+
return $object;
}
ability_to_use_main_event_from_internal_events_520.patch [^] (5,485 bytes) 2011-10-03 04:48
[Show Content]
Index: kernel/db/db_event_handler.php
===================================================================
--- kernel/db/db_event_handler.php (revision 14597)
+++ kernel/db/db_event_handler.php (working copy)
@@ -411,6 +411,12 @@
$object->Configure( $event->getEventParam('populate_ml_fields') || $this->Application->getUnitOption($event->Prefix, 'PopulateMlFields'), $form_name );
$this->PrepareObject($object, $event);
+ $parent_event = $event->getEventParam('parent_event');
+
+ if ( is_object($parent_event) ) {
+ $object->setParentEvent($parent_event);
+ }
+
// force live table if specified or is original item
$live_table = $event->getEventParam('live_table') || $event->Special == 'original';
@@ -1025,7 +1031,7 @@
// always add forced sorting before any user sorting fields
$forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting');
/* @var $forced_sorting Array */
-
+
if ($forced_sorting) {
foreach ($forced_sorting as $field => $dir) {
$object->AddOrderField($field, $dir);
@@ -1135,10 +1141,10 @@
if ( $view_filter ) {
$view_filter = unserialize($view_filter);
-
+
$temp_filter =& $this->Application->makeClass('kMultipleFilter');
/* @var $temp_filter kMultipleFilter */
-
+
$filter_menu = $this->Application->getUnitOption($event->Prefix, 'FilterMenu');
$group_key = 0;
@@ -1405,7 +1411,7 @@
/* @var $object kDBItem */
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
-
+
if ( $items_info ) {
foreach ($items_info as $id => $field_values) {
$object->Load($id);
@@ -1805,7 +1811,7 @@
if ( $this->isNewItemCreate($event) ) {
$event->CallSubEvent('OnPreSaveCreated');
-
+
if ( is_object($event->MasterEvent) ) {
$event->MasterEvent->setEventParam('IsNew', true);
}
@@ -1980,7 +1986,7 @@
// just reset id to 0 in case it was create
$object =& $event->getObject( Array ('skip_autoload' => true) );
/* @var $object kDBItem */
-
+
$object->setID(0);
$this->Application->SetVar($event->getPrefixSpecial() . '_id', 0);
}
@@ -2413,7 +2419,7 @@
/**
* Sets view filter based on request
- *
+ *
* @param kEvent $event
* @return void
* @access protected
@@ -2434,7 +2440,7 @@
list($id, $value) = explode('=', $a_filter);
$view_filter[$id] = $value;
}
-
+
$this->Application->StoreVar($event->getPrefixSpecial() . '_view_filter', serialize($view_filter));
$event->redirect = false;
}
@@ -2498,7 +2504,7 @@
$cdata->SetDBField('ResourceId', $resource_id);
$cdata->Create();
}
-
+
$this->Application->SetVar($cdata->getPrefixSpecial() . '_id', $cdata->GetID());
}
Index: kernel/db/dbitem.php
===================================================================
--- kernel/db/dbitem.php (revision 14596)
+++ kernel/db/dbitem.php (working copy)
@@ -934,18 +934,21 @@
protected function raiseEvent($name, $id = null, $additional_params = Array())
{
- if( !isset($id) ) $id = $this->GetID();
- $event = new kEvent( Array('name'=>$name,'prefix'=>$this->Prefix,'special'=>$this->Special) );
- $event->setEventParam('id', $id);
+ $event = new kEvent( $this->getPrefixSpecial() . ':' . $name );
- if ($additional_params) {
- foreach ($additional_params as $ap_name => $ap_value) {
- $event->setEventParam($ap_name, $ap_value);
- }
+ if ( is_object($this->parentEvent) ) {
+ $event->MasterEvent =& $this->parentEvent;
}
+ $additional_params['id'] = isset($id) ? $id : $this->GetID();
+
+ foreach ($additional_params as $ap_name => $ap_value) {
+ $event->setEventParam($ap_name, $ap_value);
+ }
+
$this->Application->HandleEvent($event);
- return $event->status == kEvent::erSUCCESS ? true : false;
+
+ return $event->status == kEvent::erSUCCESS;
}
/**
Index: kernel/kbase.php
===================================================================
--- kernel/kbase.php (revision 14605)
+++ kernel/kbase.php (working copy)
@@ -237,6 +237,26 @@
protected $populateMultiLangFields = false;
/**
+ * Event, that was used to create this object
+ *
+ * @var kEvent
+ * @access protected
+ */
+ protected $parentEvent = null;
+
+ /**
+ * Sets new parent event to the object
+ *
+ * @param kEvent $event
+ * @return void
+ * @access public
+ */
+ public function setParentEvent(&$event)
+ {
+ $this->parentEvent =& $event;
+ }
+
+ /**
* Set object' TableName to LIVE table, defined in unit config
*
* @access public
Index: kernel/utility/event.php
===================================================================
--- kernel/utility/event.php (revision 14590)
+++ kernel/utility/event.php (working copy)
@@ -257,11 +257,23 @@
/**
* Returns object used in event
*
+ * @param Array $params
* @return kDBBase
* @access public
*/
public function &getObject(array $params = Array())
{
+ if ( !$this->Application->hasObject($this->prefixSpecial) ) {
+ $top_event =& $this;
+
+ // when OnSave calls OnPreSave in first line, then this would make sure OnSave is used
+ while ( is_object($top_event->MasterEvent) ) {
+ $top_event =& $top_event->MasterEvent;
+ }
+
+ $params['parent_event'] =& $top_event;
+ }
+
$object =& $this->Application->recallObject($this->prefixSpecial, $this->pseudoClass, $params);
return $object;
temp_handler_ignored_parent_event_fix.patch [^] (8,470 bytes) 2011-10-12 03:50
[Show Content]
Index: kernel/db/db_event_handler.php
===================================================================
--- kernel/db/db_event_handler.php (revision 14653)
+++ kernel/db/db_event_handler.php (working copy)
@@ -449,20 +449,24 @@
*/
function checkItemStatus(&$event)
{
- $status_fields = $this->Application->getUnitOption($event->Prefix,'StatusField');
- if (!$status_fields) {
+ $status_fields = $this->Application->getUnitOption($event->Prefix, 'StatusField');
+ if ( !$status_fields ) {
return true;
}
$status_field = array_shift($status_fields);
- if ($status_field == 'Status' || $status_field == 'Enabled') {
+
+ if ( $status_field == 'Status' || $status_field == 'Enabled' ) {
$object =& $event->getObject();
- if (!$object->isLoaded()) {
+ /* @var $object kDBItem */
+
+ if ( !$object->isLoaded() ) {
return true;
}
return $object->GetDBField($status_field) == STATUS_ACTIVE;
}
+
return true;
}
@@ -594,6 +598,12 @@
$object =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
/* @var $object kTempTablesHandler */
+ $parent_event = $event->getEventParam('parent_event');
+
+ if ( is_object($parent_event) ) {
+ $object->setParentEvent($parent_event);
+ }
+
$object->BuildTables( $event->Prefix, $this->getSelectedIDs($event) );
}
@@ -1459,10 +1469,10 @@
return;
}
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
- /* @var $temp kTempTablesHandler */
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
+ /* @var $temp_handler kTempTablesHandler */
- $temp->DeleteItems($event->Prefix, $event->Special, Array($this->getPassedID($event)));
+ $temp_handler->DeleteItems($event->Prefix, $event->Special, Array ($this->getPassedID($event)));
}
/**
@@ -1477,7 +1487,7 @@
$ids = $this->Conn->GetCol($sql);
if ($ids) {
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$temp_handler->DeleteItems($event->Prefix, $event->Special, $ids);
@@ -1528,7 +1538,7 @@
if ( $items_info ) {
$delete_ids = Array ();
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
foreach ($items_info as $id => $field_values) {
@@ -1563,7 +1573,7 @@
return ;
}
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$ids = $this->StoreSelectedIDs($event);
@@ -1615,10 +1625,10 @@
$changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix);
$this->Application->RemoveVar($changes_var_name);
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
- /* @var $temp kTempTablesHandler */
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
+ /* @var $temp_handler kTempTablesHandler */
- $temp->PrepareEdit();
+ $temp_handler->PrepareEdit();
$event->SetRedirectParam('m_lang', $this->Application->GetDefaultLanguageId());
$event->SetRedirectParam($event->getPrefixSpecial() . '_id', array_shift($ids));
@@ -1642,7 +1652,7 @@
}
$skip_master = false;
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix);
@@ -1780,7 +1790,7 @@
*/
protected function OnCancelEdit(&$event)
{
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$temp_handler->CancelEdit();
@@ -1942,7 +1952,7 @@
$object =& $event->getObject( Array ('skip_autoload' => true) );
/* @var $object kDBItem */
- $temp_handler =& $this->Application->recallObject($event->Prefix . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->Prefix . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$temp_handler->PrepareEdit();
@@ -2079,7 +2089,7 @@
return ;
}
- $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
+ $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event));
/* @var $temp_handler kTempTablesHandler */
$ids = $this->StoreSelectedIDs($event);
@@ -2234,8 +2244,10 @@
* Occurs before validation attempt
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBeforeItemValidate(&$event)
+ protected function OnBeforeItemValidate(kEvent &$event)
{
}
Index: kernel/utility/temp_handler.php
===================================================================
--- kernel/utility/temp_handler.php (revision 14653)
+++ kernel/utility/temp_handler.php (working copy)
@@ -65,10 +65,29 @@
*/
var $WindowID = '';
+ /**
+ * Event, that was used to create this object
+ *
+ * @var kEvent
+ * @access protected
+ */
+ protected $parentEvent = null;
+
+ /**
+ * Sets new parent event to the object
+ *
+ * @param kEvent $event
+ * @return void
+ * @access public
+ */
+ public function setParentEvent(&$event)
+ {
+ $this->parentEvent =& $event;
+ }
+
function SetTables($tables)
{
- // set tablename as key for tables array
- $ret = Array();
+ // set table name as key for tables array
$this->Tables = $tables;
$this->MasterTable = $tables['TableName'];
}
@@ -170,7 +189,7 @@
$this->AddTables($prefix, $tables);
}
}
-
+
$this->SetTables($tables);
}
@@ -232,7 +251,7 @@
$sub_items = $this->Application->getUnitOption($prefix, 'SubItems', Array ());
/* @var $sub_items Array */
-
+
if ( is_array($sub_items) ) {
foreach ($sub_items as $prefix) {
$this->AddTables($prefix, $tmp);
@@ -255,7 +274,7 @@
$special .= '-item';
}
- $object =& $this->Application->recallObject($prefix.'.'.$special, $prefix, Array('skip_autoload' => true));
+ $object =& $this->Application->recallObject($prefix.'.'.$special, $prefix, Array('skip_autoload' => true, 'parent_event' => &$this->parentEvent));
/* @var $object kCatDBItem */
$object->PopulateMultiLangFields();
@@ -357,7 +376,7 @@
//recalling by different name, because we may get kDBList, if we recall just by prefix
$recall_prefix = $prefix_special.($special ? '' : '.').'-item';
- $object =& $this->Application->recallObject($recall_prefix, $prefix, Array('skip_autoload' => true));
+ $object =& $this->Application->recallObject($recall_prefix, $prefix, Array('skip_autoload' => true, 'parent_event' => &$this->parentEvent));
/* @var $object kDBItem */
foreach ($ids as $id)
@@ -596,7 +615,7 @@
if ( isset($master['Constrain']) ) {
$query .= ' AND ' . $master['Constrain'];
}
-
+
$this->Conn->Query($query);
}
|