コード例 #1
0
 /**
  * save
  * @param PropelPDO $con
  */
 protected function doSave($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     $this->updateObject();
     $parent = sfAssetFolderPeer::retrieveByPK($this->getValue('parent_folder'));
     $this->getObject()->insertAsLastChildOf($parent);
     $this->getObject()->save($con);
     // embedded forms
     $this->saveEmbeddedForms($con);
 }
コード例 #2
0
 /**
  * Returns a node given its primary key or the node itself
  *
  * @param      int/sfAssetFolder $node	Primary key/instance of required node
  * @param      PropelPDO $con		Connection to use.
  * @return     object		Propel object for model
  */
 public static function getNode($node, PropelPDO $con = null)
 {
     if (is_object($node)) {
         return $node;
     } else {
         $object = sfAssetFolderPeer::retrieveByPK($node, $con);
         $rtn = is_object($object) ? $object : false;
         return $rtn;
     }
 }
コード例 #3
0
 /**
  * upload many assets
  * @param sfWebRequest $request
  */
 public function executeMassUpload(sfWebRequest $request)
 {
     $options = array('size' => sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5));
     try {
         $options['author'] = $this->getUser()->getUsername();
     } catch (Exception $e) {
     }
     $this->form = new sfAssetsForm(null, $options);
     if ($request->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             try {
                 $this->form->save();
                 foreach ($this->form->assets as $asset) {
                     $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset)));
                 }
             } catch (sfAssetException $e) {
                 $this->getUser()->setFlash('warning_message', $e->getMessage());
                 $this->getUser()->setFlash('warning_params', $e->getMessageParams());
                 $folder = sfAssetFolderPeer::retrieveByPK($this->form->getValue('folder_id'));
                 $this->redirectToPath('@sf_asset_library_dir?dir=' . $folder->getRelativePath());
             }
             $this->getUser()->setFlash('notice', 'Files successfully uploaded');
             $this->redirectToPath('@sf_asset_library_dir?dir=' . $asset->getFolderPath());
         }
     }
 }
コード例 #4
0
 /**
  * upload many assets
  * @param sfWebRequest $request
  */
 public function executeMassUpload(sfWebRequest $request)
 {
     $this->form = new sfAssetsForm(null, array('size' => sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5)));
     if ($request->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $folder = sfAssetFolderPeer::retrieveByPK($this->form->getValue('folder_id'));
             $this->forward404Unless($folder, 'folder not found');
             try {
                 $nbFiles = 0;
                 for ($i = 1; $i <= sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5); $i++) {
                     if ($file = $this->form->getValue('file_' . $i)) {
                         $asset = new sfAsset();
                         $asset->setsfAssetFolder($folder);
                         $asset->setDescription($file->getOriginalName());
                         try {
                             $asset->setAuthor($this->getUser()->getUsername());
                         } catch (sfException $e) {
                             // no getUsername() method in sfUser, all right: do nothing
                         }
                         $asset->setFilename($file->getOriginalName());
                         $asset->create($file->getTempName());
                         $asset->save();
                         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset)));
                         $nbFiles++;
                     }
                 }
             } catch (sfAssetException $e) {
                 $this->getUser()->setFlash('warning_message', $e->getMessage());
                 $this->getUser()->setFlash('warning_params', $e->getMessageParams());
                 $this->redirectToPath('@sf_asset_library_dir?dir=' . $folder->getRelativePath());
             }
             $this->getUser()->setFlash('notice', 'Files successfully uploaded');
             $this->redirectToPath('@sf_asset_library_dir?dir=' . $folder->getRelativePath());
         }
     }
 }
コード例 #5
0
 /**
  * process search
  * @param  array    $params
  * @param  string   $sort
  * @return Criteria
  */
 protected static function search(array $params, $sort = 'name')
 {
     $c = new Criteria();
     if (isset($params['folder_id']) && $params['folder_id'] !== '') {
         if (null != ($folder = sfAssetFolderPeer::retrieveByPK($params['folder_id']))) {
             $c->addJoin(self::FOLDER_ID, sfAssetFolderPeer::ID);
             $c->add(sfAssetFolderPeer::TREE_LEFT, $folder->getTreeLeft(), Criteria::GREATER_EQUAL);
             $c->add(sfAssetFolderPeer::TREE_RIGHT, $folder->getTreeRIGHT(), Criteria::LESS_EQUAL);
         }
     }
     if (isset($params['filename']['is_empty'])) {
         $criterion = $c->getNewCriterion(self::FILENAME, '');
         $criterion->addOr($c->getNewCriterion(self::FILENAME, null, Criteria::ISNULL));
         $c->add($criterion);
     } elseif (isset($params['filename']['text']) && $params['filename']['text'] !== '') {
         $c->add(self::FILENAME, '%' . trim($params['filename']['text'], '*%') . '%', Criteria::LIKE);
     }
     if (isset($params['author']['is_empty'])) {
         $criterion = $c->getNewCriterion(self::AUTHOR, '');
         $criterion->addOr($c->getNewCriterion(self::AUTHOR, null, Criteria::ISNULL));
         $c->add($criterion);
     } elseif (isset($params['author']['text']) && $params['author']['text'] !== '') {
         $c->add(self::AUTHOR, '%' . trim($params['author']['text'], '*%') . '%', Criteria::LIKE);
     }
     if (isset($params['copyright']['is_empty'])) {
         $criterion = $c->getNewCriterion(self::COPYRIGHT, '');
         $criterion->addOr($c->getNewCriterion(self::COPYRIGHT, null, Criteria::ISNULL));
         $c->add($criterion);
     } elseif (isset($params['copyright']['text']) && $params['copyright']['text'] !== '') {
         $c->add(self::COPYRIGHT, '%' . trim($params['copyright']['text'], '*%') . '%', Criteria::LIKE);
     }
     if (isset($params['created_at'])) {
         if (isset($params['created_at']['from']) && $params['created_at']['from'] !== array()) {
             $criterion = $c->getNewCriterion(self::CREATED_AT, $params['created_at']['from'], Criteria::GREATER_EQUAL);
         }
         if (isset($params['created_at']['to']) && $params['created_at']['to'] !== array()) {
             if (isset($criterion)) {
                 $criterion->addAnd($c->getNewCriterion(self::CREATED_AT, $params['created_at']['to'], Criteria::LESS_EQUAL));
             } else {
                 $criterion = $c->getNewCriterion(self::CREATED_AT, $params['created_at']['to'], Criteria::LESS_EQUAL);
             }
         }
         if (isset($criterion)) {
             $c->add($criterion);
         }
     }
     if (isset($params['description']['is_empty'])) {
         $criterion = $c->getNewCriterion(self::DESCRIPTION, '');
         $criterion->addOr($c->getNewCriterion(self::DESCRIPTION, null, Criteria::ISNULL));
         $c->add($criterion);
     } else {
         if (isset($params['description']) && $params['description'] !== '') {
             $c->add(self::DESCRIPTION, '%' . trim($params['description'], '*%') . '%', Criteria::LIKE);
         }
     }
     switch ($sort) {
         case 'date':
             $c->addDescendingOrderByColumn(self::CREATED_AT);
             break;
         default:
             $c->addAscendingOrderByColumn(self::FILENAME);
     }
     return $c;
 }
コード例 #6
0
ファイル: BasesfAsset.php プロジェクト: sgrove/cothinker
 public function getsfAssetFolder($con = null)
 {
     if ($this->asfAssetFolder === null && $this->folder_id !== null) {
         include_once 'plugins/sfAssetsLibraryPlugin/lib/model/om/BasesfAssetFolderPeer.php';
         $this->asfAssetFolder = sfAssetFolderPeer::retrieveByPK($this->folder_id, $con);
     }
     return $this->asfAssetFolder;
 }