Index: branches/5.2.x/core/units/filters/item_filter_eh.php =================================================================== diff -u -N -r15145 -r15165 --- branches/5.2.x/core/units/filters/item_filter_eh.php (.../item_filter_eh.php) (revision 15145) +++ branches/5.2.x/core/units/filters/item_filter_eh.php (.../item_filter_eh.php) (revision 15165) @@ -1,159 +1,159 @@ - Array ('self' => true), - ); - - $this->permMapping = array_merge($this->permMapping, $permissions); - } - - /** - * Apply any custom changes to list's sql query - * - * @param kEvent $event - * @return void - * @access protected - * @see kDBEventHandler::OnListBuild() - */ - protected function SetCustomQuery(kEvent $event) - { - parent::SetCustomQuery($event); - - if ( !$this->Application->isAdmin ) { - $object = $event->getObject(); - /* @var $object kDBList */ - - $prefix_info = $this->Application->processPrefix($event->getEventParam('prefix')); - - $object->addFilter('prefix_filter', '%1$s.ItemPrefix = ' . $this->Conn->qstr($prefix_info['prefix'])); - $object->addFilter('status_filter', '%1$s.Enabled = 1'); - - if ( $event->Special == 'used' ) { - $filters = array_keys($this->Application->GetVar('filters', Array ())); - - if ( $filters ) { - $filters = $this->Conn->qstrArray($filters); - $object->addFilter('field_filter', '%1$s.FilterField IN (' . implode(',', $filters) . ')'); - } - else { - $object->addFilter('field_filter', 'FALSE'); - } - } - - $exclude_filters = $this->Application->GetVar('exclude_filters'); - - if ( $exclude_filters ) { - $exclude_filters = $this->Conn->qstrArray(explode(',', $exclude_filters)); - $object->addFilter('field_filter', '%1$s.FilterField NOT IN (' . implode(',', $exclude_filters) . ')'); - } - - if ( $event->getEventParam('per_page') === false ) { - $event->setEventParam('per_page', -1); - } - } - } - - /** - * Validates filter settings - * - * @param kEvent $event - * @return void - * @access protected - */ - protected function OnBeforeItemValidate(kEvent $event) - { - parent::OnBeforeItemValidate($event); - - $object = $event->getObject(); - /* @var $object kDBItem */ - - $prefix = $object->GetDBField('ItemPrefix'); - - if ( $prefix ) { - if ( !$this->Application->prefixRegistred($prefix) ) { - $object->SetError('ItemPrefix', 'not_registered'); - } - - $field = $object->GetDBField('FilterField'); - - if ( $field ) { - $fields = $this->Application->getUnitOption($prefix, 'Fields'); - $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields'); - - if ( !isset($fields[$field]) && !isset($virtual_fields[$field]) ) { - $object->SetError('FilterField', 'non_existing', null, Array ($prefix)); - } - } - } - - $object->setRequired('RangeCount', $object->GetDBField('FilterType') == 'range'); - } - - /** - * Load item if id is available - * - * @param kEvent $event - * @return void - * @access protected - */ - protected function LoadItem(kEvent $event) - { - static $cache = null; - - if ( $this->Application->isAdmin ) { - parent::LoadItem($event); - - return; - } - - $object = $event->getObject(); - /* @var $object kDBItem */ - - if ( !isset($cache) ) { - $cache = $this->Conn->Query($object->GetSelectSQL(), 'FilterKey'); - } - - $filter_key = $event->getEventParam('prefix') . '_' . $event->getEventParam('field'); - - if ( isset($cache[$filter_key]) ) { - $object->LoadFromHash($cache[$filter_key]); - } - - if ( $object->isLoaded() ) { - $actions = $this->Application->recallObject('kActions'); - /* @var $actions Params */ - - $actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); - } - else { - $object->setID(false); - } - } -} + Array ('self' => true), + ); + + $this->permMapping = array_merge($this->permMapping, $permissions); + } + + /** + * Apply any custom changes to list's sql query + * + * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() + */ + protected function SetCustomQuery(kEvent $event) + { + parent::SetCustomQuery($event); + + if ( !$this->Application->isAdmin ) { + $object = $event->getObject(); + /* @var $object kDBList */ + + $prefix_info = $this->Application->processPrefix($event->getEventParam('prefix')); + + $object->addFilter('prefix_filter', '%1$s.ItemPrefix = ' . $this->Conn->qstr($prefix_info['prefix'])); + $object->addFilter('status_filter', '%1$s.Enabled = 1'); + + if ( $event->Special == 'used' ) { + $filters = array_keys($this->Application->GetVar('filters', Array ())); + + if ( $filters ) { + $filters = $this->Conn->qstrArray($filters); + $object->addFilter('field_filter', '%1$s.FilterField IN (' . implode(',', $filters) . ')'); + } + else { + $object->addFilter('field_filter', 'FALSE'); + } + } + + $exclude_filters = $this->Application->GetVar('exclude_filters'); + + if ( $exclude_filters ) { + $exclude_filters = $this->Conn->qstrArray(explode(',', $exclude_filters)); + $object->addFilter('field_filter', '%1$s.FilterField NOT IN (' . implode(',', $exclude_filters) . ')'); + } + + if ( $event->getEventParam('per_page') === false ) { + $event->setEventParam('per_page', -1); + } + } + } + + /** + * Validates filter settings + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemValidate(kEvent $event) + { + parent::OnBeforeItemValidate($event); + + $object = $event->getObject(); + /* @var $object kDBItem */ + + $prefix = $object->GetDBField('ItemPrefix'); + + if ( $prefix ) { + if ( !$this->Application->prefixRegistred($prefix) ) { + $object->SetError('ItemPrefix', 'not_registered'); + } + + $field = $object->GetDBField('FilterField'); + + if ( $field ) { + $fields = $this->Application->getUnitOption($prefix, 'Fields'); + $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields'); + + if ( !isset($fields[$field]) && !isset($virtual_fields[$field]) ) { + $object->SetError('FilterField', 'non_existing', null, Array ($prefix)); + } + } + } + + $object->setRequired('RangeCount', $object->GetDBField('FilterType') == 'range'); + } + + /** + * Load item if id is available + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function LoadItem(kEvent $event) + { + static $cache = null; + + if ( $this->Application->isAdmin ) { + parent::LoadItem($event); + + return; + } + + $object = $event->getObject(); + /* @var $object kDBItem */ + + if ( !isset($cache) ) { + $cache = $this->Conn->Query($object->GetSelectSQL(), 'FilterKey'); + } + + $filter_key = $event->getEventParam('prefix') . '_' . $event->getEventParam('field'); + + if ( isset($cache[$filter_key]) ) { + $object->LoadFromHash($cache[$filter_key]); + } + + if ( $object->isLoaded() ) { + $actions = $this->Application->recallObject('kActions'); + /* @var $actions Params */ + + $actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); + } + else { + $object->setID(false); + } + } +}