Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773345
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, 8:45 AM
Size
15 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 8:45 AM (57 m, 18 s)
Engine
blob
Format
Raw Data
Handle
556580
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/core/kernel/db/db_tag_processor.php
===================================================================
--- trunk/core/kernel/db/db_tag_processor.php (revision 937)
+++ trunk/core/kernel/db/db_tag_processor.php (revision 938)
@@ -1,138 +1,141 @@
<?php
class kDBTagProcessor extends TagProcessor {
/**
* Prints list content using block specified
*
* @param Array $params
* @return string
* @access public
*/
function PrintList($params)
{
$list =& $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params);
$id_field = $this->Application->getUnitOption($this->Prefix,'IDField');
//<inp:cand_MapField field="candidate_id" var_name="cand_id"/>
/*$parser =& $this->Application->recallObject('TemplateParser');
// only useful in case in inside prinklist block we have another
// tagprocessor who wants to findout out printlist prefix and special
$parser->SetParam('prefix', $this->Prefix);
$parser->SetParam('special', $this->Special);*/
$list->Query();
$o = '';
$list->GoFirst();
$block_params=$this->prepareTagParams($params);
$block_params['name']=$params['block'];
$block_params['pass_params']='true';
while (!$list->EOL())
{
$this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) );
$o.= $this->Application->ParseBlock($block_params, 1);
$list->GoNext();
}
return $o;
}
/**
* Append prefix and special to tag
* params (get them from tagname) like
* they were really passed as params
*
* @param Array $tag_params
* @return Array
* @access protected
*/
function prepareTagParams($tag_params)
{
$ret=$tag_params;
$ret['Prefix']=$this->Prefix;
$ret['Special']=$this->Special;
$ret['PrefixSpecial']=$this->getPrefixSpecial();
return $ret;
}
/**
* Get's reuested field value
*
* @param Array $params
* @return string
* @access public
*/
function Field($params)
{
$field = $params['field'];
$object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
$value = $object->GetField($field);
if (isset($params['nl2br'])) $value = nl2br($value);
return $value;
}
/**
* Print grid pagination using
* block names specified
*
* @param Array $params
* @return string
* @access public
*/
function PrintPages($params)
{
$prefix_special=$this->getPrefixSpecial();
$object =& $this->Application->recallObject($prefix_special,$this->Prefix.'_List',$params);
$total = $object->GetTotalPages();
$o = '';
- $this->Application->SetVar($prefix_special.'_event','OnSetPage');
+
+ $this->Application->SetVar($prefix_special.'_event','');
+ $this->Application->SetVar($prefix_special.'_id','');
+
$current_page = $this->Application->RecallVar($prefix_special.'_page');
$block_params=$this->prepareTagParams($params);
for ($i=1; $i<=$total; $i++)
{
$this->Application->SetVar($prefix_special.'_page',$i);
$block = $params[ (($i==$current_page)?'active':'inactive').'_block' ];
$block_params['name']=$block;
$block_params['page']=$i;
$o .= $this->Application->ParseBlock($block_params, 1);
}
return $o;
}
/*function MapField($params)
{
$object =& $this->Application->recallObject($this->Prefix.'.'.$this->Special);
$value = $object->GetField($params['field']);
$this->Application->SetVar($params['var_name'],$value);
}*/
/**
* Returns input field name to
* be placed on form (for correct
* event processing)
*
* @param Array $params
* @return string
* @access public
*/
function InputName($params)
{
$prefix_special=$this->getPrefixSpecial();
$item = $this->Application->recallObject($prefix_special);
return $prefix_special.'['.$item->GetID().']['.$params['field'].']';
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_tag_processor.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 937)
+++ trunk/core/kernel/db/db_event_handler.php (revision 938)
@@ -1,409 +1,382 @@
<?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 {
/**
- * Loads item only
- *
- * @param kEvent $event
- * @access protected
- */
- function OnLoad(&$event)
- {
- $object =& $this->createObject(&$event);
- $this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnUpdate');
- $event->redirect=false;
- }
-
- /**
* 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);
$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);
}
}
/**
* Builds list
*
* @param kEvent $event
* @access protected
*/
function OnListBuild(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$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->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);
$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 page for list
- *
- * @param kEvent $event
- * @access protected
- */
- function OnSetPage(&$event)
- {
- $event->setPseudoClass('_List');
- $object =& $this->createObject(&$event);
- $new_page =& $this->Application->GetVar($event->Prefix_Special.'_page');
- $object->SetPage($new_page);
- }
-
- /**
* 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);
}
/**
* 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);
$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);
$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->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);
$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.2
\ No newline at end of property
+1.3
\ No newline at end of property
Event Timeline
Log In to Comment