Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 8:44 AM

in-portal

Index: trunk/core/kernel/utility/event.php
===================================================================
--- trunk/core/kernel/utility/event.php (revision 957)
+++ trunk/core/kernel/utility/event.php (revision 958)
@@ -1,136 +1,146 @@
<?php
define('erFATAL',-1);
define('erFAIL',-2);
define('erSUCCESS',0);
- class kEvent {
+ class kEvent extends kBase {
/**
* Event reference, that
* created this event
*
* @var kEvent
* @access public
*/
var $MasterEvent;
/**
* Event name
*
* @var string
* @access public
*/
var $Name;
/**
* Pseudo class name
*
* @var string
* @access public
*/
- var $Prefix;
+ //var $Prefix;
/**
* Special, that is recognized
* by class with pseudo class
* equals to $Prefix attrbute.
*
* @var string
* @access public
*/
- var $Special;
+ //var $Special;
/**
* Joined prefix and special,
* usually taken directly from
* tag beeing processes, to use
* in recallObject method
*
* @var string
*/
var $Prefix_Special;
/**
* Stop event queue processing
* after this event
*
* @var bool
* @access public
*/
var $cancelBubble=false;
/**
* Redirect is allowed after
* this event
*
* @var bool
* @access public
*/
var $redirect=false;
/**
* Event processing result
*
* @var int
* @access public
*/
var $status=erSUCCESS;
/**
* Each event specific only params,
* that they use for communication
*
* @var Array
* @access public
*/
var $specificParams=Array();
/**
* Pseudo class used to create object,
* in case if one is not already created
*
* @var string
* @access public
*/
var $pseudoClass='';
function setEventParam($name,$value)
{
$this->specificParams[$name]=$value;
}
function getEventParam($name)
{
return isset($this->specificParams[$name])?$this->specificParams[$name]:false;
}
function getPrefixSpecial($from_submit=false)
{
$separator=!$from_submit?'.':'_';
$ret=$this->Prefix.$separator.$this->Special;
return rtrim($ret,$separator);
}
/**
* Set's pseudo class that differs from
* the one specified in $Prefix
*
* @param string $appendix
* @access public
*/
function setPseudoClass($appendix)
{
$this->pseudoClass=$this->Prefix.$appendix;
}
function Init($prefix,$special)
{
$this->Prefix=$prefix;
$this->pseudoClass=$prefix; // default value
$this->Special=$special;
$this->Prefix_Special = rtrim($this->Prefix.'.'.$this->Special,'.');
}
+ /**
+ * Returns object used in event
+ *
+ * @access public
+ */
+ function &createObject()
+ {
+ return $this->Application->recallObject($this->Prefix_Special,$this->pseudoClass);
+ }
+
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/event.php
___________________________________________________________________
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/event_handler.php
===================================================================
--- trunk/core/kernel/event_handler.php (revision 957)
+++ trunk/core/kernel/event_handler.php (revision 958)
@@ -1,108 +1,97 @@
<?php
/**
* Note:
* 1. When adressing variables from submit containing
* Prefix_Special as part of their name use
* $event->getPrefixSpecial(true) instead of
* $event->Prefix_Special as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
* for variables beeing submitted such way (e.g. variable
* name that will be converted by PHP: "users.read_only_id"
* will be submitted as "users_read_only_id".
*
* 2. When using $this->Application-LinkVar on variables submitted
* from form which contain $Prefix_Special then note 1st item. Example:
* LinkVar($event->getPrefixSpecial(true).'_varname',$event->Prefix_Special.'_varname')
*
*/
/**
* Default event handler. Mostly abstract class
*
*/
class kEventHandler extends kBase {
/**
* Process Event
*
* @param kEvent $event
* @access public
*/
function processEvent(&$event)
{
if( method_exists($this,$event->Name) )
{
$event_name = $event->Name;
$this->$event_name(&$event);
if($event->status==erSUCCESS && $event->redirect && strlen($event->redirect) > 0 )
{
$this->Application->Redirect($event->redirect);
}
}
else
{
$this->Application->KernelDie('event <b>'.$event->Name.'</b> not implemented in class <b>'.get_class($this).'</b>');
}
}
/**
* Sample dummy event
*
* @param kEvent $event
* @access protected
*/
function OnBuild(&$event)
{
/*echo 'building: <br>';
print_pre($event);*/
}
/**
- * Retunrs object used in event
- *
- * @param kEvent $event
- * @access protected
- */
- function &createObject(&$event)
- {
- return $this->Application->recallObject($event->Prefix_Special,$event->pseudoClass);
- }
-
- /**
* Apply some special processing to
* object beeing recalled before using
* it in other events that call prepareObject
*
* @param Object $object
* @param kEvent $event
* @access protected
*/
function prepareObject(&$object,&$event)
{
// processing here
}
/**
* Creates new event as child of
* event passed as $event param
*
* @param kEvent $event
* @access protected
*/
function &inheritEvent(&$event)
{
$child_event = new kEvent();
$child_event->MasterEvent =& $event;
$child_event->Prefix=$event->Prefix;
$child_event->Special=$event->Special;
$child_event->Prefix_Special=$event->Prefix_Special;
return $child_event;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/event_handler.php
___________________________________________________________________
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_event_handler.php
===================================================================
--- trunk/core/kernel/db/db_event_handler.php (revision 957)
+++ trunk/core/kernel/db/db_event_handler.php (revision 958)
@@ -1,381 +1,381 @@
<?php
/**
* Note:
* 1. When adressing variables from submit containing
* Prefix_Special as part of their name use
* $event->getPrefixSpecial(true) instead of
* $event->Prefix_Special as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
* for variables beeing submitted such way (e.g. variable
* name that will be converted by PHP: "users.read_only_id"
* will be submitted as "users_read_only_id".
*
* 2. When using $this->Application-LinkVar on variables submitted
* from form which contain $Prefix_Special then note 1st item. Example:
* LinkVar($event->getPrefixSpecial(true).'_varname',$event->Prefix_Special.'_varname')
*
*/
/**
* EventHandler that is used to process
* any database related events
*
*/
class kDBEventHandler extends kEventHandler {
/**
* Get's ID of item to be edited.
* Returns 1st id in case if many
* items were selected.
*
* @param kEvent $event
* @return int
*/
function getPassedID(&$event)
{
$ret=$this->Application->GetVar($event->getPrefixSpecial().'_id');
if($ret===false)
{
$ids=$this->Application->GetVar($event->getPrefixSpecial().'_selected_ids');
$ids=explode(',',$ids);
if($ids) $ret=array_shift($ids);
}
return $ret;
}
/**
* Builds item (loads if needed)
*
* @param kEvent $event
* @access protected
*/
function OnItemBuild(&$event)
{
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnItemPrepareQuery');
$object->setSelectSQL($sql);
// 1. set from config what needed
$fields = $this->Application->getUnitOption($event->Prefix,'Fields');
$object->setConfigFields( array_keys($fields) );
// 2. loads if allowed
$auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad');
if($auto_load)
{
$id = $this->getPassedID(&$event);
$object->Load($id);
}
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnUpdate');
}
/**
* Builds list
*
* @param kEvent $event
* @access protected
*/
function OnListBuild(&$event)
{
$event->setPseudoClass('_List');
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnListPrepareQuery');
$object->setSelectSQL($sql);
$t=$this->Application->GetVar('t');
$this->Application->StoreVar('redirect_to',$t);
$this->SetPagination(&$event);
$this->SetSorting(&$event);
}
/**
* Set's correct page for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetPagination(&$event)
{
$per_page = $event->getEventParam('per_page');
if(!$per_page)
{
$per_page=$this->Application->RecallVar($event->Prefix_Special.'_PerPage');
if(!$per_page)
{
$per_page=10;
}
}
$event->setPseudoClass('_List');
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$object->SetPerPage($per_page);
$object->CountRecs();
$object->SetPage( $this->Application->GetLinkedVar( $event->Prefix_Special.'_Page' ) );
}
/**
* Set's correct sorting for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetSorting(&$event)
{
$event->setPseudoClass('_List');
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir');
//Use default if not specified
/*if ( $cur_sort1 === false || $cur_sort1_dir == false ) {
$cur_sort1 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2_Dir');
}*/
if($cur_sort1 != '' && $cur_sort1_dir != '')
{
$object->AddOrderField($cur_sort1, $cur_sort1_dir);
}
if($cur_sort2 != '' && $cur_sort2_dir != '')
{
$object->AddOrderField($cur_sort2, $cur_sort2_dir);
}
}
/**
* Some kind of filter processing stuff.
* Not in use by now
*
*/
function AddFilters()
{
}
/**
* Set's new sorting for list
*
* @param kEvent $event
* @access protected
*/
function OnSetSorting(&$event)
{
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1',$event->Prefix_Special.'_Sort1');
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1_Dir',$event->Prefix_Special.'_Sort1_Dir');
//$event->setPseudoClass('_List');
- //$object =& $this->createObject(&$event);
+ //$object =& $event->createObject();
}
/**
* Common builder part for Item & List
*
* @param Object $object
* @access private
*/
function dbBuild(&$object,&$event)
{
// set Item & List common parameters from config
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$object->setTableName($table);
$id_field = $this->Application->getUnitOption($event->Prefix,'IDField');
$object->setIDField($id_field);
// get selected ids from post & save them to session
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
$ids=array_keys($items_info);
$this->Application->SetVar($event->getPrefixSpecial().'_selected_ids',implode(',',$ids));
}
$this->Application->LinkVar($event->getPrefixSpecial().'_selected_ids');
// set's any possible hidden fields needed for both Item & List
$current_event = $this->Application->GetVar($event->Prefix_Special.'_event');
$this->Application->setEvent($event->Prefix_Special,$current_event);
}
/**
* Returns select query for loading item/list
*
* @param kEvent $event
* @param string $event_name
* @return string
* @access protected
*/
function getSelectSQL(&$event,$event_name)
{
$new_event =& $this->inheritEvent(&$event);
$new_event->Name=$event_name;
$this->Application->HandleEvent(&$new_event);
return $event->getEventParam('SQLQuery');
}
/**
* Creates needed sql query to load item,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnItemPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ItemSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates needed sql query to load list,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnListPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ListSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates new kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnCreate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info) $field_values = array_shift($items_info);
$object->SetFieldsFromHash($field_values);
if( $object->Create() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
}
}
/**
* Updates kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnUpdate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
//$object->Load($id);
$object->SetFieldsFromHash($field_values);
if( $object->Update($id) )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
}
}
/**
* Delete's kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnDelete(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$object->ID=$this->Application->GetVar($event->Prefix_Special.'_id');
if( $object->Delete() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
/**
* Prepares new kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnNew(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
- $object =& $this->createObject(&$event);
+ $object =& $event->createObject();
$this->prepareObject(&$object,&$event);
$object->setID(0);
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
$event->redirect=false;
}
/**
* Cancel's kDBItem Editing/Creation
*
* @param kEvent $event
* @access protected
*/
function OnCancel(&$event)
{
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_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

Event Timeline