getFilename(); if($withHash) { $src .= '?'.md5_file($this->getPath($type)); } return $src; } public function getPath($type = self::TYPE_BIG) { return self::getUploadPath().DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR.$this->getFilename(); } public function getRealWidth($type = self::TYPE_BIG) { return imagesx(imagecreatefromjpeg($this->getPath($type))); } public function getRealHeight($type = self::TYPE_BIG) { return imagesy(imagecreatefromjpeg($this->getPath($type))); } public function delete(Doctrine_Connection $conn = null) { return parent::delete($conn); } public static function getUploadPath() { return sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.self::DIR_NAME; } public static function getWidth($type = self::TYPE_BIG) { switch($type) { case self::TYPE_BIG: return 600; case self::TYPE_MIDDLE: return 130; case self::TYPE_SMALL: return 60; } } public static function getHeight($type = self::TYPE_BIG) { switch($type) { case self::TYPE_BIG: return 400; case self::TYPE_MIDDLE: return 100; case self::TYPE_SMALL: return 40; } } public static function getAspectRatio() { return self::getWidth() / self::getHeight(); } public static function getMimetype() { return 'image/jpeg'; } public function existsFiles() { if(sfContext::getInstance()->getConfiguration()->isDebug()) { return true; } return (file_exists($this->getPath(self::TYPE_BIG)) && file_exists($this->getPath(self::TYPE_MIDDLE)) && file_exists($this->getPath(self::TYPE_SMALL)) === true); } public function getPublicDataArray() { sfLoader::loadHelpers('Asset'); $result = array(); $result['id'] = $this->getId(); $result['text'] = $this->getText(); $result['src'] = image_path($this->getSrc(self::TYPE_BIG), true); return $result; } protected function getSrealityData() { $file2import = @file_get_contents($this->getPath(self::TYPE_BIG)); $result = array( 'main' => new XML_RPC_Value((int) $this->getIsMain(), 'int'), 'data' => new XML_RPC_Value($file2import, 'base64') ); return $result; } public function importToSreality($advert_id) { if(strlen($this->getSrealityId())) { return; } if(strlen($advert_id)) { $sreality = new saSreality(); $this->setSrealityId($sreality->addPhoto((int) $advert_id, $this->getSrealityData())); } } public function deleteToSreality() { if(strlen($this->getSrealityId())) { $sreality = new saSreality(); $sreality->delPhoto((int) $this->getSrealityId()); } } public function preInsert($event) { if(!$this->getEstate()->getMainImage()) { $this->setIsMain(true); } try { $this->importToSreality($this->getEstate()->getSrealityId()); } catch (Exception $exc) { sfContext::getInstance()->getUser()->addMessage($exc->getMessage()); } parent::preInsert($event); } public function preDelete($event) { if($this->getIsMain()) { $new_main = Doctrine::getTable('Image')->createQuery() ->addWhere('estate_id = ?', $this->getEstateId()) ->addWhere('is_main = ?', false) ->fetchOne(); if($new_main) { $new_main->setIsMain(true); $new_main->save(); } } try { $this->deleteToSreality(); } catch (Exception $exc) { sfContext::getInstance()->getUser()->addMessage($exc->getMessage()); } parent::preDelete($event); } public function postDelete($event) { if($this->getEstate()->getSynchReals()) { try { $this->getEstate()->importToReals(); } catch (Exception $exc) { sfContext::getInstance()->getUser()->addMessage($exc->getMessage()); } } parent::postDelete($event); } public function postInsert($event) { if($this->getEstate()->getSynchReals()) { try { $this->getEstate()->importToReals(); } catch (Exception $exc) { sfContext::getInstance()->getUser()->addMessage($exc->getMessage()); } } parent::postInsert($event); } }