/** * replace asset * @param sfWebRequest $request */ public function executeReplaceAsset(sfWebRequest $request) { $this->forward404Unless($request->isMethod(sfRequest::POST), 'method not allowed'); $sfAsset = $request->getParameter('sf_asset'); $asset = sfAssetPeer::retrieveByPK($sfAsset['id']); $this->forward404Unless($asset, 'asset not found'); $this->form = new sfAssetReplaceForm($asset); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { // physically replace asset $file = $this->form->getValue('file'); $asset->destroy(); $asset->create($file->getTempName(), false, false); $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset))); $this->getUser()->setFlash('notice', 'The file has been replaced'); } return $this->redirect('@sf_asset_library_edit?id=' . $asset->getId()); }
/** * get input form field * @param string $name * @param integer $value possible value of asset id * @param array $options * @return string */ function input_sf_asset_image_tag($name, $value = null, $options = array()) { $url = str_replace('&', '&', url_for('@sf_asset_library_list?dir=' . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . '&popup=2')); $asset = empty($value) ? new sfAsset() : sfAssetPeer::retrieveByPK($value); return '<a id="sf_asset_input_image" href="#" rel="{url: \'' . $url . '\', name: \'' . $name . '\', type: \'' . $options['type'] . '\'}">' . image_tag('/sfAssetsLibraryPlugin/images/folder_open', array('alt' => 'Insert Image', 'title' => __('Insert Image', null, 'sfAsset'))) . '</a> ' . asset_image_tag($asset, 'small', array('id' => $options['id'] . '_img')); }