Index: branches/RC/core/units/files/file_eh.php =================================================================== diff -u -r9581 -r9598 --- branches/RC/core/units/files/file_eh.php (.../file_eh.php) (revision 9581) +++ branches/RC/core/units/files/file_eh.php (.../file_eh.php) (revision 9598) @@ -23,17 +23,6 @@ */ function OnBeforeItemCreate(&$event) { - parent::OnBeforeItemCreate($event); - - $object =& $event->getObject(); - - $this->resetPrimary($object); - - if (!$this->primaryFileFound($object)) { - $object->SetDBField('IsPrimary', 1); - $object->SetDBField('Status', STATUS_ACTIVE); - } - $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); } @@ -46,99 +35,11 @@ { $object =& $event->getObject(); - $this->resetPrimary($object); - if (!$object->GetDBField('FileName')) { $object->SetDBField('FileName', basename($object->GetDBField('FilePath'))); } } - /** - * Checks for primary file along all files with same main item - * - * @param kDBItem $object - * @return int - */ - function primaryFileFound(&$object) - { - $sql = 'SELECT '.$object->IDField.' - FROM '.$object->TableName.' - WHERE (IsPrimary = 1) AND ('.$this->getParentClause($object).')'; - return $this->Conn->GetOne($sql); - } - - /** - * Resets primary mark from all item files - * - * @param kDBItem $object - */ - function resetPrimary(&$object) - { - if (!$object->GetDBField('IsPrimary')) { - return ; - } - - $sql = 'UPDATE '.$object->TableName.' - SET IsPrimary = 0 - WHERE '.$this->getParentClause($object); - $this->Conn->Query($sql); - - $object->SetDBField('Status', STATUS_ACTIVE); - } - - /** - * Makes selected file primary - * - * @param kEvent $event - */ - function OnSetPrimary(&$event) - { - $ids = $this->StoreSelectedIDs($event); - if (!$ids) { - return ; - } - - $object =& $event->getObject( Array('skip_autoload' => true) ); - $object->Load( array_shift($ids) ); - - $object->SetDBField('IsPrimary', 1); - $object->Update(); - - $this->clearSelectedIDs($event); - } - - /** - * Don't allow to delete other user's messages - * - * @param kEvent $event - */ - function customProcessing(&$event, $type) - { - parent::customProcessing($event, $type); - if ($event->Name == 'OnMassDelete' && $type == 'before') { - $ids = $event->getEventParam('ids'); - if ($ids) { - $object =& $event->getObject(); - /* @var $object kDBItem */ - - $primary_file_id = $this->primaryFileFound($object); - if ($primary_file_id && ($primary_index = array_search($primary_file_id, $ids))) { - $sql = 'SELECT COUNT(*) - FROM '.$object->TableName.' - WHERE (IsPrimary = 0) AND ('.$this->getParentClause($object).')'; - $non_primary_found = $this->Conn->Query($sql); - - if ($non_primary_found) { - // non-primary files found for same main item -> don't delete primary file until all non-primary files are deleted - unset($ids[$primary_index]); - } - } - - $event->setEventParam('ids', $ids); - } - } - } - function SetCustomQuery(&$event) { parent::SetCustomQuery($event); @@ -149,18 +50,6 @@ $object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE); } } - - /** - * Returns sql clause, that links file to it's parent item - * - * @param kDBItem $object - * @return string - */ - function getParentClause(&$object) - { - $parent_info = $object->getLinkedInfo($object->Special); - return $parent_info['ForeignKey'].' = '.$parent_info['ParentId']; - } } ?> \ No newline at end of file