/**
  * 
  * @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);
     }
 }
 public function &get($name, $default = null, $isStripNullbyte = true)
 {
     if ($isStripNullbyte) {
         $value = opToolkit::stripNullByteDeep(parent::get($name, $default));
     } else {
         $value =& parent::get($name, $default);
     }
     return $value;
 }
 public function &get($name, $default = null)
 {
     $val = $this->proxy_get($name);
     if ($val !== NULL) {
         // FALSE errors will return here -- see proxy_get()
         return $val;
     }
     return parent::get($name, $default);
 }
 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);
 }
Beispiel #5
0
 /**
  * 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);
 }
$t->is($ph->remove('nonexistant', 'foobar'), 'foobar', '->remove() takes a default value as its second argument');
$t->is($ph->getAll(), null, '->remove() removes the key from parameters');
// ->set()
$t->diag('->set()');
$foo = 'bar';
$ph = new sfParameterHolder();
$ph->set('foo', $foo);
$t->is($ph->get('foo'), $foo, '->set() sets the value for a key');
$foo = 'foo';
$t->is($ph->get('foo'), 'bar', '->set() sets the value for a key, not a reference');
// ->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';
// ->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');
Beispiel #8
0
 /**
  * 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 the value of a request parameter.
  *
  * This is a proxy method equivalent to:
  *
  * <code>$this->getRequest()->getParameterHolder()->get($name)</code>
  *
  * @param  string $name The parameter name
  *
  * @param string    $default
  *
  * @return string The request parameter value
  */
 public function getRequestParameter($name, $default = null)
 {
     return $this->requestParameterHolder->get($name, $default);
 }
 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);
     }
 }
// ->set()
$t->diag('->set()');
$foo = 'bar';
$ph = new sfParameterHolder();
$ph->set('foo', $foo);
$t->is($ph->get('foo'), $foo, '->set() sets the value for a key');
$foo = 'foo';
$t->is($ph->get('foo'), 'bar', '->set() sets the value for a key, not a reference');
$ph->set('myfoo', 'bar', 'symfony/mynamespace');
$t->is($ph->get('myfoo', null, 'symfony/mynamespace'), 'bar', '->set() takes a namespace as its third parameter');
// ->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');
$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');