Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Jul 20, 6:33 AM

in-portal

Index: trunk/kernel/units/relationship/relationship_event_handler.php
===================================================================
--- trunk/kernel/units/relationship/relationship_event_handler.php (revision 4721)
+++ trunk/kernel/units/relationship/relationship_event_handler.php (revision 4722)
@@ -1,195 +1,194 @@
<?php
class RelationshipEventHandler extends InpDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnAddRelation' => Array('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Add new relation
*
* @param kEvent $event
*/
function OnAddRelation(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$table_info = $object->getLinkedInfo();
$main_item_type = $this->Application->getUnitOption($table_info['ParentPrefix'],'ItemType');
$target['id'] = $this->Application->GetVar('TargetId');
$target['type'] = $this->Application->GetVar('TargetType');
$object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
$object->SetDBField('SourceType', $main_item_type);
$object->SetDBField('TargetId', $target['id']);
$object->SetDBField('TargetType', $target['type']);
// 1. get item info used in relation
$configs = $this->extractModulesInfo();
foreach($configs as $prefix => $config_data)
{
if($config_data['ItemType'] == $target['type']) break;
}
// this forces prepareOptions of kMultiLanguge formatter to substiture title field (if multilingual) of target item
// BUT this is not the solution, find out another way to get correct title field here
$target_object =& $this->Application->recallObject($prefix, null, Array('skip_autoload' => true));
$title_field = $this->Application->getUnitOption($prefix, 'TitleField');
$item['name'] = $this->Conn->GetOne('SELECT '.$title_field.' FROM '.$config_data['TableName'].' WHERE ResourceId = '.$target['id']);
$item['type'] = $this->Application->Phrase($config_data['TitlePhrase']);
$object->SetDBField('ItemName', $item['name']);
$object->SetDBField('ItemType', $item['type']);
$object->setID(0);
$event->redirect = false;
// 2. substitute opener
$opener_stack = $this->Application->RecallVar('opener_stack');
$opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
array_pop($opener_stack);
$return_template = $this->Application->RecallVar('return_template');
$new_level = 'index4.php|'.ltrim($this->Application->BuildEnv($return_template, Array('m_opener'=>'u'),'all'),ENV_VAR_NAME.'=');
array_push($opener_stack,$new_level);
$this->Application->StoreVar('opener_stack',serialize($opener_stack));
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
}
/**
* 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 ListPrepareQuery(&$event)
{
return $this->BaseQuery($event,'ListSQLs');
}
/**
* 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 ItemPrepareQuery(&$event)
{
return $this->BaseQuery($event,'ItemSQLs');
}
/**
* Get item name & type based on relation type & modules installed
*
* @param kEvent $event
* @param string $sql_field
*/
function BaseQuery(&$event, $sql_field)
{
$sqls = $this->Application->getUnitOption($event->Prefix,$sql_field);
$sql = isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls[''];
$configs = $this->extractModulesInfo();
// 2. build sql based on information queried
$sql_templates['ItemName'] = 'IFNULL(%s.%s,\' \')';
$sql_templates['TableJoin'] = 'LEFT JOIN %1$s ON %1$s.ResourceId = rel.TargetId';
$sql_templates['TargetName'] = 'IF(rel.TargetType = %s, \'%s\', %s)';
$sql_parts = Array();
$sql_parts['TargetName'] = "''";
foreach($configs as $prefix => $config_data)
{
$sql_parts['ItemName'][] = sprintf($sql_templates['ItemName'], $config_data['TableName'], $config_data['TitleField']);
$sql_parts['TableJoin'][] = sprintf($sql_templates['TableJoin'], $config_data['TableName']);
$sql_parts['TargetName'] = sprintf( $sql_templates['TargetName'],
$config_data['ItemType'],
'!'.$config_data['TitlePhrase'].'!',
$sql_parts['TargetName']);
$sql_parts['TargetName'] = str_replace('rel','%1$s',$sql_parts['TargetName']);
}
$object =& $event->getObject();
$vars = Array('#ITEM_NAMES#', '#ITEM_TYPES#');
$replacements = Array( implode(', ',$sql_parts['ItemName']), $sql_parts['TargetName'] );
$calculated_fields =& $object->getProperty('CalculatedFields');
foreach($calculated_fields as $field_name => $field_expression)
{
$calculated_fields[$field_name] = str_replace($vars,$replacements,$field_expression);
}
$object->setProperty('CalculatedFields', $calculated_fields);
$sql = str_replace('#ITEM_JOIN#', implode(' ',$sql_parts['TableJoin']), $sql);
$sql = str_replace('rel.','%1$s.',$sql);
return $sql;
}
/**
* Get configs from modules installed
*
* @return Array
* @access private
*/
function extractModulesInfo()
{
- // 1. get installed modules & their config info
- $db =& $this->Application->GetADODBConnection();
- $prefixes = $db->GetCol('SELECT Var FROM '.TABLE_PREFIX.'Modules');
+ // get installed modules & their config info
+ // maybe we should leave only prefixes, that have "view" permission
$configs = Array();
- foreach($prefixes as $prefix)
- {
+ foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
+ $prefix = $module_data['Var'];
$configs[$prefix] = $this->Application->getUnitOptions($prefix);
if($configs[$prefix] === false) unset($configs[$prefix]);
}
return $configs;
}
/**
* Deletes relations to hooked item from other items
*
* @param kEvent $event
*/
function OnDeleteForeignRelations(&$event)
{
$main_object =& $event->MasterEvent->getObject();
$resource_id = $main_object->GetDBField('ResourceId');
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'DELETE FROM '.$table.' WHERE TargetId = '.$resource_id;
$this->Conn->Query($sql);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/relationship/relationship_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/kernel/admin_templates/xml/tree_categories.tpl
===================================================================
--- trunk/kernel/admin_templates/xml/tree_categories.tpl (revision 4721)
+++ trunk/kernel/admin_templates/xml/tree_categories.tpl (revision 4722)
@@ -1,7 +1,7 @@
<inp2:m_XMLTemplate/>
<inp2:m_DefineElement name="category">
- <folder name="<inp2:Field name="Name"/>" icon="<inp2:c_ModulePath/>img/icons/icon24_catalog.gif" href="<inp2:CategoryLink index_file="browse.php" template="catalog" pass="m"/>" load_url="<inp2:CategoryLink pass="m"/>"></folder>
+ <folder name="<inp2:Field name="Name"/>" icon="<inp2:c_ModulePath/>img/icons/icon24_catalog.gif" href="<inp2:CategoryLink index_file="browse.php" template="catalog" pass="m"/>" onclick="checkEditMode()" load_url="<inp2:CategoryLink pass="m"/>"></folder>
</inp2:m_DefineElement>
<tree>
<inp2:c_ListCategories render_as="category" row_start_render_as="html:" row_end_render_as="html:"/>
</tree>
Property changes on: trunk/kernel/admin_templates/xml/tree_categories.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/units/relationship/relationship_event_handler.php
===================================================================
--- trunk/core/units/relationship/relationship_event_handler.php (revision 4721)
+++ trunk/core/units/relationship/relationship_event_handler.php (revision 4722)
@@ -1,195 +1,194 @@
<?php
class RelationshipEventHandler extends InpDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnAddRelation' => Array('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Add new relation
*
* @param kEvent $event
*/
function OnAddRelation(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$table_info = $object->getLinkedInfo();
$main_item_type = $this->Application->getUnitOption($table_info['ParentPrefix'],'ItemType');
$target['id'] = $this->Application->GetVar('TargetId');
$target['type'] = $this->Application->GetVar('TargetType');
$object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
$object->SetDBField('SourceType', $main_item_type);
$object->SetDBField('TargetId', $target['id']);
$object->SetDBField('TargetType', $target['type']);
// 1. get item info used in relation
$configs = $this->extractModulesInfo();
foreach($configs as $prefix => $config_data)
{
if($config_data['ItemType'] == $target['type']) break;
}
// this forces prepareOptions of kMultiLanguge formatter to substiture title field (if multilingual) of target item
// BUT this is not the solution, find out another way to get correct title field here
$target_object =& $this->Application->recallObject($prefix, null, Array('skip_autoload' => true));
$title_field = $this->Application->getUnitOption($prefix, 'TitleField');
$item['name'] = $this->Conn->GetOne('SELECT '.$title_field.' FROM '.$config_data['TableName'].' WHERE ResourceId = '.$target['id']);
$item['type'] = $this->Application->Phrase($config_data['TitlePhrase']);
$object->SetDBField('ItemName', $item['name']);
$object->SetDBField('ItemType', $item['type']);
$object->setID(0);
$event->redirect = false;
// 2. substitute opener
$opener_stack = $this->Application->RecallVar('opener_stack');
$opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
array_pop($opener_stack);
$return_template = $this->Application->RecallVar('return_template');
$new_level = 'index4.php|'.ltrim($this->Application->BuildEnv($return_template, Array('m_opener'=>'u'),'all'),ENV_VAR_NAME.'=');
array_push($opener_stack,$new_level);
$this->Application->StoreVar('opener_stack',serialize($opener_stack));
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
}
/**
* 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 ListPrepareQuery(&$event)
{
return $this->BaseQuery($event,'ListSQLs');
}
/**
* 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 ItemPrepareQuery(&$event)
{
return $this->BaseQuery($event,'ItemSQLs');
}
/**
* Get item name & type based on relation type & modules installed
*
* @param kEvent $event
* @param string $sql_field
*/
function BaseQuery(&$event, $sql_field)
{
$sqls = $this->Application->getUnitOption($event->Prefix,$sql_field);
$sql = isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls[''];
$configs = $this->extractModulesInfo();
// 2. build sql based on information queried
$sql_templates['ItemName'] = 'IFNULL(%s.%s,\' \')';
$sql_templates['TableJoin'] = 'LEFT JOIN %1$s ON %1$s.ResourceId = rel.TargetId';
$sql_templates['TargetName'] = 'IF(rel.TargetType = %s, \'%s\', %s)';
$sql_parts = Array();
$sql_parts['TargetName'] = "''";
foreach($configs as $prefix => $config_data)
{
$sql_parts['ItemName'][] = sprintf($sql_templates['ItemName'], $config_data['TableName'], $config_data['TitleField']);
$sql_parts['TableJoin'][] = sprintf($sql_templates['TableJoin'], $config_data['TableName']);
$sql_parts['TargetName'] = sprintf( $sql_templates['TargetName'],
$config_data['ItemType'],
'!'.$config_data['TitlePhrase'].'!',
$sql_parts['TargetName']);
$sql_parts['TargetName'] = str_replace('rel','%1$s',$sql_parts['TargetName']);
}
$object =& $event->getObject();
$vars = Array('#ITEM_NAMES#', '#ITEM_TYPES#');
$replacements = Array( implode(', ',$sql_parts['ItemName']), $sql_parts['TargetName'] );
$calculated_fields =& $object->getProperty('CalculatedFields');
foreach($calculated_fields as $field_name => $field_expression)
{
$calculated_fields[$field_name] = str_replace($vars,$replacements,$field_expression);
}
$object->setProperty('CalculatedFields', $calculated_fields);
$sql = str_replace('#ITEM_JOIN#', implode(' ',$sql_parts['TableJoin']), $sql);
$sql = str_replace('rel.','%1$s.',$sql);
return $sql;
}
/**
* Get configs from modules installed
*
* @return Array
* @access private
*/
function extractModulesInfo()
{
- // 1. get installed modules & their config info
- $db =& $this->Application->GetADODBConnection();
- $prefixes = $db->GetCol('SELECT Var FROM '.TABLE_PREFIX.'Modules');
+ // get installed modules & their config info
+ // maybe we should leave only prefixes, that have "view" permission
$configs = Array();
- foreach($prefixes as $prefix)
- {
+ foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
+ $prefix = $module_data['Var'];
$configs[$prefix] = $this->Application->getUnitOptions($prefix);
if($configs[$prefix] === false) unset($configs[$prefix]);
}
return $configs;
}
/**
* Deletes relations to hooked item from other items
*
* @param kEvent $event
*/
function OnDeleteForeignRelations(&$event)
{
$main_object =& $event->MasterEvent->getObject();
$resource_id = $main_object->GetDBField('ResourceId');
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'DELETE FROM '.$table.' WHERE TargetId = '.$resource_id;
$this->Conn->Query($sql);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/relationship/relationship_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/core/admin_templates/categories/xml/tree_categories.tpl
===================================================================
--- trunk/core/admin_templates/categories/xml/tree_categories.tpl (revision 4721)
+++ trunk/core/admin_templates/categories/xml/tree_categories.tpl (revision 4722)
@@ -1,7 +1,7 @@
<inp2:m_XMLTemplate/>
<inp2:m_DefineElement name="category">
- <folder name="<inp2:Field name="Name"/>" icon="<inp2:c_ModulePath/>img/icons/icon24_catalog.gif" href="<inp2:CategoryLink index_file="browse.php" template="catalog" pass="m"/>" load_url="<inp2:CategoryLink pass="m"/>"></folder>
+ <folder name="<inp2:Field name="Name"/>" icon="<inp2:c_ModulePath/>img/icons/icon24_catalog.gif" href="<inp2:CategoryLink index_file="browse.php" template="catalog" pass="m"/>" onclick="checkEditMode()" load_url="<inp2:CategoryLink pass="m"/>"></folder>
</inp2:m_DefineElement>
<tree>
<inp2:c_ListCategories render_as="category" row_start_render_as="html:" row_end_render_as="html:"/>
</tree>
Property changes on: trunk/core/admin_templates/categories/xml/tree_categories.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property

Event Timeline