Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r14092 -r14095 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14092) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14095) @@ -1,6 +1,6 @@ getPassedID($event); if ($object->Load($id)) { $actions =& $this->Application->recallObject('kActions'); - $actions->Set($event->Prefix_Special.'_id', $object->GetID() ); + $actions->Set($event->getPrefixSpecial().'_id', $object->GetID() ); $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); if ($use_pending_editing && $event->Special != 'original') { @@ -254,7 +254,7 @@ function OnPaste(&$event) { if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) || !$this->_checkPastePermission($event)) { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; return; } @@ -292,11 +292,11 @@ function OnMassDelete(&$event) { if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; return; } - $event->status=erSUCCESS; + $event->status=kEvent::erSUCCESS; $ids = $this->StoreSelectedIDs($event); @@ -630,87 +630,10 @@ $except_types = $event->getEventParam('except'); $type_clauses = $this->getTypeClauses($event); - // convert prepared type clauses into list filters - $includes_or_filter =& $this->Application->makeClass('kMultipleFilter'); - $includes_or_filter->setType(FLT_TYPE_OR); + $search_helper =& $this->Application->recallObject('SearchHelper'); + /* @var $search_helper kSearchHelper */ - $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter'); - $excepts_and_filter->setType(FLT_TYPE_AND); - - $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter'); - $includes_or_filter_h->setType(FLT_TYPE_OR); - - $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter'); - $excepts_and_filter_h->setType(FLT_TYPE_AND); - - if ($types) { - $types_array = explode(',', $types); - for ($i = 0; $i < sizeof($types_array); $i++) { - $type = trim($types_array[$i]); - if (isset($type_clauses[$type])) { - if ($type_clauses[$type]['having_filter']) { - $includes_or_filter_h->removeFilter('filter_'.$type); - $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']); - }else { - $includes_or_filter->removeFilter('filter_'.$type); - $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']); - } - } - } - } - - if ($except_types) { - $except_types_array = explode(',', $except_types); - for ($i = 0; $i < sizeof($except_types_array); $i++) { - $type = trim($except_types_array[$i]); - if (isset($type_clauses[$type])) { - if ($type_clauses[$type]['having_filter']) { - $excepts_and_filter_h->removeFilter('filter_'.$type); - $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']); - }else { - $excepts_and_filter->removeFilter('filter_'.$type); - $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']); - } - } - } - } - - /*if (!$this->Application->isAdminUser) { - $object->addFilter('expire_filter', '%1$s.Expire IS NULL OR %1$s.Expire > UNIX_TIMESTAMP()'); - }*/ - - /*$list_type = $event->getEventParam('ListType'); - switch($list_type) - { - case 'favorites': - $fav_table = $this->Application->getUnitOption('fav','TableName'); - $user_id =& $this->Application->RecallVar('user_id'); - - $sql = 'SELECT DISTINCT f.ResourceId - FROM '.$fav_table.' f - LEFT JOIN '.$object->TableName.' p ON p.ResourceId = f.ResourceId - WHERE f.PortalUserId = '.$user_id; - $ids = $this->Conn->GetCol($sql); - if(!$ids) $ids = Array(-1); - $object->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.PrimaryCat = 1'); - $object->addFilter('favorites_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')'); - break; - case 'search': - $search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - $sql = ' SELECT DISTINCT ResourceId - FROM '.$search_results_table.' - WHERE ItemType=11'; - $ids = $this->Conn->GetCol($sql); - if(!$ids) $ids = Array(-1); - $object->addFilter('search_filter', '%1$s.`ResourceId` IN ('.implode(',',$ids).')'); - break; - } */ - - $object->addFilter('includes_filter', $includes_or_filter); - $object->addFilter('excepts_filter', $excepts_and_filter); - - $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER); - $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER); + $search_helper->SetComplexFilter($event, $type_clauses, $types, $except_types); } /** @@ -935,12 +858,12 @@ // substituiting pending status value for pending editing if ($object->HasField('OrgId') && $object->GetDBField('OrgId') > 0 && $object->GetDBField('Status') == -2) { - $options = $object->Fields['Status']['options']; + $options = $object->GetFieldOption('Status', 'options'); foreach ($options as $key => $val) { if ($key == 2) $key = -2; $new_options[$key] = $val; } - $object->Fields['Status']['options'] = $new_options; + $object->SetFieldOption('Status', 'options', $new_options); } // linking existing images for item with virtual fields @@ -1073,7 +996,7 @@ $event->redirect = false; $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - $keywords = unhtmlentities( trim($this->Application->GetVar('keywords')) ); + $keywords = kUtil::unhtmlentities( trim($this->Application->GetVar('keywords')) ); $query_object =& $this->Application->recallObject('HTTPQuery'); $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; @@ -1284,10 +1207,10 @@ $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_'.$conf_postfix) / 100; $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_'.$conf_postfix) / 100; $relevance_clause = '('.implode(' + ', $revelance_parts).') / '.$weight_sum.' * '.$rel_keywords; - if ($rel_pop && isset($object->Fields['Hits'])) { + if ($rel_pop && $object->isField('Hits')) { $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; } - if ($rel_rating && isset($object->Fields['CachedRating'])) { + if ($rel_rating && $object->isField('CachedRating')) { $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; } @@ -1591,14 +1514,14 @@ $condition = ''; switch ($record['FieldType']) { case 'select': - $keywords[$field] = unhtmlentities( $keywords[$field] ); + $keywords[$field] = kUtil::unhtmlentities( $keywords[$field] ); if ($keywords[$field]) { $condition = sprintf($condition_patterns['is'], $field_name, $this->Conn->qstr( $keywords[$field] )); } break; case 'multiselect': - $keywords[$field] = unhtmlentities( $keywords[$field] ); + $keywords[$field] = kUtil::unhtmlentities( $keywords[$field] ); if ($keywords[$field]) { $condition = Array (); $values = explode('|', substr($keywords[$field], 1, -1)); @@ -1610,7 +1533,7 @@ break; case 'text': - $keywords[$field] = unhtmlentities( $keywords[$field] ); + $keywords[$field] = kUtil::unhtmlentities( $keywords[$field] ); if (mb_strlen($keywords[$field]) >= $this->Application->ConfigValue('Search_MinKeyword_Length')) { $highlight_keywords[] = $keywords[$field]; @@ -1767,7 +1690,7 @@ $object->SetPerPage( $this->getPerPage($event) ); // main lists on Front-End have special get parameter for page - $page = $object->mainList ? $this->Application->GetVar('page') : false; + $page = $object->isMainList() ? $this->Application->GetVar('page') : false; if (!$page) { // page is given in "env" variable for given prefix @@ -1780,7 +1703,7 @@ $page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Page'); } - if (!$object->mainList) { + if (!$object->isMainList()) { // main lists doesn't use session for page storing $this->Application->StoreVarDefault($event->getPrefixSpecial() . '_Page', 1, true); // true for optional @@ -1894,7 +1817,7 @@ $export_options = $export_object->loadOptions($event); echo $export_options['start_from'] * 100 / $export_options['total_records']; - $event->status = erSTOP; + $event->status = kEvent::erSTOP; } /** @@ -2065,7 +1988,7 @@ function OnCancelAction(&$event) { - $event->redirect_params = Array('pass' => 'all,'.$event->GetPrefixSpecial()); + $event->setRedirectParams(Array('pass' => 'all,'.$event->GetPrefixSpecial()), true); $event->redirect = $this->Application->GetVar('cancel_template'); } @@ -2107,7 +2030,7 @@ { parent::OnPreSave($event); $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($event->status == erSUCCESS && $use_pending_editing) { + if ($event->status == kEvent::erSUCCESS && $use_pending_editing) { // decision: clone or not clone $object =& $event->getObject(); @@ -2170,7 +2093,7 @@ { parent::OnPreCreate($event); - if ($event->status == erSUCCESS) { + if ($event->status == kEvent::erSUCCESS) { $object =& $event->getObject(); $owner_field = $this->getOwnerField($event->Prefix); @@ -2253,7 +2176,7 @@ $item_status = $perm_helper->AddCheckPermission($primary_category, $event->Prefix); if ($item_status == STATUS_DISABLED) { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; } else { $object->SetDBField('Status', $item_status); @@ -2298,7 +2221,7 @@ */ function processAdditionalCategories(&$object, $mode) { - if (!array_key_exists('MoreCategories', $object->VirtualFields)) { + if ( !$object->isVirtualField('MoreCategories') ) { // given category item doesn't require such type of processing return ; } @@ -2407,10 +2330,10 @@ } if ($object->Update()) { - $event->status = erSUCCESS; + $event->status = kEvent::erSUCCESS; } else { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; $event->redirect = false; break; } @@ -2428,7 +2351,7 @@ */ function SetFrontRedirectTemplate(&$event, $template_key) { - if ($this->Application->isAdminUser || $event->status != erSUCCESS) { + if ($this->Application->isAdminUser || $event->status != kEvent::erSUCCESS) { return ; } @@ -2474,7 +2397,7 @@ } if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; return; } @@ -2496,7 +2419,7 @@ } if (!$ret) { - $event->status = erFAIL; + $event->status = kEvent::erFAIL; $event->redirect = false; break; } @@ -2515,7 +2438,7 @@ { parent::OnDelete($event); - if ($event->status == erSUCCESS && !$this->Application->isAdmin) { + if ($event->status == kEvent::erSUCCESS && !$this->Application->isAdmin) { $event->SetRedirectParam('pass', 'm'); $event->SetRedirectParam('m_cat_id', 0); } @@ -2657,7 +2580,7 @@ $object =& $event->getObject(); /* @var $object kDBItem */ - $event->status = erSTOP; + $event->status = kEvent::erSTOP; $field = $this->Application->GetVar('field'); if (!preg_match('/^File([\d]+)/', $field)) { @@ -2678,7 +2601,7 @@ */ function OnMakeVote(&$event) { - $event->status = erSTOP; + $event->status = kEvent::erSTOP; if ($this->Application->GetVar('ajax') != 'yes') { // this is supposed to call from AJAX only