/** * Retrieves folder by relative path * * @param string $path * @param string $separator * @return sfAssetFolder */ public static function retrieveByPath($path = '', $separator = DIRECTORY_SEPARATOR) { $path = self::cleanPath($path); $c = new Criteria(); $c->add(sfAssetFolderPeer::RELATIVE_PATH, $path ? $path : null); return sfAssetFolderPeer::doSelectOne($c); }
/** * Retrieves a sfAsset object from a relative URL like * /medias/foo/bar.jpg * i.e. the kind of URL returned by $sf_asset->getUrl() */ public static function retrieveFromUrl($url) { $url = sfAssetFolderPeer::cleanPath($url); list($relPath, $filename) = sfAssetsLibraryTools::splitPath($url); $c = new Criteria(); $c->add(sfAssetPeer::FILENAME, $filename); $c->addJoin(sfAssetPeer::FOLDER_ID, sfAssetFolderPeer::ID); $c->add(sfAssetFolderPeer::RELATIVE_PATH, $relPath ? $relPath : null); return sfAssetPeer::doSelectOne($c); }
public function configure() { // remove unneeded fields unset($this['name'], $this['tree_left'], $this['tree_right'], $this['relative_path'], $this['created_at'], $this['updated_at']); // add parent folder select $this->widgetSchema['parent_folder'] = new sfWidgetFormPropelChoice(array('model' => 'sfAssetFolder', 'criteria' => sfAssetFolderPeer::getAllNonDescendantsPathsCriteria($this->getObject()))); $this->validatorSchema['parent_folder'] = new sfValidatorPropelChoice(array('model' => 'sfAssetFolder', 'column' => 'id', 'required' => true)); // avoid id conflict for id $this->widgetSchema['id']->setIdFormat('move_%s'); }
public function configure() { // remove unneeded fields unset($this['folder_id'], $this['filename'], $this['description'], $this['author'], $this['copyright'], $this['type'], $this['filesize'], $this['created_at']); // add parent folder select $this->widgetSchema['parent_folder'] = new sfWidgetFormPropelChoice(array('model' => 'sfAssetFolder', 'criteria' => sfAssetFolderPeer::getAllPathsButOneCriteria($this->getObject()->getsfAssetFolder()))); $this->validatorSchema['parent_folder'] = new sfValidatorPropelChoice(array('model' => 'sfAssetFolder', 'column' => 'id', 'required' => true)); // avoid id conflict for id $this->widgetSchema['id']->setIdFormat('move_%s'); }
public function getSubfoldersWithFolderNames() { $c = new Criteria(); $c->add(sfAssetFolderPeer::TREE_PARENT, $this->getId()); $folders = sfAssetFolderPeer::doSelect($c); $foldernames = array(); foreach ($folders as $folder) { $foldernames[$folder->getName()] = $folder; } return $foldernames; }
/** * 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); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); if (sfAssetFolderPeer::retrieveRoot()) { throw new sfException('The asset library already has a root'); } $this->logSection('asset', sprintf('Creating root node at %s...', sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')), null, 'COMMENT'); $folder = new sfAssetFolder(); $folder->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')); sfAssetFolderPeer::createRoot($folder); $folder->save(); $this->logSection('asset', 'Root Node Created', null, 'INFO'); }
/** * * @param object $task * @param array $args */ function run_sfassetlibrary_create_root($task, $args) { $app = $args[0]; $env = empty($args[1]) ? 'dev' : $args[1]; // define constants define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', $app); define('SF_ENVIRONMENT', $env); define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; // initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $con = Propel::getConnection(); if (sfAssetFolderPeer::getRoot()) { throw new sfException('The asset library already has a root'); } echo pakeColor::colorize(sprintf("Creating root node at %s...\n", sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')), 'COMMENT'); sfAssetFolderPeer::createRoot(); echo pakeColor::colorize("Root Node Created\n", 'INFO'); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); if (!($rootFolder = sfAssetFolderPeer::retrieveRoot())) { $task = new sfAssetCreateRootTask($this->dispatcher, $this->formatter); $task->setCommandApplication($this->commandApplication); $taskOption = array('--env=' . $options['env'], '--connection=' . $options['connection']); if ($options['application']) { $taskOption[] = '--application=' . $options['application']; } $ret = $task->run(array(), $taskOption); $rootFolder = sfAssetFolderPeer::retrieveRoot(); } $this->logSection('asset', sprintf('Comparing files from %s with assets stored in the database...', $arguments['dirname']), null, 'COMMENT'); try { $rootFolder->synchronizeWith($arguments['dirname'], $options['verbose'], $options['removeOrphanAssets'], $options['removeOrphanFolders']); } catch (sfAssetException $e) { throw new sfException(strtr($e->getMessage(), $e->getMessageParams())); } $this->logSection('asset', 'Synchronization complete', null, 'INFO'); }
/** * * @param object $task * @param array $args */ function run_sfassetlibrary_synchronize($task, $args, $options) { if (!count($args)) { sfAssetsLibraryTools::log('Usage: php symfony sfassetlibrary-synchronize [app] [dirname] --notVerbose --removeOrphanAssets --removeOrphanFolders'); return; } $app = $args[0]; if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) { throw new Exception('The app "' . $app . '" does not exist.'); } if (!isset($args[1])) { throw new Exception('You must define a sychronization folder'); } $base_folder = $args[1]; $verbose = array_key_exists('notVerbose', $options) ? false : true; $removeOrphanAssets = array_key_exists('removeOrphanAssets', $options) ? true : false; $removeOrphanFolders = array_key_exists('removeOrphanFolders', $options) ? true : false; // define constants define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', $app); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', true); // get configuration require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; // initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $con = Propel::getConnection(); // synchronize sfAssetsLibraryTools::log(sprintf("Comparing files from %s with assets stored in the database...", $base_folder), 'green'); $rootFolder = sfAssetFolderPeer::getRoot(); try { $rootFolder->synchronizeWith($base_folder, $verbose, $removeOrphanAssets, $removeOrphanFolders); } catch (sfAssetException $e) { throw new sfException(strtr($e->getMessage(), $e->getMessageParams())); } echo pakeColor::colorize("Synchronization complete\n", 'INFO'); }
<?php echo form_tag('sfAsset/moveFolder', 'method=post'); echo input_hidden_tag('id', $folder->getId()); ?> <div class="form-row"> <label for="new_folder"> <?php echo image_tag('/sfAssetsLibraryPlugin/images/folder_go.png', 'align=top'); ?> <?php echo link_to_function(__('Move folder', null, 'sfAsset'), 'document.getElementById("input_move_folder").style.display="block"'); ?> </label> <div class="content" id="input_move_folder" style="display:none"> <?php echo select_tag('new_folder', options_for_select(sfAssetFolderPeer::getAllNonDescendantsPaths($folder), $folder->getParentPath()), 'style=width:170px'); ?> <?php echo submit_tag(__('Ok', null, 'sfAsset')); ?> </div> </div> </form> <div class="form-row"> <?php echo image_tag('/sfAssetsLibraryPlugin/images/folder_delete.png', 'align=top'); ?> <?php echo link_to(__('Delete folder', null, 'sfAsset'), 'sfAsset/deleteFolder?id=' . $folder->getId(), array('post' => true, 'confirm' => __('Are you sure?', null, 'sfAsset'))); ?>
<?php $app = "frontend"; include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php'; $browser = new sfTestBrowser(); $browser->initialize(); $con = Propel::getConnection(); $con->begin(); try { $t = new lime_test(5, new lime_output_color()); $t->diag('sfAssetPeer'); $con->begin(); $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::getRoot()->getRelativePath() . '/filename.jpg'), null, 'sfAssetPeer::retrieveFromUrl() returns null when a URL is not found'); $t->is(sfAssetPeer::exists(sfAssetFolderPeer::getRoot()->getId(), 'filename.jpg'), false, 'sfAssetPeer::exists() returns false when an asset is not found'); $sfAsset = new sfAsset(); $sfAsset->setsfAssetFolder(sfAssetFolderPeer::getRoot()); $sfAsset->setFilename('filename.jpg'); $sfAsset->save($con); $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::getRoot()->getRelativePath() . '/filename.jpg')->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from its URL'); $t->is(sfAssetPeer::retrieveFromUrl($sfAsset->getUrl())->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from the result of `getUrl()`'); $t->is(sfAssetPeer::exists(sfAssetFolderPeer::getRoot()->getId(), 'filename.jpg'), true, 'sfAssetPeer::exists() returns true when an asset is found'); } catch (Exception $e) { echo $e->getMessage(); } // reset DB $con->rollback();
/** * 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; }
/** * Get the associated sfAssetFolder object * * @param PropelPDO Optional Connection object. * @return sfAssetFolder The associated sfAssetFolder object. * @throws PropelException */ public function getsfAssetFolder(PropelPDO $con = null) { if ($this->asfAssetFolder === null && $this->folder_id !== null) { $c = new Criteria(sfAssetFolderPeer::DATABASE_NAME); $c->add(sfAssetFolderPeer::ID, $this->folder_id); $this->asfAssetFolder = sfAssetFolderPeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->asfAssetFolder->addsfAssets($this); */ } return $this->asfAssetFolder; }
public static function doSelectJoinAll(Criteria $c, $con = null) { foreach (sfMixer::getCallables('BasesfAssetPeer:doSelectJoinAll:doSelectJoinAll') as $callable) { call_user_func($callable, 'BasesfAssetPeer', $c, $con); } $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } sfAssetPeer::addSelectColumns($c); $startcol2 = sfAssetPeer::NUM_COLUMNS - sfAssetPeer::NUM_LAZY_LOAD_COLUMNS + 1; sfAssetFolderPeer::addSelectColumns($c); $startcol3 = $startcol2 + sfAssetFolderPeer::NUM_COLUMNS; $c->addJoin(sfAssetPeer::FOLDER_ID, sfAssetFolderPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = sfAssetPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = sfAssetFolderPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getsfAssetFolder(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addsfAsset($obj1); break; } } if ($newObject) { $obj2->initsfAssets(); $obj2->addsfAsset($obj1); } $results[] = $obj1; } return $results; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(sfAssetFolderPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(sfAssetFolderPeer::DATABASE_NAME); $criteria->add(sfAssetFolderPeer::ID, $pks, Criteria::IN); $objs = sfAssetFolderPeer::doSelect($criteria, $con); } return $objs; }
/** * get files of folder, sorted * @param array $dirs * @param string $sortOrder * @return array */ public function getSortedFiles(array $dirs, $sortOrder) { $c = new Criteria(); $c->add(sfAssetPeer::FOLDER_ID, $this->getId()); switch ($sortOrder) { case 'date': $dirs = sfAssetFolderPeer::sortByDate($dirs); $c->addDescendingOrderByColumn(sfAssetPeer::CREATED_AT); break; default: $dirs = sfAssetFolderPeer::sortByName($dirs); $c->addAscendingOrderByColumn(sfAssetPeer::FILENAME); } return sfAssetPeer::doSelect($c); }
public function executeMoveAsset() { $this->forward404Unless($this->getRequest()->getMethod() == sfRequest::POST); $sf_asset = sfAssetPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($sf_asset); $folder = sfAssetFolderPeer::retrieveByPath($this->getRequestParameter('new_folder')); $this->forward404Unless($folder); if ($folder->getId() != $sf_asset->getFolderId()) { try { $sf_asset->move($folder); $sf_asset->save(); $this->setFlash('notice', 'The file has been moved'); } catch (sfAssetException $e) { $this->setFlash('warning_message', $e->getMessage()); $this->setFlash('warning_params', $e->getMessageParams()); } } else { $this->setFlash('warning', 'The target folder is the same as the original folder. The asset has not been moved.'); } return $this->redirect('sfAsset/edit?id=' . $sf_asset->getId()); }
/** * Inserts node as parent of given node. * * @param sfAssetFolder $node Propel object for destination node * @param PropelPDO $con Connection to use. * @return sfAssetFolder The current object (for fluent API support) */ public function insertAsParentOf(NodeObject $node, PropelPDO $con = null) { sfAssetFolderPeer::insertAsParentOf($this, $node, $con); return $this; }
$t->diag('sfAssetFolder::move()'); # move $sfAssetFolder2 from /root/Test_Directory/Test_Sub-directory to /root/Test_Sub-directory $sfAssetFolder2->move($root); $sfAssetFolder2->save(); # So now we have: # root/ # Test_Directory/ sfAssetFolder # Test_Sub-directory/ sfAssetFolder2 # Test_Sub-sub-directory/ sfAssetFolder3 # toto # raikkonen.jpg // Bug in Propel instance pooling + NestedSets... sfAssetFolderPeer::clearInstancePool(); $root = sfAssetFolderPeer::retrieveByPk($rootId); $sfAssetFolder2 = sfAssetFolderPeer::retrieveByPk($id2); $sfAssetFolder3 = sfAssetFolderPeer::retrieveByPk($id3); $t->is($sfAssetFolder2->retrieveParent()->getId(), $root->getId(), 'move() gives the correct parent'); $t->is($sfAssetFolder3->retrieveParent()->retrieveParent()->getId(), $root->getId(), 'move() also moves children'); $t->is($sfAssetFolder2->getRelativePath(), $root->getRelativePath() . '/' . $sfAssetFolder2->getName(), 'move() changes descendants relative paths'); $t->is($sfAssetFolder3->getRelativePath(), $sfAssetFolder2->getRelativePath() . '/' . $sfAssetFolder3->getName(), 'move() changes descendants relative paths'); sfAssetPeer::clearInstancePool(); $sfAsset = sfAssetPeer::retrieveByPk($sf_asset_id); $sfAsset2 = sfAssetPeer::retrieveByPk($sf_asset2_id); $t->ok(is_file($sfAsset->getFullPath()), 'move() also moves assets under the moved folder'); $t->ok(is_file($sfAsset2->getFullPath()), 'move() also moves assets under the moved folder'); } catch (Exception $e) { echo $e->getMessage(); } // reset DB $con->rollBack(); function debugTree($root)
/** * Reload all already loaded nodes to sync them with updated db * * @param sfAssetFolder $node Propel object for parent node * @param int $delta Value to be shifted by, can be negative * @param PropelPDO $con Connection to use. */ protected static function updateLoadedNode(NodeObject $node, $delta, PropelPDO $con = null) { if (Propel::isInstancePoolingEnabled()) { $keys = array(); foreach (self::$instances as $obj) { $keys[] = $obj->getPrimaryKey(); } if (!empty($keys)) { // We don't need to alter the object instance pool; we're just modifying these ones // already in the pool. $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(sfAssetFolderPeer::ID, $keys, Criteria::IN); $stmt = sfAssetFolderPeer::doSelectStmt($criteria, $con); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key = sfAssetFolderPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($object = sfAssetFolderPeer::getInstanceFromPool($key))) { $object->setLeftValue($row[1]); $object->setRightValue($row[2]); } } $stmt->closeCursor(); } } }
/** * move asset * @param sfWebRequest $request */ public function executeMoveAsset(sfWebRequest $request) { $this->forward404Unless($request->getMethod() == sfRequest::POST, 'method not allowed'); $sfAsset = $request->getParameter('sf_asset'); $asset = sfAssetPeer::retrieveByPK($sfAsset['id']); $this->forward404Unless($asset, 'asset not found'); $destFolder = sfAssetFolderPeer::retrieveByPk($sfAsset['parent_folder']); $this->forward404Unless($destFolder, 'destination folder not found'); $this->form = new sfAssetMoveForm($asset); $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid() && $destFolder->getId() != $asset->getFolderId()) { try { $asset->move($destFolder); $asset->save(); $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset))); $this->getUser()->setFlash('notice', 'The file has been moved'); } catch (sfAssetException $e) { $this->getUser()->setFlash('warning_message', $e->getMessage()); $this->getUser()->setFlash('warning_params', $e->getMessageParams()); } } else { $this->getUser()->setFlash('warning', 'The asset has not been moved.'); } return $this->redirect('@sf_asset_library_edit?id=' . $asset->getId()); }
<?php include_partial('sfAsset/create_folder_header'); ?> <?php echo form_tag('sfAsset/massUpload', 'method=post multipart=true'); ?> <fieldset> <div class="form-row"> <label for="parent_folder"><?php echo __('Place under:', null, 'sfAsset'); ?> </label> <?php echo select_tag('parent_folder', options_for_select(sfAssetFolderPeer::getAllPaths(), $sf_params->get('parent_folder'))); ?> </div> <?php for ($i = 1; $i <= sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5); $i++) { ?> <div class="form-row"> <label for="files_1"><?php echo __('File %nb%:', array('%nb%' => $i), 'sfAsset'); ?> </label> <?php echo input_file_tag('files[' . $i . ']'); ?> </div>
echo link_to_function(__('Search', null, 'sfAsset'), 'document.getElementById("sf_asset_search").style.display="block"'); ?> </div> <?php echo form_tag('sfAsset/search', array('method' => 'get', 'id' => 'sf_asset_search', 'style' => 'display:none')); ?> <div class="form-row"> <label for="search_params_rel_path"><?php echo __('Folder:', null, 'sfAsset'); ?> </label> <div class="content"> <?php echo select_tag('search_params[path]', '<option></option>' . options_for_select(sfAssetFolderPeer::getAllPaths(), isset($search_params['path']) ? $search_params['path'] : null), 'style=width:200px'); ?> </div> </div> <div class="form-row"> <label for="search_params_name"><?php echo __('Filename:', null, 'sfAsset'); ?> </label> <div class="content"> <?php echo input_tag('search_params[name]', isset($search_params['name']) ? $search_params['name'] : null, 'size=20'); ?> </div> </div>
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = sfAssetFolderPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTreeLeft($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setTreeRight($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setTreeParent($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setStaticScope($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setName($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setRelativePath($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setCreatedAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setUpdatedAt($arr[$keys[8]]); } }
$browser->initialize(); $con = Propel::getConnection(); $con->begin(); try { // run the test $t = new lime_test(13, new lime_output_color()); $t->diag('sfAssetFolderPeer'); $sfAssetFolder = sfAssetFolderPeer::retrieveByPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')); $t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from app_sfAssetsLibrary_upload_dir string'); $sfAssetFolder = sfAssetFolderPeer::retrieveByPath(); $t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from empty string'); $sfAssetFolder = sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . '/simple'); $t->isa_ok($sfAssetFolder, 'sfAssetFolder', 'createFromPath() creates a sfAssetFolder from simple string'); $t->isa_ok($sfAssetFolder->getParent(), 'sfAssetFolder', 'createFromPath() from simple string has a parent'); $t->ok($sfAssetFolder->getParent()->isRoot(), 'createFromPath() creates a root child from simple string'); $sfAssetFolder2 = sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . '/simple/subfolder'); $t->isa_ok($sfAssetFolder2, 'sfAssetFolder', 'createFromPath() creates a sfAssetFolder from simple string'); $t->is($sfAssetFolder2->getParent()->getId(), $sfAssetFolder->getId(), 'createFromPath() from simple string parent is correct'); $sfAssetFolder = sfAssetFolderPeer::createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . '/second/subfolder'); $t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a sfAssetFolder from simple string'); $t->ok($sfAssetFolder->getParent() instanceof sfAssetFolder, 'createFromPath() from composed string has a parent'); $t->ok($sfAssetFolder->getParent()->getParent()->isRoot(), 'createFromPath() creates a root child from composed string'); $sfAssetFolder = sfAssetFolderPeer::createFromPath('third/subfolder'); $t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a sfAssetFolder from simple string'); $t->ok($sfAssetFolder->getParent() instanceof sfAssetFolder, 'createFromPath() from composed string has a parent'); $t->ok($sfAssetFolder->getParent()->getParent()->isRoot(), 'createFromPath() creates a root child from composed string'); } catch (Exception $e) { // do nothing } // reset DB $con->rollback();
/** * Retrieves a sfAsset object from a relative URL like * /medias/foo/bar.jpg * i.e. the kind of URL returned by $sf_asset->getUrl() */ public static function retrieveFromUrl($url) { $url = sfAssetFolderPeer::cleanPath($url); list($relPath, $filename) = sfAssetsLibraryTools::splitPath($url); return Doctrine::getTable('sfAsset a')->createQuery()->leftJoin('sfAssetFolder f')->where('f.relative_path = ? AND a.filename = ', $relPath ? $relPath : null, $filename)->fetchOne(); }
public function retrieveParentIgnoringPooling(PropelPDO $con = null) { return sfAssetFolderPeer::retrieveParent($this, $con); }
/** * Selects a collection of sfAsset objects pre-filled with all related objects. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of sfAsset objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { foreach (sfMixer::getCallables('BasesfAssetPeer:doSelectJoinAll:doSelectJoinAll') as $callable) { call_user_func($callable, 'BasesfAssetPeer', $c, $con); } $c = clone $c; // Set the correct dbName if it has not been overridden if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } sfAssetPeer::addSelectColumns($c); $startcol2 = sfAssetPeer::NUM_COLUMNS - sfAssetPeer::NUM_LAZY_LOAD_COLUMNS; sfAssetFolderPeer::addSelectColumns($c); $startcol3 = $startcol2 + (sfAssetFolderPeer::NUM_COLUMNS - sfAssetFolderPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(sfAssetPeer::FOLDER_ID), array(sfAssetFolderPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = sfAssetPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = sfAssetPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = sfAssetPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); sfAssetPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined sfAssetFolder rows $key2 = sfAssetFolderPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = sfAssetFolderPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = sfAssetFolderPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); sfAssetFolderPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (sfAsset) to the collection in $obj2 (sfAssetFolder) $obj2->addsfAsset($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Selects a collection of Property objects pre-filled with all related objects except Kitchen. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of Property objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptKitchen(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } PropertyPeer::addSelectColumns($c); $startcol2 = PropertyPeer::NUM_COLUMNS - PropertyPeer::NUM_LAZY_LOAD_COLUMNS; OfferPeer::addSelectColumns($c); $startcol3 = $startcol2 + (OfferPeer::NUM_COLUMNS - OfferPeer::NUM_LAZY_LOAD_COLUMNS); TypePeer::addSelectColumns($c); $startcol4 = $startcol3 + (TypePeer::NUM_COLUMNS - TypePeer::NUM_LAZY_LOAD_COLUMNS); TypologyPeer::addSelectColumns($c); $startcol5 = $startcol4 + (TypologyPeer::NUM_COLUMNS - TypologyPeer::NUM_LAZY_LOAD_COLUMNS); StatePeer::addSelectColumns($c); $startcol6 = $startcol5 + (StatePeer::NUM_COLUMNS - StatePeer::NUM_LAZY_LOAD_COLUMNS); sfAssetFolderPeer::addSelectColumns($c); $startcol7 = $startcol6 + (sfAssetFolderPeer::NUM_COLUMNS - sfAssetFolderPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(PropertyPeer::OFFER_ID), array(OfferPeer::ID), $join_behavior); $c->addJoin(array(PropertyPeer::TYPE_ID), array(TypePeer::ID), $join_behavior); $c->addJoin(array(PropertyPeer::TYPOLOGY_ID), array(TypologyPeer::ID), $join_behavior); $c->addJoin(array(PropertyPeer::STATE_ID), array(StatePeer::ID), $join_behavior); $c->addJoin(array(PropertyPeer::SF_ASSET_FOLDER_ID), array(sfAssetFolderPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PropertyPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PropertyPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = PropertyPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); PropertyPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Offer rows $key2 = OfferPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = OfferPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = OfferPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); OfferPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (Property) to the collection in $obj2 (Offer) $obj2->addProperty($obj1); } // if joined row is not null // Add objects for joined Type rows $key3 = TypePeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = TypePeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = TypePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); TypePeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (Property) to the collection in $obj3 (Type) $obj3->addProperty($obj1); } // if joined row is not null // Add objects for joined Typology rows $key4 = TypologyPeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = TypologyPeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = TypologyPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); TypologyPeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (Property) to the collection in $obj4 (Typology) $obj4->addProperty($obj1); } // if joined row is not null // Add objects for joined State rows $key5 = StatePeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = StatePeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = StatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); StatePeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (Property) to the collection in $obj5 (State) $obj5->addProperty($obj1); } // if joined row is not null // Add objects for joined sfAssetFolder rows $key6 = sfAssetFolderPeer::getPrimaryKeyHashFromRow($row, $startcol6); if ($key6 !== null) { $obj6 = sfAssetFolderPeer::getInstanceFromPool($key6); if (!$obj6) { $omClass = sfAssetFolderPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj6 = new $cls(); $obj6->hydrate($row, $startcol6); sfAssetFolderPeer::addInstanceToPool($obj6, $key6); } // if $obj6 already loaded // Add the $obj1 (Property) to the collection in $obj6 (sfAssetFolder) $obj6->addProperty($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }