Index: branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5869) @@ -16,12 +16,32 @@ */ var $useFilenames = true; + /** + * Use pending editing abilities during item (delegated by permissions) + * + * @var bool + */ + var $usePendingEditing = false; + function Clear() { parent::Clear(); $this->CategoryPath = Array(); } + /** + * Set's prefix and special + * + * @param string $prefix + * @param string $special + * @access public + */ + function Init($prefix, $special, $event_params = null) + { + parent::Init($prefix, $special, $event_params); + $this->usePendingEditing = $this->Application->getUnitOption($this->Prefix, 'UsePendingEditing'); + } + function Create($force_id=false, $system_create=false) { if (!$this->Validate()) return false; @@ -380,6 +400,59 @@ } return $image_data; } + + function ChangeStatus($new_status) + { + $status_field = array_shift( $this->Application->getUnitOption($this->Prefix,'StatusField') ); + $this->SetDBField($status_field, $new_status); + return $this->Update(); + } + + /** + * Approves changes made to category item + * + * @return bool + */ + function ApproveChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_ACTIVE); + } + + $this->raiseEvent('OnBeforeDeleteOriginal', null, Array('original_id' => $original_id)); + + // delete original item, because changes made in pending copy (this item) got to be approved in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($original_id)); + + $this->SetDBField('OrgId', 0); + return $this->ChangeStatus(STATUS_ACTIVE); + } + + /** + * Decline changes made to category item + * + * @return bool + */ + function DeclineChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_DISABLED); + } + + // delete this item, because changes made in pending copy (this item) will be declined in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($this->GetID())); + + // original item is not changed here, because it is already enabled (thrus pending copy is visible to item's owner or admin with permission) + return true; + } } ?> \ No newline at end of file