public function testCanCreateElements() { $element = $this->factory->createElement(array('name' => 'foo', 'attributes' => array('type' => 'text', 'class' => 'foo-class', 'data-js-type' => 'my.form.text'))); $this->assertInstanceOf('Zend\\Form\\ElementInterface', $element); $this->assertEquals('foo', $element->getName()); $this->assertEquals('text', $element->getAttribute('type')); $this->assertEquals('foo-class', $element->getAttribute('class')); $this->assertEquals('my.form.text', $element->getAttribute('data-js-type')); }
public function testCreatingCaptchaElementViaFormFactoryWillCreateCaptcha() { $factory = new Factory(); $element = $factory->createElement(array('type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'foo', 'options' => array('captcha' => array('class' => 'dumb', 'options' => array('sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer'))))); $this->assertInstanceOf('Zend\\Form\\Element\\Captcha', $element); $captcha = $element->getCaptcha(); $this->assertInstanceOf('Zend\\Captcha\\Dumb', $captcha); }
public function searchAction() { $elementName = $this->params()->fromRoute('element'); $elementName = str_replace('-', '\\', $elementName); $term = $this->params()->fromQuery('term', ''); $factory = new Factory(); $element = $factory->createElement(array('type' => $elementName, 'options' => array('sm' => $this->getServiceLocator()))); $options = $element->getOptions(); $this->setOm($options['object_manager']); $proxy = $element->getProxy(); $this->setProxy($proxy); $this->setOptions($options); $qb = $proxy->getObjectManager()->getRepository($proxy->getTargetClass())->createQueryBuilder('q'); $driver = ''; if (class_exists("\\Doctrine\\ORM\\QueryBuilder") && $qb instanceof \Doctrine\ORM\QueryBuilder) { /* @var $qb \Doctrine\ORM\QueryBuilder */ $qb->setMaxResults(20); $driver = 'orm'; } elseif (class_exists("\\Doctrine\\ODM\\MongoDB\\Query\\Builder") && $qb instanceof \Doctrine\ODM\MongoDB\Query\Builder) { /* @var $qb \Doctrine\ODM\MongoDB\Query\Builder */ $qb->limit(20); $driver = 'odm'; } else { throw new \Exception('Can\'t find ORM or ODM doctrine driver'); } foreach ($options['searchFields'] as $field) { if ($driver == 'orm') { $qb->orWhere($qb->expr()->like('q.' . $field, $qb->expr()->literal("%{$term}%"))); } elseif ($driver == 'odm') { $qb->addOr($qb->expr()->field($field)->equals(new \MongoRegex("/{$term}/i"))); } } if ($options['orderBy']) { if ($driver == 'orm') { $qb->orderBy('q.' . $options['orderBy'][0], $options['orderBy'][1]); } elseif ($driver == 'odm') { $qb->sort($options['orderBy'][0], $options['orderBy'][1]); } } $this->setObjects($qb->getQuery()->execute()); $valueOptions = $this->getValueOptions(); $view = new JsonModel($valueOptions); return $view; }
public function __construct($name = null) { parent::__construct($name); $this->add(array('name' => 'cedula', 'options' => array('label' => 'Cedula'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'nombres', 'options' => array('label' => 'Nombre'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'apellidos', 'options' => array('label' => 'Apellidos'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'codigo', 'options' => array('label' => 'Codigo'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'facultad', 'options' => array('label' => 'Facultad'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $radio = new Element\Radio('facultad'); $radio->setLabel('Facultad'); $this->add($radio); $radio = new Element\Radio('unidadacademica'); $radio->setLabel('Unidad Academica'); $this->add($radio); $this->add(array('name' => 'semestre', 'options' => array('label' => 'Semestre del Año'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'formacion', 'options' => array('label' => 'Formacion'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'direccion', 'options' => array('label' => 'Direccion'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $this->add(array('name' => 'telefono', 'options' => array('label' => 'Telefono'), 'attributes' => array('type' => 'text', 'class' => 'input'))); $factory = new Factory(); $correo = $factory->createElement(array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'correo', 'options' => array('label' => 'Correo'), 'attributes' => array('class' => 'input'))); $this->add($correo); //boton $this->add(array('name' => 'send', 'attributes' => array('type' => 'submit', 'value' => 'Guardar', 'title' => 'Guardar'))); }