public function executeCreate_asset(sfWebRequest $request)
 {
     $form = new sfSympalAssetUploadForm();
     $upload = $request->getParameter($form->getName());
     $form->setUploadDirectory($upload['directory']);
     $form->bind($upload, $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $postFile = $form->getValue('file');
         $fileName = $postFile->getOriginalName();
         $name = Doctrine_Inflector::urlize(sfSympalAssetToolkit::getNameFromFile($fileName));
         $extension = pathinfo($fileName, PATHINFO_EXTENSION);
         $fullName = $extension ? $name . '.' . $extension : $name;
         $destinationDirectory = sfConfig::get('sf_web_dir') . '/' . sfSympalConfig::get('assets', 'root_dir') . $upload['directory'];
         $this->getUser()->setFlash('notice', 'File uploaded successfully.');
         $postFile->save($destinationDirectory . '/' . $fullName);
         $assetObject = sfSympalAssetToolkit::createAssetObject($upload['directory'] . '/' . $fullName);
         if (!($asset = $assetObject->getDoctrineAsset())) {
             $asset = new sfSympalAsset();
         }
         $asset->path = $assetObject->getRelativePathDirectory();
         $asset->name = $assetObject->getName();
         $asset->save();
     } else {
         $this->getUser()->setFlash('error', 'Could not upload file.');
     }
     if ($this->isAjax) {
         $this->redirect('@sympal_assets_select?is_ajax=' . $this->isAjax . '&dir=' . $upload['directory']);
     } else {
         $this->redirect('@sympal_assets?is_ajax=' . $this->isAjax . '&dir=' . $upload['directory']);
     }
 }
Ejemplo n.º 2
0
 public function setAsset(sfSympalAsset $asset)
 {
     $this->setUploadDirectory($asset->getRootPath());
     $this->_asset = $asset;
     if ($this->_asset->isImage()) {
         $this->widgetSchema['width'] = new sfWidgetFormInput();
         $this->widgetSchema['height'] = new sfWidgetFormInput();
         $this->validatorSchema['width'] = new sfValidatorString(array('trim' => true));
         $this->validatorSchema['height'] = new sfValidatorString(array('trim' => true));
     }
 }
 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();
         }
     }
 }
function check_asset_values(lime_test $t, sfSympalAsset $asset, $values)
{
    $savedValues = $asset->toArray();
    unset($savedValues['id']);
    $t->is($savedValues, $values, sprintf('The asset "%s" has the correct values', $values['name']));
}