public function getAssetObject() { if (!$this->_assetObject) { $this->_assetObject = sfSympalAssetToolkit::createAssetObject($this->path . '/' . $this->name); } return $this->_assetObject; }
public static function getIconsPath() { if (!self::$iconsPath) { self::$iconsPath = sfConfig::get('sf_web_dir') . self::getIconsDir(); } return self::$iconsPath; }
public function synchronizeDirectory($dir) { $files = sfFinder::type('file')->maxdepth(0)->relative()->in($dir); $path = str_replace($this->_path, null, $dir); $exists = Doctrine_Core::getTable('sfSympalAsset')->findByPath($path); $keys = array(); foreach ($exists as $asset) { $keys[$asset->getName()] = $asset; } foreach ($files as $file) { if (!isset($keys[$file])) { $assetObject = sfSympalAssetToolkit::createAssetObject($path . '/' . $file); $doctrineAsset = new sfSympalAsset(); $doctrineAsset->setAssetObject($assetObject); $doctrineAsset->save(); } } // Remove assets that don't exist anymore on disk foreach ($keys as $name => $asset) { if (!$asset->fileExists()) { $asset->delete(); } } }
public function executeEdit_asset(sfWebRequest $request) { $this->asset = $this->getRoute()->getObject(); if ($request->isMethod('post')) { $this->form = new sfSympalAssetEditForm(); $this->form->setAsset($this->asset); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $postFile = $this->form->getValue('file'); if ($postFile) { $fileName = $postFile->getOriginalName(); $name = Doctrine_Inflector::urlize(sfSympalAssetToolkit::getNameFromFile($fileName)); $extension = pathinfo($fileName, PATHINFO_EXTENSION); $fullName = $extension ? $name . '.' . $extension : $name; $newPath = $this->asset->getPathDirectory() . '/' . $fullName; $this->asset->move($newPath); $postFile->save($newPath); $this->asset->save(); $this->asset->copyOriginal(); } else { if ($this->asset->isImage()) { $this->asset->resize($this->form->getValue('width'), $this->form->getValue('height')); } $this->asset->rename($this->form->getValue('new_name')); } $this->asset->save(); if ($this->isAjax) { $this->redirect('@sympal_assets_select?is_ajax=1&dir=' . $this->asset->getRelativePathDirectory()); } else { $this->redirect($this->generateUrl('sympal_assets_edit_asset', $this->asset)); } } } else { $values = array('new_name' => $this->asset->getName(), 'current_name' => $this->asset->getName(), 'directory' => $this->asset->getRelativePathDirectory()); if ($this->asset->isImage()) { $values['width'] = $this->asset->getWidth(); $values['height'] = $this->asset->getHeight(); } $this->form = new sfSympalAssetEditForm($values); $this->form->setAsset($this->asset); } }
public function getOriginal() { if (!$this->_original) { $original = sfSympalAssetToolkit::createAssetObject($this->getRelativePathDirectory() . '/' . sfSympalConfig::get('assets', 'originals_dir') . '/' . $this->getName()); if ($original->exists()) { $this->_original = $original; } } return $this->_original; }
/** * Returns an sfSympalAssetObject instance representing an original * copy of this asset (if one exists) * * @param boolean $create Whether or not to try to create an original if it doesn't exist * @return sfSympalAssetObject */ public function getOriginal($create = true) { if (!$this->_original) { $original = sfSympalAssetToolkit::createAssetObject($this->getRelativePathDirectory() . DIRECTORY_SEPARATOR . sfSympalConfig::get('assets', 'originals_dir') . DIRECTORY_SEPARATOR . $this->getName()); if ($original->exists()) { $this->_original = $original; } elseif ($create) { $this->getDoctrineAsset()->copyOriginal(); // try to get the original, but don't create on failure $this->_original = $this->getOriginal(false); } } return $this->_original; }