Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r8409 -r8413 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8409) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8413) @@ -20,7 +20,7 @@ 'OnCancelAction' => Array('self' => true), ); - + $this->permMapping = array_merge($this->permMapping, $permissions); } @@ -46,7 +46,7 @@ $object->setID($id); } } - + /** * Checks permissions of user * @@ -89,7 +89,7 @@ if (strlen($selected_ids)) { $perm_helper =& $this->Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ - + $items = $perm_helper->GetCategoryItemData($event->Prefix, $selected_ids); $check_method = ($event->Name == 'OnMassDelete') ? 'DeleteCheckPermission' : 'ModifyCheckPermission'; foreach ($items as $item_id => $item_data) { @@ -187,7 +187,7 @@ $type_clauses['my_items']['include'] = '%1$s.CreatedById = '.$user_id; $type_clauses['my_items']['except'] = '%1$s.CreatedById <> '.$user_id; $type_clauses['my_items']['having_filter'] = false; - + $type_clauses['pick']['include'] = '%1$s.EditorsPick = 1 AND '.TABLE_PREFIX.'CategoryItems.PrimaryCat = 1'; $type_clauses['pick']['except'] = '%1$s.EditorsPick! = 1 AND '.TABLE_PREFIX.'CategoryItems.PrimaryCat = 1'; $type_clauses['pick']['having_filter'] = false; @@ -375,26 +375,10 @@ $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); - if ( !$this->Application->IsAdmin() ) - { - $object->addFilter('status_filter', '%1$s.Status = 1'); - if ($this->Application->getUnitOption($event->Prefix, 'UsePendingEditing')) { - // if category item uses pending editing abilities, then in no cases show pending copies on front - $object->addFilter('original_filter', '%1$s.OrgId = 0 OR %1$s.OrgId IS NULL'); - } - } - else { - if ($this->Application->getUnitOption($event->Prefix, 'UsePendingEditing')) { - $pending_ids = $this->Conn->GetCol( - 'SELECT OrgId FROM '.$object->TableName.' - WHERE Status = -2 AND OrgId IS NOT NULL'); - if ($pending_ids) { - $object->addFilter('no_original_filter', '%1$s.'.$object->IDField.' NOT IN ('.implode(',', $pending_ids).')'); - } - } - } $types = $event->getEventParam('types'); + $this->applyItemStatusFilter($object, $types); + $except_types = $event->getEventParam('except'); $type_clauses = $this->getTypeClauses($event); @@ -482,6 +466,65 @@ } /** + * Adds filter that filters out items with non-required statuses + * + * @param kDBList $object + * @param string $types + */ + function applyItemStatusFilter(&$object, $types) + { + // Link1 (before modifications) [Status = 1, OrgId = NULL], Link2 (after modifications) [Status = -2, OrgId = Link1_ID] + $pending_editing = $this->Application->getUnitOption($object->Prefix, 'UsePendingEditing'); + + if ( !$this->Application->IsAdmin() ) { + $types = explode(',', $types); + if (in_array('my_items', $types)) { + $allow_statuses = Array (STATUS_ACTIVE, STATUS_PENDING, STATUS_PENDING_EDITING); + $object->addFilter('status_filter', '%1$s.Status IN ('.implode(',', $allow_statuses).')'); + + if ($pending_editing) { + $user_id = $this->Application->RecallVar('user_id'); + $this->applyPendingEditingFilter($object, $user_id); + } + } + else { + $object->addFilter('status_filter', '%1$s.Status = 1'); + if ($pending_editing) { + // if category item uses pending editing abilities, then in no cases show pending copies on front + $object->addFilter('original_filter', '%1$s.OrgId = 0 OR %1$s.OrgId IS NULL'); + } + } + } + else { + if ($pending_editing) { + $this->applyPendingEditingFilter($object); + } + } + } + + /** + * Adds filter, that removes live items if they have pending editing copies + * + * @param kDBList $object + * @param int $user_id + */ + function applyPendingEditingFilter(&$object, $user_id = null) + { + $sql = 'SELECT OrgId + FROM '.$object->TableName.' + WHERE Status = '.STATUS_PENDING_EDITING.' AND OrgId IS NOT NULL'; + + if (isset($user_id)) { + $sql .= ' AND CreatedById = '.$user_id; + } + + $pending_ids = $this->Conn->GetCol($sql); + if ($pending_ids) { + $object->addFilter('no_original_filter', '%1$s.'.$object->IDField.' NOT IN ('.implode(',', $pending_ids).')'); + } + } + + /** * Adds calculates fields for item statuses * * @param kCatDBItem $object @@ -1740,15 +1783,15 @@ if ($this->Application->IsAdmin()) { return true; } - + $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); if ($use_pending_editing) { $object =& $event->getObject(); /* @var $object kDBItem */ - + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ - + $primary_category = $object->GetDBField('CategoryId') > 0 ? $object->GetDBField('CategoryId') : $this->Application->GetVar('m_cat_id'); $item_status = $perm_helper->AddCheckPermission($primary_category, $event->Prefix); if ($item_status == STATUS_DISABLED) { @@ -1760,7 +1803,7 @@ } } } - + /** * Creates category item & redirects to confirmation template (front-end only) * @@ -1771,7 +1814,7 @@ parent::OnCreate($event); $this->SetFrontRedirectTemplate($event, 'suggest'); } - + /** * Creates category item & redirects to confirmation template (front-end only) * @@ -1782,7 +1825,7 @@ parent::OnUpdate($event); $this->SetFrontRedirectTemplate($event, 'modify'); } - + /** * Sets next template to one required for front-end after adding/modifying item * @@ -1794,14 +1837,14 @@ if ($this->Application->IsAdmin() || $event->status != erSUCCESS) { return ; } - + $event->SetRedirectParam('opener', 's'); - + $object =& $event->getObject(); $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'confirm_template' : 'pending_confirm_template'; $event->redirect = $this->Application->GetVar($template_key.'_'.$next_template); } - + /** * Apply same processing to each item beeing selected in grid * @@ -1843,7 +1886,7 @@ } } } - + /** * Deletes items & preserves clean env * @@ -1852,13 +1895,13 @@ function OnMassDelete(&$event) { parent::OnMassDelete($event); - + if ($event->status == erSUCCESS && !$this->Application->IsAdmin()) { $event->SetRedirectParam('pass', 'm'); $event->SetRedirectParam('m_cat_id', 0); } } - + /** * Checks, that currently loaded item is allowed for viewing (non permission-based) * @@ -1871,14 +1914,14 @@ if (!$object->isLoaded()) { return true; } - + $status = $object->GetDBField('Status'); - + $user_id = $this->Application->RecallVar('user_id'); if (($status == -2 || $status == STATUS_PENDING) && ($object->GetDBField('CreatedById') == $user_id)) { return true; } - + return $status == STATUS_ACTIVE; } }