Index: branches/5.3.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r15677 -r15698 --- branches/5.3.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15677) +++ branches/5.3.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15698) @@ -1,6 +1,6 @@ Application->recallObject('ListHelper'); /* @var $list_helper ListHelper */ - $select_clause = $this->Application->getUnitOption($object->Prefix, 'NavigationSelectClause', NULL); + $select_clause = $object->getUnitConfig()->getNavigationSelectClause(NULL); return $list_helper->getNavigationResource($object, $event->getEventParam('list'), $event->Special == 'next', $select_clause); } @@ -236,8 +236,7 @@ $main_object = $this->Application->recallObject($regs[1]); /* @var $main_object kDBItem */ - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - return $main_object->GetDBField($id_field); + return $main_object->GetDBField($event->getUnitConfig()->getIDField()); } // 1. get id from post (used in admin) @@ -311,8 +310,10 @@ // get selected ids from post & save them to session $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + if ( $items_info ) { - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $id_field = $event->getUnitConfig()->getIDField(); + foreach ($items_info as $id => $field_values) { if ( getArrayValue($field_values, $id_field) ) { array_push($ids, $id); @@ -409,14 +410,15 @@ protected function getRequestProtectedFields($hash) { // by default don't allow changing ID or foreign key from request + $config = $this->getUnitConfig(); + $fields = Array (); - $fields[] = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $fields[] = $config->getIDField(); - $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); + $parent_prefix = $config->getParentPrefix(); if ( $parent_prefix && !$this->Application->isAdmin ) { - $foreign_key = $this->Application->getUnitOption($this->Prefix, 'ForeignKey'); - $fields[] = is_array($foreign_key) ? $foreign_key[$parent_prefix] : $foreign_key; + $fields[] = $config->getForeignKey($parent_prefix); } return $fields; @@ -467,7 +469,7 @@ $form_name = (string)getArrayValue($request_forms, $object->getPrefixSpecial()); } - $object->Configure($event->getEventParam('populate_ml_fields') || $this->Application->getUnitOption($event->Prefix, 'PopulateMlFields'), $form_name); + $object->Configure($event->getEventParam('populate_ml_fields') || $event->getUnitConfig()->getPopulateMlFields(), $form_name); $this->PrepareObject($object, $event); $parent_event = $event->getEventParam('parent_event'); @@ -498,13 +500,12 @@ */ protected function checkItemStatus(kEvent $event) { - $status_fields = $this->Application->getUnitOption($event->Prefix, 'StatusField'); - if ( !$status_fields ) { + $status_field = $event->getUnitConfig()->getStatusField(true); + + if ( !$status_field ) { return true; } - $status_field = array_shift($status_fields); - if ( $status_field == 'Status' || $status_field == 'Enabled' ) { $object = $event->getObject(); /* @var $object kDBItem */ @@ -571,7 +572,7 @@ $object->setSelectSQL($sql); // 2. loads if allowed - $auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad'); + $auto_load = $event->getUnitConfig()->getAutoLoad(); $skip_autoload = $event->getEventParam('skip_autoload'); if ( $auto_load && !$skip_autoload ) { @@ -970,7 +971,7 @@ if ( $per_page ) { // per-page is passed as tag parameter to PrintList, InitList, etc. - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $config_mapping = $event->getUnitConfig()->getConfigMapping(); // 2. per-page setting is stored in configuration variable if ( $config_mapping ) { @@ -1138,22 +1139,22 @@ */ protected function _getDefaultSorting(kEvent $event) { - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); - $sorting_prefix = array_key_exists($event->Special, $list_sortings) ? $event->Special : ''; - $sorting_configs = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $config = $event->getUnitConfig(); + $sorting_configs = $config->getConfigMapping(); + $list_sortings = $config->getListSortingsBySpecial($event); if ( $sorting_configs && array_key_exists('DefaultSorting1Field', $sorting_configs) ) { // sorting defined in configuration variables overrides one from unit config - $list_sortings[$sorting_prefix]['Sorting'] = Array ( + $list_sortings['Sorting'] = Array ( $this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']), $this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']), ); // TODO: lowercase configuration variable values in db, instead of here - $list_sortings[$sorting_prefix]['Sorting'] = array_map('strtolower', $list_sortings[$sorting_prefix]['Sorting']); + $list_sortings['Sorting'] = array_map('strtolower', $list_sortings['Sorting']); } - return isset($list_sortings[$sorting_prefix]) ? $list_sortings[$sorting_prefix] : Array (); + return $list_sortings ? $list_sortings : Array (); } /** @@ -1268,7 +1269,7 @@ $temp_filter = $this->Application->makeClass('kMultipleFilter'); /* @var $temp_filter kMultipleFilter */ - $filter_menu = $this->Application->getUnitOption($event->Prefix, 'FilterMenu'); + $filter_menu = $event->getUnitConfig()->getFilterMenu(); $group_key = 0; $group_count = count($filter_menu['Groups']); @@ -1323,7 +1324,7 @@ ); $sql = 'SELECT * - FROM ' . $this->Application->getUnitOption('item-filter', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('item-filter')->getTableName() . ' WHERE (' . implode(') AND (', $where_clause) . ')'; $filters = $this->Conn->Query($sql, 'FilterField'); @@ -1681,8 +1682,10 @@ */ protected function OnDeleteAll(kEvent $event) { - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName(); $ids = $this->Conn->GetCol($sql); if ( $ids ) { @@ -1977,29 +1980,29 @@ } // save changes to database - $sesion_log_id = $this->Application->RecallVar('_SessionLogId_'); + $session_log_id = $this->Application->RecallVar('_SessionLogId_'); - if (!$save || !$sesion_log_id) { + if (!$save || !$session_log_id) { // saving changes to database disabled OR related session log missing return ; } $add_fields = Array ( 'PortalUserId' => $this->Application->RecallVar('user_id'), - 'SessionLogId' => $sesion_log_id, + 'SessionLogId' => $session_log_id, ); - $change_log_table = $this->Application->getUnitOption('change-log', 'TableName'); + $change_log_table = $this->Application->getUnitConfig('change-log')->getTableName(); foreach ($changes as $rec) { $this->Conn->doInsert(array_merge($rec, $add_fields), $change_log_table); } $this->Application->incrementCacheSerial('change-log'); - $sql = 'UPDATE ' . $this->Application->getUnitOption('session-log', 'TableName') . ' + $sql = 'UPDATE ' . $this->Application->getUnitConfig('session-log')->getTableName() . ' SET AffectedItems = AffectedItems + ' . count($changes) . ' - WHERE SessionLogId = ' . $sesion_log_id; + WHERE SessionLogId = ' . $session_log_id; $this->Conn->Query($sql); $this->Application->incrementCacheSerial('session-log'); @@ -2256,8 +2259,9 @@ $ids = $this->StoreSelectedIDs($event); if ( $ids ) { - $status_field = $object->getStatusField(); - $order_field = $this->Application->getUnitOption($event->Prefix, 'OrderField'); + $config = $event->getUnitConfig(); + $status_field = $config->getStatusField(true); + $order_field = $config->getOrderField(); if ( !$order_field ) { $order_field = 'Priority'; @@ -2481,11 +2485,8 @@ // 1. delete direct subscriptions to item, that was deleted $this->_deleteSubscriptions($event->Prefix, 'ItemId', $object->GetID()); - $sub_items = $this->Application->getUnitOption($event->Prefix, 'SubItems', Array ()); - /* @var $sub_items Array */ - // 2. delete this item sub-items subscriptions, that reference item, that was deleted - foreach ($sub_items as $sub_prefix) { + foreach ($event->getUnitConfig()->getSubItems(Array ()) as $sub_prefix) { $this->_deleteSubscriptions($sub_prefix, 'ParentItemId', $object->GetID()); } } @@ -2502,7 +2503,7 @@ protected function _deleteSubscriptions($prefix, $field, $value) { $sql = 'SELECT TemplateId - FROM ' . $this->Application->getUnitOption('email-template', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('email-template')->getTableName() . ' WHERE BindToSystemEvent REGEXP "' . $this->Conn->escape($prefix) . '(\\\\.[^:]*:.*|:.*)"'; $email_template_ids = $this->Conn->GetCol($sql); @@ -2788,7 +2789,7 @@ protected function FilterAction(kEvent $event) { $view_filter = Array (); - $filter_menu = $this->Application->getUnitOption($event->Prefix, 'FilterMenu'); + $filter_menu = $event->getUnitConfig()->getFilterMenu(); switch ($event->Name) { case 'OnRemoveFilters': @@ -3159,11 +3160,8 @@ } $field_name = $this->Application->GetVar('field'); - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); - $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); - $field_options = array_key_exists($field_name, $fields) ? $fields[$field_name] : $virtual_fields[$field_name]; + $field_options = $this->_getUploadFieldDefinition($event, $field_name); - $upload_dir = $field_options['upload_dir']; $storage_format = array_key_exists('storage_format', $field_options) ? $field_options['storage_format'] : false; if ( !is_writable($tmp_path) ) { @@ -3202,6 +3200,26 @@ } /** + * Returns upload field definition + * + * @param kEvent $event + * @param string $field_name + * @return Array + * @access protected + */ + protected function _getUploadFieldDefinition(kEvent $event, $field_name) + { + $config = $event->getUnitConfig(); + $ret = $config->getFieldByName($field_name); + + if ( !$ret ) { + $ret = $config->getVirtualFieldByName($field_name); + } + + return $ret; + } + + /** * Delete temporary files, that won't be used for sure * * @param string $path @@ -3457,7 +3475,6 @@ $field = $this->Application->GetVar('field'); $cur_value = $this->Application->GetVar('cur_value'); - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); $object = $event->getObject(); @@ -3471,7 +3488,7 @@ } $sql = 'SELECT DISTINCT ' . $field . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + FROM ' . $event->getUnitConfig()->getTableName() . ' WHERE ' . $field . ' LIKE ' . $this->Conn->qstr($cur_value . '%') . ' ORDER BY ' . $field . ' LIMIT 0,' . $limit; @@ -3536,11 +3553,11 @@ */ protected function OnCloneSubItem(kEvent $event) { - $clones = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Clones'); + $sub_item_prefix = $event->Prefix . '-' . preg_replace('/^#/', '', $event->MasterEvent->Prefix); - $subitem_prefix = $event->Prefix . '-' . preg_replace('/^#/', '', $event->MasterEvent->Prefix); - $clones[$subitem_prefix] = Array ('ParentPrefix' => $event->Prefix); - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones); + $event->MasterEvent->getUnitConfig()->addClones(Array ( + $sub_item_prefix => Array ('ParentPrefix' => $event->Prefix), + )); } /**