getIsGlobal(); } public function isDir() { return $this->getIsDir(); } public function hasPermissionRead(Zakaznik $zakaznik, $is_agentura = false) { if($is_agentura) { return $this->getZakaznikId() == $zakaznik->getId() && $this->getAgenturaRead(); } return $this->getZakaznikId() == $zakaznik->getId(); } public function hasPermissionWrite(Zakaznik $zakaznik, $is_agentura = false) { if($is_agentura) { return $this->getZakaznikId() == $zakaznik->getId() && $this->getAgenturaWrite(); } return $this->getZakaznikId() == $zakaznik->getId(); } public function getNiceFilename() { if($this->isDir()) { return $this->getSlug(); } return $this->getSlug().'.'.$this->getExtension(); } public function getExtension() { if(!$this->isDir()) { $info = pathinfo($this->getPath()); return $info['extension']; } return null; } public function getPath() { return sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.'documents'.DIRECTORY_SEPARATOR.$this->getFilename(); } public function getContentType() { return saCommon::getMimeFromFilename($this->getPath()); } public function hasChildren($is_agentura = false) { $query = Doctrine::getTable('Document')->createQuery() ->addWhere('parent_id = ?', $this->getId()); if($is_agentura) { $query->addWhere('agentura_read = ?', true); } return $query->count() > 0; } public function getChildren($is_agentura = false) { $query = Doctrine::getTable('Document')->createQuery() ->addWhere('parent_id = ?', $this->getId()); if($is_agentura) { $query->addWhere('agentura_read = ?', true); } return $query->execute(); } public function hasParent() { return !is_null($this->getParentId()); } public function getParent() { return Doctrine::getTable('Document')->findOneById($this->getParentId()); } public function preDelete($event) { foreach($this->getChildren() as $child) { $child->delete(); } if(!$this->isDir()) { unlink($this->getPath()); } parent::preDelete($event); } public function getDirChoices($prefix = '', $is_agentura = false) { $choices = array(); foreach($this->getChildren($is_agentura) as $child) { if($child->isDir()) { $choices[$child->getId()] = $prefix.' '.$child->getName(); $choices = $choices + $child->getDirChoices($prefix.'-', $is_agentura); } } return $choices; } public function postUpdate($event) { DocumentEventTable::createEvent($this, DocumentEvent::ACTION_UPDATE); parent::postUpdate($event); } public function postInsert($event) { DocumentEventTable::createEvent($this, DocumentEvent::ACTION_CREATE); parent::postInsert($event); } public function postDelete($event) { DocumentEventTable::createEvent($this, DocumentEvent::ACTION_DELETE); parent::postDelete($event); } public function getVirtualPath() { if($this->hasParent()) { $path = $this->getParent()->getVirtualPath().'/'; } else { $path = '/'; } $path .= $this->getNiceFilename(); return $path; } }