/** * Execute /../stock/listItem * * @param type $request */ public function execute($request) { $head = sfYaml::load(sfConfig::get('sf_app_dir') . '/lib/list/item_list.yml'); $itemlist_headers = array($head['listItem']['header1'], $head['listItem']['header2'], $head['listItem']['header3'], $head['listItem']['header6']); $columns = 'id,name,sales_unit_price,stock_available'; $recordsLimit = 5; //have to take from lists if (!$request->hasParameter('pageNo')) { $pageNo = 1; } else { $pageNo = $request->getParameter('pageNo', 1); } $pager = new SimplePager('Item', $recordsLimit); $pager->setPage($pageNo); $pager->setNumResults($this->getItemService()->countItems()); $pager->init(); $offset = $pager->getOffset(); $offset = empty($offset) ? 0 : $offset; $paramHolder = new sfParameterHolder(); $paramHolder->set('columns', $columns); $paramHolder->set('offset', $offset); $paramHolder->set('limit', $recordsLimit); $itemlist_data = $this->getItemService()->getItems($paramHolder); $listContainer = new ListContainer(); $listContainer->setListName('ItemList'); $listContainer->setListHeaders($itemlist_headers); $listContainer->setListContent($itemlist_data); $listContainer->setRowLink("stock/showItem?id="); $listContainer->setPager($pager); $this->listcontainer = $listContainer; }
public function execute($request) { $head = sfYaml::load(sfConfig::get('sf_app_dir') . '/lib/list/seller_list.yml'); $sellerlist_headers = array($head['listSeller']['header1'], $head['listSeller']['header2'], $head['listSeller']['header3'], $head['listSeller']['header4']); $columns = 'id,name,address,tp_hp'; $recordsLimit = 5; //have to take from lists if (!$request->hasParameter('pageNo')) { $pageNo = 1; } else { $pageNo = $request->getParameter('pageNo', 1); } $pager = new SimplePager('Seller', $recordsLimit); $pager->setPage($pageNo); $pager->setNumResults($this->getSellerService()->countSellers()); $pager->init(); $offset = $pager->getOffset(); $offset = empty($offset) ? 0 : $offset; $paramHolder = new sfParameterHolder(); $paramHolder->set('columns', $columns); $paramHolder->set('offset', $offset); $paramHolder->set('limit', $recordsLimit); $sellerlist_data = $this->getSellerService()->getSellers($paramHolder); $listContainer = new ListContainer(); $listContainer->setListName('SellerList'); $listContainer->setListHeaders($sellerlist_headers); $listContainer->setListContent($sellerlist_data); $listContainer->setRowLink("seller/showSeller?id="); $listContainer->setPager($pager); $this->listcontainer = $listContainer; }
/** * * @return Seller Doctrine-Collection * @throws DaoException */ public function getSellers(sfParameterHolder $paramHolder) { try { $query = Doctrine_Query::create()->select($paramHolder->get('columns'))->from('seller')->orderBy('name')->offset($paramHolder->get('offset'))->limit($paramHolder->get('limit')); return $query->execute(array(), Doctrine::HYDRATE_NONE); } catch (Exception $e) { throw new DaoException($e->getMessage(), $e->getCode(), $e); } }
/** * Returns variables that will be accessible to the template. * * @return array Attributes from the template */ protected function getGlobalVars() { $context = $this->getContext(); $shortcuts = array('sf_context' => $context, 'sf_params' => $context->getRequest()->getParameterHolder(), 'sf_request' => $context->getRequest(), 'sf_user' => $context->getUser(), 'sf_view' => $this); if (sfConfig::get('sf_use_flash')) { $sf_flash = new sfParameterHolder(); $sf_flash->add($context->getUser()->getAttributeHolder()->getAll('symfony/flash')); $shortcuts['sf_flash'] = $sf_flash; } return $shortcuts; }
public function &getAll($isStripNullbyte = true) { if ($isStripNullbyte) { $value = opToolkit::stripNullByteDeep(parent::getAll()); } else { $value =& parent::getAll(); } return $value; }
public function &get($name, $default = null) { if (self::$varTranslation === null) { self::$varTranslation = sfConfig::get('app_profile_var_translation', array()); } if (array_key_exists($name, self::$varTranslation)) { $name = strtolower(self::$varTranslation[$name]); } return parent::get($name, $default); }
// ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok($ph == unserialize(serialize($ph)), 'sfParameterHolder implements the Serializable interface'); // Array path as a key $t->diag('Array path as a key'); $ph = new sfParameterHolder(); $ph->add(array('foo' => array('bar' => 'foo'))); $t->is($ph->has('foo[bar]'), true, '->has() can takes a multi-array key'); $t->is($ph->get('foo[bar]'), 'foo', '->has() can takes a multi-array key'); $t->is($ph->remove('foo[bar]'), 'foo', '->remove() can takes a multi-array key'); $t->is($ph->getAll(), array('foo' => array()), '->remove() can takes a multi-array key');
<?php include_partial('entity/header', array('entity' => $entity, 'show_actions' => true)); ?> <?php include_partial('entity/modificationtabs', array('entity' => $entity)); ?> <?php include_partial('global/section', array('title' => 'Relationship Modifications', 'pointer' => 'Relationships with ' . $entity->name . ' that were recently added or removed')); ?> <?php $holder = new sfParameterHolder(); $holder->set('fromMerges', array()); include_partial('global/table', array('columns' => array('Date', 'User', 'Action', 'Relationship'), 'pager' => $modification_pager, 'row_partial' => 'modification/relationshiplistrow', 'holder' => $holder));
/** * update the currently set filters * * @param sfParameterHolder $attributeHolder * @param string $filter the name of the filter, typically from the query string * @param string $value the value of the filter * @param string $namespace the local filter namespace ('sf_admin/$namespace/filters') */ public static function updateAdminFilters(sfParameterHolder $attributeHolder, $filter, $value, $namespace) { $attributeHolder->set($filter, $value, "sf_admin/{$namespace}/filters"); return; }
/** * Loads the config for the search engine. */ protected function initialize() { // set a global configuration variable ... require $this->configuration->getConfigCache()->checkConfig('config/search.yml'); $holder = $this->getParameterHolder(); if (!isset($config[$holder->get('name')])) { throw new sfLuceneException('The name of this index is invalid : ' . $holder->get('name')); } $config = $config[$holder->get('name')]; foreach (array('encoding', 'cultures' => 'enabled_cultures', 'mb_string', 'host', 'port', 'base_url') as $key => $param) { if (is_int($key)) { $holder->set($param, $config['index'][$param]); } else { $holder->set($param, $config['index'][$key]); } } $models = new sfParameterHolder(); foreach ($config['models'] as $name => $model) { $fields = new sfParameterHolder(); foreach ($model['fields'] as $field => $fieldProperties) { $fieldsData = new sfParameterHolder(); $fieldsData->add($fieldProperties); $fields->set($field, $fieldsData); } $data = new sfParameterHolder(); $data->set('fields', $fields); $data->set('partial', $model['partial']); $data->set('indexer', $model['indexer']); $data->set('title', $model['title']); $data->set('description', $model['description']); $data->set('peer', $model['peer']); $data->set('rebuild_limit', $model['rebuild_limit']); $data->set('validator', $model['validator']); $data->set('categories', $model['categories']); $data->set('route', $model['route']); $data->set('callback', $model['callback']); $models->set($name, $data); } $holder->set('models', $models); $factories = new sfParameterHolder(); $factories->add($config['factories']); $holder->set('factories', $factories); if (!in_array($holder->get('culture'), $holder->get('enabled_cultures'))) { throw new sfLuceneException(sprintf('Culture "%s" is not enabled.', $holder->get('culture'))); } $this->raw_configuration = $config; }
/** * Simulates a click on a link or button. * * @param string $name The link or button text * @param array $arguments * * @return sfBrowser */ public function click($name, $arguments = array()) { $dom = $this->getResponseDom(); if (!$dom) { throw new sfException('Cannot click because there is no current page in the browser.'); } $xpath = new DomXpath($dom); // text link if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item(0)) { return $this->get($link->getAttribute('href')); } // image link if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item(0)) { return $this->get($link->getAttribute('href')); } // form if (!($form = $xpath->query(sprintf('//input[((@type="submit" or @type="button") and @value="%s") or (@type="image" and @alt="%s")]/ancestor::form', $name, $name))->item(0))) { if (!($form = $xpath->query(sprintf('//button[.="%s" or @id="%s" or @name="%s"]/ancestor::form', $name, $name, $name))->item(0))) { throw new sfException(sprintf('Cannot find the "%s" link or button.', $name)); } } // form attributes $url = $form->getAttribute('action'); $method = $form->getAttribute('method') ? strtolower($form->getAttribute('method')) : 'get'; // merge form default values and arguments $defaults = array(); $arguments = sfToolkit::arrayDeepMerge($this->fields, $arguments); foreach ($xpath->query('descendant::input | descendant::textarea | descendant::select', $form) as $element) { $elementName = $element->getAttribute('name'); $nodeName = $element->nodeName; $value = null; if ($nodeName == 'input' && ($element->getAttribute('type') == 'checkbox' || $element->getAttribute('type') == 'radio')) { if ($element->getAttribute('checked')) { $value = $element->getAttribute('value'); } } else { if ($nodeName == 'input' && $element->getAttribute('type') == 'file') { $ph = new sfParameterHolder(); $ph->add($arguments); $filename = $ph->get($elementName, ''); if (is_readable($filename)) { $fileError = UPLOAD_ERR_OK; $fileSize = filesize($filename); } else { $fileError = UPLOAD_ERR_NO_FILE; $fileSize = 0; } $ph->remove($elementName); $arguments = $ph->getAll(); $this->parseArgumentAsArray($elementName, array('name' => basename($filename), 'type' => '', 'tmp_name' => $filename, 'error' => $fileError, 'size' => $fileSize), $this->files); } else { if ($nodeName == 'input' && ($element->getAttribute('type') != 'submit' && $element->getAttribute('type') != 'button' || $element->getAttribute('value') == $name) && ($element->getAttribute('type') != 'image' || $element->getAttribute('alt') == $name)) { $value = $element->getAttribute('value'); } else { if ($nodeName == 'textarea') { $value = ''; foreach ($element->childNodes as $el) { $value .= $dom->saveXML($el); } } else { if ($nodeName == 'select') { if ($multiple = $element->hasAttribute('multiple')) { $elementName = str_replace('[]', '', $elementName); $value = array(); } else { $value = null; } $found = false; foreach ($xpath->query('descendant::option', $element) as $option) { if ($option->getAttribute('selected')) { $found = true; if ($multiple) { $value[] = $option->getAttribute('value'); } else { $value = $option->getAttribute('value'); } } } // if no option is selected and if it is a simple select box, take the first option as the value if (!$found && !$multiple) { $value = $xpath->query('descendant::option', $element)->item(0)->getAttribute('value'); } } } } } } if (null !== $value) { $this->parseArgumentAsArray($elementName, $value, $defaults); } } // create request parameters $arguments = sfToolkit::arrayDeepMerge($defaults, $arguments); if ('post' == $method) { return $this->post($url, $arguments); } else { $query_string = http_build_query($arguments, null, '&'); $sep = false === strpos($url, '?') ? '?' : '&'; return $this->get($url . ($query_string ? $sep . $query_string : '')); } }
/** * Returns true if a request parameter exists. * * This is a proxy method equivalent to: * * <code>$this->getRequest()->getParameterHolder()->has($name)</code> * * @param string $name The parameter name * @return boolean true if the request parameter exists, false otherwise */ public function hasRequestParameter($name) { return $this->requestParameterHolder->has($name); }
$t->ok($doc->getDocument()->getField('title')->isStored, 'field type "Keyword" is stored'); $t->ok($doc->getDocument()->getField('title')->isIndexed, 'field type "Keyword" is indexed'); $t->ok($doc->getDocument()->getField('title')->isTokenized, 'field type "Keyword" is tokenized'); $t->ok(!$doc->getDocument()->getField('title')->isBinary, 'field type "Keyword" is not binary'); $indexer->delete(); $t->diag('testing ->insert(), document fields'); $model->setTitle('foobar!'); try { $indexer->insert(); $lucene->commit(); $doc = getDoc($lucene, $indexer->getModelGuid()); $t->is($doc->title, 'foobar!', '->insert() handles strings from field getters'); } catch (Exception $e) { $t->fail('->insert() handles strings from field getters'); } $ph = new sfParameterHolder(); $ph->add(array('type' => 'text', 'boost' => 1)); $h->get('fields')->set('nonScalar', $ph); try { $indexer->insert(); $t->fail('->insert() fails if field getter does not return a scalar'); } catch (Exception $e) { $t->pass('->insert() fails if field getter does not return a scalar'); } $indexer->delete(); $h->get('fields')->remove('nonScalar'); $h->get('fields')->set('stringable_object', $ph); try { $indexer->insert(); $lucene->commit(); $doc = getDoc($lucene, $indexer->getModelGuid());
public function __construct($colName, $columnDescription = array(), $translatePropel = false) { // sometimes we get null if the yml line is empty if ($columnDescription == null) { $columnDescription = array(); } // for the short syntax type(size) if (is_string($columnDescription)) { $columnDescription = array('type' => $columnDescription); } $this->setName($colName); $columnInfo = new sfParameterHolder(); $columnInfo->add($columnDescription); if ($translatePropel) { // we translate the propel types to doctrine ones $propelType = strtolower($columnInfo->get('type')); if (array_key_exists($propelType, self::$propel2docDictionary['types'])) { $columnInfo->set('type', self::$propel2docDictionary['types'][$propelType]); } else { $columnInfo->set('type', $propelType); } // we store it in lowercase // if there is a default propel size we set it if (!$columnInfo->get('size')) { if (isset(self::$defaultPropelSize[$propelType])) { $columnInfo->set('size', self::$defaultPropelSize[$propelType]); } } // we translate the constraints foreach ($columnInfo->getAll() as $key => $value) { if (array_key_exists($key, self::$propel2docDictionary['constraints'])) { $columnInfo->set(self::$propel2docDictionary['constraints'][$key], $columnInfo->get($key)); } } } // we store the raw description, only used in setUpForeignRelation $this->columnInfo = $columnInfo; // name $this->setProperty('name', $colName); $this->setProperty('columnName', $columnInfo->get('columnName')); // type if (!($type = $columnInfo->get('type'))) { // we try to figure out the type // FIXME: write a method to detect relations? if ($columnInfo->get('foreignClass') || $columnInfo->get('foreignTable')) { $type = 'integer'; } else { $type = 'string'; } // default type } elseif (is_string($type)) { preg_match('/([^\\(\\s]+)\\s*\\([\\s]*([\\d]+)[\\s]*\\)/', $type, $matches); if (!empty($matches)) { $type = $matches[1]; $columnInfo->set('size', $matches[2]); } } $this->setProperty('type', $type); // size if (!($size = $columnInfo->get('size'))) { if (is_string($type)) { if (isset(self::$defaultDoctrineSize[$type])) { $size = self::$defaultDoctrineSize[$type]; } // we have a default size for this type } } if (!$size) { $size = 'null'; } $this->setProperty('size', $size); // constraints if ($constraints = array_intersect_key($columnDescription, array_flip(self::$allowedConstraints))) { $this->properties = array_merge($this->properties, $constraints); } }
// ->setByRef() $t->diag('->setByRef()'); $foo = 'bar'; $ph = new sfParameterHolder(); $ph->setByRef('foo', $foo); $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key'); $foo = 'foo'; $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key as a reference'); // ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok($ph == unserialize(serialize($ph)), 'sfParameterHolder implements the Serializable interface');
public function has($name) { return parent::has($name) || $this->proxy_has($name); }
/** * Save information from the last flashcard review session in the database. * Allows to see the last review session results on subsequent GET request, * and until the user starts another review session. * * The data could also be used in the active member statistics, .. * * @param object $params */ protected function saveReviewSessionInfo(sfParameterHolder $params) { $data = array('ts_start' => $params->get('ts_start'), 'fc_pass' => $params->get('fc_pass'), 'fc_fail' => $params->get('fc_fail')); ActiveMembersPeer::saveReviewSummaryInfo($this->getUser()->getUserId(), $data); }
/** * Loads the config for the search engine. */ protected function initialize() { $config = self::getConfig(); $holder = $this->getParameterHolder(); if (!isset($config[$holder->get('name')])) { throw new sfLuceneException('The name of this index is invalid.'); } $config = $config[$holder->get('name')]; foreach (array('encoding', 'cultures' => 'enabled_cultures', 'stop_words', 'short_words', 'analyzer', 'case_sensitive', 'mb_string') as $key => $param) { if (is_int($key)) { $holder->set($param, $config['index'][$param]); } else { $holder->set($param, $config['index'][$key]); } } $models = new sfParameterHolder(); foreach ($config['models'] as $name => $model) { $fields = new sfParameterHolder(); foreach ($model['fields'] as $field => $fieldProperties) { $fieldsData = new sfParameterHolder(); $fieldsData->add($fieldProperties); $fields->set($field, $fieldsData); } $data = new sfParameterHolder(); $data->set('fields', $fields); $data->set('partial', $model['partial']); $data->set('indexer', $model['indexer']); $data->set('title', $model['title']); $data->set('description', $model['description']); $data->set('peer', $model['peer']); $data->set('rebuild_limit', $model['rebuild_limit']); $data->set('validator', $model['validator']); $data->set('categories', $model['categories']); $data->set('route', $model['route']); $models->set($name, $data); } $holder->set('models', $models); $factories = new sfParameterHolder(); $factories->add($config['factories']); $holder->set('factories', $factories); if (!in_array($holder->get('culture'), $holder->get('enabled_cultures'))) { throw new sfLuceneException(sprintf('Culture "%s" is not enabled.', $holder->get('culture'))); } }
/** * Returns a parameter holder as an array. * * @param sfParameterHolder $parameterHolder A sfParameterHolder instance * @param boolean $removeObjects when set to true, objects are removed. default is false for BC. * * @return array The parameter holder as an array */ public static function flattenParameterHolder($parameterHolder, $removeObjects = false) { $values = array(); if ($parameterHolder instanceof sfNamespacedParameterHolder) { foreach ($parameterHolder->getNamespaces() as $ns) { $values[$ns] = array(); foreach ($parameterHolder->getAll($ns) as $key => $value) { $values[$ns][$key] = $value; } ksort($values[$ns]); } } else { foreach ($parameterHolder->getAll() as $key => $value) { $values[$key] = $value; } } if ($removeObjects) { $values = self::removeObjects($values); } ksort($values); return $values; }
$ph->setByRef('foo', $foo); $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key'); $foo = 'foo'; $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key as a reference'); $myfoo = 'bar'; $ph->setByRef('myfoo', $myfoo, 'symfony/mynamespace'); $t->is($ph->get('myfoo', null, 'symfony/mynamespace'), $myfoo, '->setByRef() takes a namespace as its third parameter'); // ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $ph->add($myparameters, 'symfony/mynamespace'); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $t->is($ph->getAll('symfony/mynamespace'), $myparameters, '->add() takes a namespace as its second argument'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $ph->addByRef($myparameters, 'symfony/mynamespace'); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $t->is($myparameters, $ph->getAll('symfony/mynamespace'), '->add() takes a namespace as its second argument'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters');