Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r14974 -r14989 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14974) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14989) @@ -1,6 +1,6 @@ getPrefixSpecial(true) instead of * $event->getPrefixSpecial() 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 + * 1st parameter returns correct current Prefix_Special + * for variables being 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". * @@ -51,40 +51,40 @@ * @return bool * @access public */ - function CheckPermission(&$event) + public function CheckPermission(kEvent &$event) { $section = $event->getSection(); - if (!$this->Application->isAdmin) { - $allow_events = Array('OnSearch', 'OnSearchReset', 'OnNew'); - if (in_array($event->Name, $allow_events)) { + if ( !$this->Application->isAdmin ) { + $allow_events = Array ('OnSearch', 'OnSearchReset', 'OnNew'); + if ( in_array($event->Name, $allow_events) ) { // allow search on front return true; } } - elseif (($event->Name == 'OnPreSaveAndChangeLanguage') && !$this->UseTempTables($event)) { + elseif ( ($event->Name == 'OnPreSaveAndChangeLanguage') && !$this->UseTempTables($event) ) { // allow changing language in grids, when not in editing mode return $this->Application->CheckPermission($section . '.view', 1); } - if (!preg_match('/^CATEGORY:(.*)/', $section)) { + if ( !preg_match('/^CATEGORY:(.*)/', $section) ) { // only if not category item events - if ((substr($event->Name, 0, 9) == 'OnPreSave') || ($event->Name == 'OnSave')) { - if ($this->isNewItemCreate($event)) { - return $this->Application->CheckPermission($section.'.add', 1); + if ( (substr($event->Name, 0, 9) == 'OnPreSave') || ($event->Name == 'OnSave') ) { + if ( $this->isNewItemCreate($event) ) { + return $this->Application->CheckPermission($section . '.add', 1); } else { - return $this->Application->CheckPermission($section.'.add', 1) || $this->Application->CheckPermission($section.'.edit', 1); + return $this->Application->CheckPermission($section . '.add', 1) || $this->Application->CheckPermission($section . '.edit', 1); } } } - if ($event->Name == 'OnPreCreate') { + if ( $event->Name == 'OnPreCreate' ) { // save category_id before item create (for item category selector not to destroy permission checking category) $this->Application->LinkVar('m_cat_id'); } - if ($event->Name == 'OnSaveWidths') { + if ( $event->Name == 'OnSaveWidths' ) { return $this->Application->isAdminUser; } @@ -94,96 +94,108 @@ /** * Allows to override standard permission mapping * + * @return void + * @access protected + * @see kEventHandler::$permMapping */ - function mapPermissions() + protected function mapPermissions() { parent::mapPermissions(); - $permissions = Array( - 'OnLoad' => Array('self' => 'view', 'subitem' => 'view'), - 'OnItemBuild' => Array('self' => 'view', 'subitem' => 'view'), - 'OnSuggestValues' => Array('self' => 'view', 'subitem' => 'view'), - 'OnBuild' => Array('self' => true), + $permissions = Array ( + 'OnLoad' => Array ('self' => 'view', 'subitem' => 'view'), + 'OnItemBuild' => Array ('self' => 'view', 'subitem' => 'view'), + 'OnSuggestValues' => Array ('self' => 'view', 'subitem' => 'view'), - 'OnNew' => Array('self' => 'add', 'subitem' => 'add|edit'), - 'OnCreate' => Array('self' => 'add', 'subitem' => 'add|edit'), - 'OnUpdate' => Array('self' => 'edit', 'subitem' => 'add|edit'), - 'OnSetPrimary' => Array('self' => 'add|edit', 'subitem' => 'add|edit'), - 'OnDelete' => Array('self' => 'delete', 'subitem' => 'add|edit'), - 'OnDeleteAll' => Array('self' => 'delete', 'subitem' => 'add|edit'), - 'OnMassDelete' => Array('self' => 'delete', 'subitem' => 'add|edit'), - 'OnMassClone' => Array('self' => 'add', 'subitem' => 'add|edit'), + 'OnBuild' => Array ('self' => true), - 'OnCut' => array('self'=>'edit', 'subitem' => 'edit'), - 'OnCopy' => array('self'=>'edit', 'subitem' => 'edit'), - 'OnPaste' => array('self'=>'edit', 'subitem' => 'edit'), + 'OnNew' => Array ('self' => 'add', 'subitem' => 'add|edit'), + 'OnCreate' => Array ('self' => 'add', 'subitem' => 'add|edit'), + 'OnUpdate' => Array ('self' => 'edit', 'subitem' => 'add|edit'), + 'OnSetPrimary' => Array ('self' => 'add|edit', 'subitem' => 'add|edit'), + 'OnDelete' => Array ('self' => 'delete', 'subitem' => 'add|edit'), + 'OnDeleteAll' => Array ('self' => 'delete', 'subitem' => 'add|edit'), + 'OnMassDelete' => Array ('self' => 'delete', 'subitem' => 'add|edit'), + 'OnMassClone' => Array ('self' => 'add', 'subitem' => 'add|edit'), - 'OnSelectItems' => Array('self' => 'add|edit', 'subitem' => 'add|edit'), - 'OnProcessSelected' => Array('self' => 'add|edit', 'subitem' => 'add|edit'), - 'OnStoreSelected' => Array('self' => 'add|edit', 'subitem' => 'add|edit'), - 'OnSelectUser' => Array('self' => 'add|edit', 'subitem' => 'add|edit'), + 'OnCut' => Array ('self'=>'edit', 'subitem' => 'edit'), + 'OnCopy' => Array ('self'=>'edit', 'subitem' => 'edit'), + 'OnPaste' => Array ('self'=>'edit', 'subitem' => 'edit'), - 'OnMassApprove' => Array('self' => 'advanced:approve|edit', 'subitem' => 'advanced:approve|add|edit'), - 'OnMassDecline' => Array('self' => 'advanced:decline|edit', 'subitem' => 'advanced:decline|add|edit'), - 'OnMassMoveUp' => Array('self' => 'advanced:move_up|edit', 'subitem' => 'advanced:move_up|add|edit'), - 'OnMassMoveDown' => Array('self' => 'advanced:move_down|edit', 'subitem' => 'advanced:move_down|add|edit'), + 'OnSelectItems' => Array ('self' => 'add|edit', 'subitem' => 'add|edit'), + 'OnProcessSelected' => Array ('self' => 'add|edit', 'subitem' => 'add|edit'), + 'OnStoreSelected' => Array ('self' => 'add|edit', 'subitem' => 'add|edit'), + 'OnSelectUser' => Array ('self' => 'add|edit', 'subitem' => 'add|edit'), - 'OnPreCreate' => Array('self' => 'add|add.pending', 'subitem' => 'edit|edit.pending'), - 'OnEdit' => Array('self' => 'edit|edit.pending', 'subitem' => 'edit|edit.pending'), + 'OnMassApprove' => Array ('self' => 'advanced:approve|edit', 'subitem' => 'advanced:approve|add|edit'), + 'OnMassDecline' => Array ('self' => 'advanced:decline|edit', 'subitem' => 'advanced:decline|add|edit'), + 'OnMassMoveUp' => Array ('self' => 'advanced:move_up|edit', 'subitem' => 'advanced:move_up|add|edit'), + 'OnMassMoveDown' => Array ('self' => 'advanced:move_down|edit', 'subitem' => 'advanced:move_down|add|edit'), - 'OnExport' => Array('self' => 'view|advanced:export'), - 'OnExportBegin' => Array('self' => 'view|advanced:export'), - 'OnExportProgress' => Array('self' => 'view|advanced:export'), + 'OnPreCreate' => Array ('self' => 'add|add.pending', 'subitem' => 'edit|edit.pending'), + 'OnEdit' => Array ('self' => 'edit|edit.pending', 'subitem' => 'edit|edit.pending'), + 'OnExport' => Array ('self' => 'view|advanced:export'), + 'OnExportBegin' => Array ('self' => 'view|advanced:export'), + 'OnExportProgress' => Array ('self' => 'view|advanced:export'), - 'OnSetAutoRefreshInterval' => Array ('self' => true, 'subitem' => true), - 'OnAutoRefreshToggle' => Array ('self' => true, 'subitem' => true), - // theese event do not harm, but just in case check them too :) - 'OnCancelEdit' => Array('self' => true, 'subitem' => true), - 'OnCancel' => Array('self' => true, 'subitem' => true), - 'OnReset' => Array('self' => true, 'subitem' => true), + 'OnSetAutoRefreshInterval' => Array ('self' => true, 'subitem' => true), + 'OnAutoRefreshToggle' => Array ('self' => true, 'subitem' => true), - 'OnSetSorting' => Array('self' => true, 'subitem' => true), - 'OnSetSortingDirect' => Array('self' => true, 'subitem' => true), - 'OnResetSorting' => Array('self' => true, 'subitem' => true), + // theese event do not harm, but just in case check them too :) + 'OnCancelEdit' => Array ('self' => true, 'subitem' => true), + 'OnCancel' => Array ('self' => true, 'subitem' => true), + 'OnReset' => Array ('self' => true, 'subitem' => true), - 'OnSetFilter' => Array('self' => true, 'subitem' => true), - 'OnApplyFilters' => Array('self' => true, 'subitem' => true), - 'OnRemoveFilters' => Array('self' => true, 'subitem' => true), - 'OnSetFilterPattern' => Array('self' => true, 'subitem' => true), + 'OnSetSorting' => Array ('self' => true, 'subitem' => true), + 'OnSetSortingDirect' => Array ('self' => true, 'subitem' => true), + 'OnResetSorting' => Array ('self' => true, 'subitem' => true), - 'OnSetPerPage' => Array('self' => true, 'subitem' => true), - 'OnSetPage' => Array('self' => true, 'subitem' => true), + 'OnSetFilter' => Array ('self' => true, 'subitem' => true), + 'OnApplyFilters' => Array ('self' => true, 'subitem' => true), + 'OnRemoveFilters' => Array ('self' => true, 'subitem' => true), + 'OnSetFilterPattern' => Array ('self' => true, 'subitem' => true), - 'OnSearch' => Array('self' => true, 'subitem' => true), - 'OnSearchReset' => Array('self' => true, 'subitem' => true), + 'OnSetPerPage' => Array ('self' => true, 'subitem' => true), + 'OnSetPage' => Array ('self' => true, 'subitem' => true), - 'OnGoBack' => Array('self' => true, 'subitem' => true), + 'OnSearch' => Array ('self' => true, 'subitem' => true), + 'OnSearchReset' => Array ('self' => true, 'subitem' => true), - // it checks permission itself since flash uploader does not send cookies - 'OnUploadFile' => Array ('self' => true, 'subitem' => true), - 'OnDeleteFile' => Array ('self' => true, 'subitem' => true), + 'OnGoBack' => Array ('self' => true, 'subitem' => true), - 'OnViewFile' => Array ('self' => true, 'subitem' => true), - 'OnSaveWidths' => Array ('self' => true, 'subitem' => true), + // it checks permission itself since flash uploader does not send cookies + 'OnUploadFile' => Array ('self' => true, 'subitem' => true), + 'OnDeleteFile' => Array ('self' => true, 'subitem' => true), - 'OnValidateMInputFields' => Array ('self' => 'view'), - 'OnValidateField' => Array ('self' => true, 'subitem' => true), - ); + 'OnViewFile' => Array ('self' => true, 'subitem' => true), + 'OnSaveWidths' => Array ('self' => true, 'subitem' => true), + + 'OnValidateMInputFields' => Array ('self' => 'view'), + 'OnValidateField' => Array ('self' => true, 'subitem' => true), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { - $events_map = Array( - 'OnRemoveFilters' => 'FilterAction', - 'OnApplyFilters' => 'FilterAction', - 'OnMassApprove'=>'iterateItems', - 'OnMassDecline'=>'iterateItems', - 'OnMassMoveUp'=>'iterateItems', - 'OnMassMoveDown'=>'iterateItems', - ); + $events_map = Array ( + 'OnRemoveFilters' => 'FilterAction', + 'OnApplyFilters' => 'FilterAction', + 'OnMassApprove' => 'iterateItems', + 'OnMassDecline' => 'iterateItems', + 'OnMassMoveUp' => 'iterateItems', + 'OnMassMoveDown' => 'iterateItems', + ); $this->eventMethods = array_merge($this->eventMethods, $events_map); } @@ -197,15 +209,16 @@ * * @param kEvent $event * @return int + * @access public */ - function getPassedID(&$event) + public function getPassedID(kEvent &$event) { - if ($event->getEventParam('raise_warnings') === false) { + if ( $event->getEventParam('raise_warnings') === false ) { $event->setEventParam('raise_warnings', 1); } if ( $event->Special == 'previous' || $event->Special == 'next' ) { - $object =& $this->Application->recallObject( $event->getEventParam('item') ); + $object =& $this->Application->recallObject($event->getEventParam('item')); /* @var $object kDBItem */ $list_helper =& $this->Application->recallObject('ListHelper'); @@ -220,7 +233,7 @@ return 0; } - if (preg_match('/^auto-(.*)/', $event->Special, $regs) && $this->Application->prefixRegistred($regs[1])) { + if ( preg_match('/^auto-(.*)/', $event->Special, $regs) && $this->Application->prefixRegistred($regs[1]) ) { // - returns field DateFormat value from language (LanguageId is extracted from current phrase object) $main_object =& $this->Application->recallObject($regs[1]); /* @var $main_object kDBItem */ @@ -230,28 +243,28 @@ } // 1. get id from post (used in admin) - $ret = $this->Application->GetVar($event->getPrefixSpecial(true).'_id'); - if (($ret !== false) && ($ret != '')) { + $ret = $this->Application->GetVar($event->getPrefixSpecial(true) . '_id'); + if ( ($ret !== false) && ($ret != '') ) { return $ret; } // 2. get id from env (used in front) - $ret = $this->Application->GetVar($event->getPrefixSpecial().'_id'); - if (($ret !== false) && ($ret != '')) { + $ret = $this->Application->GetVar($event->getPrefixSpecial() . '_id'); + if ( ($ret !== false) && ($ret != '') ) { return $ret; } // recall selected ids array and use the first one - $ids = $this->Application->GetVar($event->getPrefixSpecial().'_selected_ids'); - if ($ids != '') { - $ids = explode(',',$ids); - if ($ids) { + $ids = $this->Application->GetVar($event->getPrefixSpecial() . '_selected_ids'); + if ( $ids != '' ) { + $ids = explode(',', $ids); + if ( $ids ) { $ret = array_shift($ids); } } else { // if selected ids are not yet stored $this->StoreSelectedIDs($event); - return $this->Application->GetVar($event->getPrefixSpecial().'_id'); // StoreSelectedIDs sets this variable + return $this->Application->GetVar($event->getPrefixSpecial() . '_id'); // StoreSelectedIDs sets this variable } return $ret; @@ -265,19 +278,19 @@ * * @param kEvent $event * @param Array $direct_ids - * - * @return Array ids stored + * @return Array + * @access protected */ - function StoreSelectedIDs(&$event, $direct_ids = null) + protected function StoreSelectedIDs(kEvent &$event, $direct_ids = null) { $wid = $this->Application->GetTopmostWid($event->Prefix); - $session_name = rtrim($event->getPrefixSpecial().'_selected_ids_'.$wid, '_'); + $session_name = rtrim($event->getPrefixSpecial() . '_selected_ids_' . $wid, '_'); $ids = $event->getEventParam('ids'); - if (isset($direct_ids) || ($ids !== false)) { + if ( isset($direct_ids) || ($ids !== false) ) { // save ids directly if they given + reset array indexes $resulting_ids = $direct_ids ? array_values($direct_ids) : ($ids ? array_values($ids) : false); - if ($resulting_ids) { + if ( $resulting_ids ) { $this->Application->SetVar($event->getPrefixSpecial() . '_selected_ids', implode(',', $resulting_ids)); $this->Application->LinkVar($event->getPrefixSpecial() . '_selected_ids', $session_name, '', true); $this->Application->SetVar($event->getPrefixSpecial() . '_id', $resulting_ids[0]); @@ -288,38 +301,37 @@ return Array (); } - $ret = Array(); + $ret = Array (); // May be we don't need this part: ? - $passed = $this->Application->GetVar($event->getPrefixSpecial(true).'_id'); - if($passed !== false && $passed != '') - { + $passed = $this->Application->GetVar($event->getPrefixSpecial(true) . '_id'); + if ( $passed !== false && $passed != '' ) { array_push($ret, $passed); } - $ids = Array(); + $ids = Array (); // 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'); - foreach($items_info as $id => $field_values) - { - if( getArrayValue($field_values,$id_field) ) array_push($ids,$id); + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + if ( $items_info ) { + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + foreach ($items_info as $id => $field_values) { + if ( getArrayValue($field_values, $id_field) ) { + array_push($ids, $id); + } } - //$ids=array_keys($items_info); + //$ids = array_keys($items_info); } $ret = array_unique(array_merge($ret, $ids)); - $this->Application->SetVar($event->getPrefixSpecial().'_selected_ids', implode(',',$ret)); - $this->Application->LinkVar($event->getPrefixSpecial().'_selected_ids', $session_name, '', !$ret); // optional when IDs are missing + $this->Application->SetVar($event->getPrefixSpecial() . '_selected_ids', implode(',', $ret)); + $this->Application->LinkVar($event->getPrefixSpecial() . '_selected_ids', $session_name, '', !$ret); // optional when IDs are missing // This is critical - otherwise getPassedID will return last ID stored in session! (not exactly true) // this smells... needs to be refactored - $first_id = getArrayValue($ret,0); - if (($first_id === false) && ($event->getEventParam('raise_warnings') == 1)) { + $first_id = getArrayValue($ret, 0); + if ( ($first_id === false) && ($event->getEventParam('raise_warnings') == 1) ) { if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->appendTrace(); } @@ -336,17 +348,18 @@ * * @param kEvent $event * @param bool $from_session return ids from session (written, when editing was started) - * @return array + * @return Array + * @access protected */ - function getSelectedIDs(&$event, $from_session = false) + protected function getSelectedIDs(kEvent &$event, $from_session = false) { - if ($from_session) { + if ( $from_session ) { $wid = $this->Application->GetTopmostWid($event->Prefix); - $var_name = rtrim($event->getPrefixSpecial().'_selected_ids_'.$wid, '_'); + $var_name = rtrim($event->getPrefixSpecial() . '_selected_ids_' . $wid, '_'); $ret = $this->Application->RecallVar($var_name); } else { - $ret = $this->Application->GetVar($event->getPrefixSpecial().'_selected_ids'); + $ret = $this->Application->GetVar($event->getPrefixSpecial() . '_selected_ids'); } return explode(',', $ret); @@ -356,30 +369,35 @@ * Stores IDs, selected in grid in session * * @param kEvent $event + * @return void + * @access protected */ - function OnStoreSelected(&$event) + protected function OnStoreSelected(kEvent &$event) { $this->StoreSelectedIDs($event); $id = $this->Application->GetVar($event->getPrefixSpecial() . '_id'); - if ($id !== false) { + if ( $id !== false ) { $event->SetRedirectParam($event->getPrefixSpecial() . '_id', $id); $event->SetRedirectParam('pass', 'all,' . $event->getPrefixSpecial()); } } /** - * Returs associative array of submitted fields for current item + * Returns associative array of submitted fields for current item * Could be used while creating/editing single item - * meaning on any edit form, except grid edit * * @param kEvent $event + * @return Array + * @access protected */ - function getSubmittedFields(&$event) + protected function getSubmittedFields(kEvent &$event) { - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - $field_values = $items_info ? array_shift($items_info) : Array(); + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + $field_values = $items_info ? array_shift($items_info) : Array (); + return $field_values; } @@ -388,31 +406,34 @@ * from Application variables and Session * * @param kEvent $event + * @return void + * @access protected */ - function clearSelectedIDs(&$event) + protected function clearSelectedIDs(kEvent &$event) { $prefix_special = $event->getPrefixSpecial(); $ids = implode(',', $this->getSelectedIDs($event, true)); $event->setEventParam('ids', $ids); $wid = $this->Application->GetTopmostWid($event->Prefix); - $session_name = rtrim($prefix_special.'_selected_ids_'.$wid, '_'); + $session_name = rtrim($prefix_special . '_selected_ids_' . $wid, '_'); $this->Application->RemoveVar($session_name); - $this->Application->SetVar($prefix_special.'_selected_ids', ''); + $this->Application->SetVar($prefix_special . '_selected_ids', ''); - $this->Application->SetVar($prefix_special.'_id', ''); // $event->getPrefixSpecial(true).'_id' too may be + $this->Application->SetVar($prefix_special . '_id', ''); // $event->getPrefixSpecial(true) . '_id' too may be } /** * Common builder part for Item & List * * @param kDBBase|kDBItem|kDBList $object * @param kEvent $event - * @access private + * @return void + * @access protected */ - function dbBuild(&$object, &$event) + protected function dbBuild(&$object, kEvent &$event) { // for permission checking inside item/list build events $event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true)); @@ -422,10 +443,10 @@ } else { $request_forms = $this->Application->GetVar('forms', Array ()); - $form_name = (string)getArrayValue( $request_forms, $object->getPrefixSpecial() ); + $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') || $this->Application->getUnitOption($event->Prefix, 'PopulateMlFields'), $form_name); $this->PrepareObject($object, $event); $parent_event = $event->getEventParam('parent_event'); @@ -437,24 +458,24 @@ // force live table if specified or is original item $live_table = $event->getEventParam('live_table') || $event->Special == 'original'; - if( $this->UseTempTables($event) && !$live_table ) - { + if ( $this->UseTempTables($event) && !$live_table ) { $object->SwitchToTemp(); } $this->Application->setEvent($event->getPrefixSpecial(), ''); $save_event = $this->UseTempTables($event) && $this->Application->GetTopmostPrefix($event->Prefix) == $event->Prefix ? 'OnSave' : 'OnUpdate'; - $this->Application->SetVar($event->getPrefixSpecial().'_SaveEvent',$save_event); + $this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', $save_event); } /** * Checks, that currently loaded item is allowed for viewing (non permission-based) * * @param kEvent $event * @return bool + * @access protected */ - function checkItemStatus(&$event) + protected function checkItemStatus(kEvent &$event) { $status_fields = $this->Application->getUnitOption($event->Prefix, 'StatusField'); if ( !$status_fields ) { @@ -481,13 +502,14 @@ * Shows not found template content * * @param kEvent $event - * + * @return void + * @access protected */ - function _errorNotFound(&$event) + protected function _errorNotFound(kEvent &$event) { - if ($event->getEventParam('raise_warnings') === 0) { + if ( $event->getEventParam('raise_warnings') === 0 ) { // when it's possible, that autoload fails do nothing - return ; + return; } if ( $this->Application->isDebugMode() ) { @@ -513,7 +535,7 @@ // in case if missing item is recalled first from event (not from template) $this->Application->InitParser(); - $this->Application->HTML = $this->Application->ParseBlock( Array ('name' => $error_template) ); + $this->Application->HTML = $this->Application->ParseBlock(Array ('name' => $error_template)); $this->Application->Done(); exit; } @@ -526,7 +548,7 @@ * @param kEvent $event * @access protected */ - function OnItemBuild(&$event) + protected function OnItemBuild(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -539,21 +561,21 @@ // 2. loads if allowed $auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad'); - $skip_autload = $event->getEventParam('skip_autoload'); + $skip_autoload = $event->getEventParam('skip_autoload'); - if ($auto_load && !$skip_autload) { + if ( $auto_load && !$skip_autoload ) { $perm_status = true; $user_id = $this->Application->InitDone ? $this->Application->RecallVar('user_id') : USER_ROOT; $event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true)); $status_checked = false; - if ($user_id == USER_ROOT || $this->CheckPermission($event)) { + if ( $user_id == USER_ROOT || $this->CheckPermission($event) ) { // don't autoload item, when user doesn't have view permission $this->LoadItem($event); $status_checked = true; $editing_mode = defined('EDITING_MODE') ? EDITING_MODE : false; - if ($user_id != USER_ROOT && !$this->Application->isAdmin && !($editing_mode || $this->checkItemStatus($event))) { + if ( $user_id != USER_ROOT && !$this->Application->isAdmin && !($editing_mode || $this->checkItemStatus($event)) ) { // non-root user AND on front-end AND (not editing mode || incorrect status) $perm_status = false; } @@ -593,19 +615,21 @@ $actions =& $this->Application->recallObject('kActions'); /* @var $actions Params */ - $actions->Set($event->getPrefixSpecial().'_GoTab', ''); - $actions->Set($event->getPrefixSpecial().'_GoId', ''); - $actions->Set('forms[' . $event->getPrefixSpecial() . ']', $object->getFormName()); + $actions->Set($event->getPrefixSpecial() . '_GoTab', ''); + $actions->Set($event->getPrefixSpecial() . '_GoId', ''); + $actions->Set('forms[' . $event->getPrefixSpecial() . ']', $object->getFormName()); } /** - * Build subtables array from configs + * Build sub-tables array from configs * * @param kEvent $event + * @return void + * @access protected */ - function OnTempHandlerBuild(&$event) + protected function OnTempHandlerBuild(kEvent &$event) { - $object =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $object =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); /* @var $object kTempTablesHandler */ $parent_event = $event->getEventParam('parent_event'); @@ -614,16 +638,17 @@ $object->setParentEvent($parent_event); } - $object->BuildTables( $event->Prefix, $this->getSelectedIDs($event) ); + $object->BuildTables($event->Prefix, $this->getSelectedIDs($event)); } /** * Checks, that object used in event should use temp tables * * @param kEvent $event * @return bool + * @access protected */ - function UseTempTables(&$event) + protected function UseTempTables(kEvent &$event) { $top_prefix = $this->Application->GetTopmostPrefix($event->Prefix); // passed parent, not always actual $special = ($top_prefix == $event->Prefix) ? $event->Special : $this->getMainSpecial($event); @@ -632,25 +657,13 @@ } /** - * Returns table prefix from event (temp or live) - * - * @param kEvent $event - * @return string - * @todo Needed? Should be refactored (by Alex) - */ - function TablePrefix(&$event) - { - return $this->UseTempTables($event) ? $this->Application->GetTempTablePrefix('prefix:'.$event->Prefix).TABLE_PREFIX : TABLE_PREFIX; - } - - /** * Load item if id is available * * @param kEvent $event * @return void * @access protected */ - protected function LoadItem(&$event) + protected function LoadItem(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -681,7 +694,7 @@ * @param kEvent $event * @access protected */ - function OnListBuild(&$event) + protected function OnListBuild(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBList */ @@ -710,7 +723,7 @@ $object->reset(); if ( $event->getEventParam('skip_parent_filter') === false ) { - $object->linkToParent( $this->getMainSpecial($event) ); + $object->linkToParent($this->getMainSpecial($event)); } $this->AddFilters($event); @@ -726,19 +739,20 @@ } /** - * Get's special of main item for linking with subitem + * Returns special of main item for linking with sub-item * * @param kEvent $event * @return string + * @access protected */ - function getMainSpecial(&$event) + protected function getMainSpecial(kEvent &$event) { $main_special = $event->getEventParam('main_special'); - if ($main_special === false) { + if ( $main_special === false ) { // main item's special not passed - if (substr($event->Special, -5) == '-item') { + if ( substr($event->Special, -5) == '-item' ) { // temp handler added "-item" to given special -> process that here return substr($event->Special, 0, -5); } @@ -758,13 +772,13 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { } /** - * Set's new perpage for grid + * Set's new per-page for grid * * @param kEvent $event */ @@ -2756,7 +2770,7 @@ * @return void * @access protected */ - protected function prepareObject(&$object, &$event) + protected function prepareObject(&$object, kEvent &$event) { if ( $event->Special == 'export' || $event->Special == 'import' ) { $export_helper =& $this->Application->recallObject('CatItemExportHelper');