public function configure() { $object = $this->getObject(); $this->useFields(array('egreso', 'complicaciones', 'riesgoqx_id', 'contaminacionqx_id', 'eventoqx_id', 'clasificacionqx', 'destino_px', 'status', 'ev_adversos_anestesia')); //$this->widgetSchema['paciente_id'] = new sfWidgetFormInputHidden(); $this->widgetSchema['egreso'] = new sfWidgetFormInputText(); $this->widgetSchema['complicaciones'] = new sfWidgetFormTextarea(); $this->widgetSchema['status'] = new sfWidgetFormInputHidden(); $this->widgetSchema['status']->setAttribute('value', '100'); $this->setWidget('destino_px', new sfWidgetFormChoice(array('choices' => array('Recuperación', 'Intensivos', 'Sala', 'Defunción'), 'expanded' => true))); $this->setWidget('clasificacionqx', new sfWidgetFormChoice(array('choices' => array(null, 'Mayor', 'Menor'), 'expanded' => false))); $this->widgetSchema->setLabels(AgendaPeer::getLabels()); /* Ajustes a los validadores */ $this->validatorSchema['egreso']->setOption('required', true); $this->validatorSchema['egreso']->setMessage('required', 'Falta hora'); // Agregando las personas del transoperatorio $this->widgetSchema['egreso']->setAttributes(array('id' => 'datahora')); $transPersonal = $object->getPersonalTransoperatorio(); $tmp = new sfForm(); if ($transPersonal != null) { foreach ($transPersonal as $personal) { if ($personal->getPersonalNombre()) { $x = new PersonalcirugiaForm($personal); $x->useFields(array('finaliza', 'personal_nombre')); $tmp->embedForm('personal' . $personal->getId(), $x); } } $this->embedForm('temporal', $tmp); } $this->validatorSchema['clasificacionqx']->setOption('required', true); $this->validatorSchema['clasificacionqx']->setMessage('required', 'Falta clasificación de la cirugía'); }
/** * AJAX action to add new invoice items * @param sfWebRequest $request * @return unknown_type */ public function executeAjaxAddInvoiceItem(sfWebRequest $request) { $index = 'new_item_invoice_' . time(); $item = new Item(); $item->common_id = $request->getParameter('invoice_id'); $form = new sfForm(); $form->getWidgetSchema()->setNameFormat('invoice[%s]'); $form->embedForm('Items', new FormsContainer(array($index => new ItemForm($item)), 'ItemForm')); $params = array('invoiceItemForm' => $form['Items'][$index], 'item' => $item, 'isNew' => true, 'rowId' => $index); return $this->renderPartial('invoiceRow', $params); }
public function configure() { $wrapperForm = new sfForm(); foreach ($this->courseParticipant->ParticipantLessons as $lesson) { //$wrapperForm->embedForm($todo->getId(), new TodoForm($todo)); $wrapperForm->embedForm($lesson->getLesson()->getDate(), new embeddedLessonParticipantForm($lesson)); } $this->embedForm('participantLessons', $wrapperForm); $this->widgetSchema->setNameFormat('participant_course_abseces[%s]'); }
public function configure() { $subForm = new sfForm(); foreach ($this->options['collection'] as $index => $record) { if ($this->options['level'] == Users::REGISTERED_USER && $record->getCollections() == ',' && $record->getAllPublic() === false) { } else { $form = new MyWidgetsForm($record, array('level' => $this->options['level'])); $subForm->embedForm($index, $form); } } $this->embedForm('MyWidgets', $subForm); $this->widgetSchema->setNameFormat('user_widget[%s]'); }
public function configure() { $q = Doctrine_Core::getTable('ScssScout')->createQuery('s')->leftJoin('s.Patrol p')->where('p.troop_id = ?', sfContext::getInstance()->getUser()->getProfile()->getActiveEnrollment()->getTroop()->getId())->orderBy('s.last_name, s.first_name ASC'); $this->widgetSchema['scout_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'ScssScout', 'query' => $q)); $scout = new ScssScout(); $sForm = new sfForm(); $pMax = sfContext::getInstance()->getUser()->getProfile()->getActiveEnrollment()->getWeek()->getPeriods(); foreach ($pMax as $i => $period) { $enroll = new ScssScoutEnrollment(); $enroll->Scout = $scout; $form = new ScssScoutEnrollmentForm($enroll, array('period' => $period)); $sForm->embedForm($i, $form); } $this->embedForm('ClassesByPeriod', $sForm); }
public function configure() { $subForm = new sfForm(); if (isset($this->options['no_load'])) { $keywords = array(); } else { $keywords = Doctrine::getTable('ClassificationKeywords')->findForTable($this->options['table'], $this->options['id']); } foreach ($keywords as $index => $childObject) { $form = new ClassificationKeywordsForm($childObject); $subForm->embedForm($index, $form); } $this->embedForm('ClassificationKeywords', $subForm); $subForm2 = new sfForm(); $this->embedForm('newKeywords', $subForm2); $this->widgetSchema->setNameFormat('keywords[%s]'); }
public function configure() { $num_votos = 5; unset($this['created_at'], $this['updated_at'], $this['parlamentario_list']); if (sfContext::getInstance()->getRouting()->getCurrentRouteName() == 'votacion_comision_edit') { $this->embedRelation('VotacionComisionParlamentario AS Voto'); } else { $subForm = new sfForm(); for ($i = 0; $i < $num_votos; $i++) { $VotacionParlamentario = new VotacionComisionParlamentario(); $VotacionParlamentario->VotacionComision = $this->getObject(); $form = new VotacionComisionParlamentarioForm($VotacionParlamentario); $subForm->embedForm($i, $form); } $this->embedForm('Voto', $subForm); } }
public function configure() { $subForm = new sfForm(); if (isset($this->options['no_load'])) { $names = array(); } else { $names = Doctrine::getTable('VernacularNames')->findForTable($this->options['table'], $this->options['id']); } foreach ($names as $index => $childObject) { $form = new VernacularNamesForm($childObject); $subForm->embedForm($index, $form); } $this->embedForm('VernacularNames', $subForm); $subForm2 = new sfForm(); $this->embedForm('newVal', $subForm2); $this->widgetSchema->setNameFormat('grouped_vernacular[%s]'); }
public function configure() { $subForm = new sfForm(); if (isset($this->options['no_load'])) { $items = array(); } else { $items = Doctrine::getTable('LoanItems')->findForLoan($this->options['loan']->getId()); } foreach ($items as $index => $childObject) { $form = new LoanItemsForm($childObject); $subForm->embedForm($index, $form); } $this->embedForm('LoanItems', $subForm); $subForm2 = new sfForm(); $this->embedForm('newLoanItems', $subForm2); $this->widgetSchema->setNameFormat('loan_overview[%s]'); }
public function configure() { $subForm = new sfForm(); $collections = Doctrine::getTable('Collections')->fetchByCollectionParent($this->options['current_user'], $this->options['user_ref'], $this->options['collection_ref']); foreach ($collections as $record) { if (count($record->CollectionsRights)) { $right = $record->CollectionsRights[0]; } else { $right = new CollectionsRights(); $right->setCollectionRef($record->getId()); $right->setDbUserType(0); $right->setUserRef($this->options['user_ref']); } $form = new SubCollectionsRightsForm($right, array('collection' => $record)); $subForm->embedForm($record->getId(), $form); } $this->embedForm('collections', $subForm); $this->widgetSchema->setNameFormat('sub_collection[%s]'); }
protected function embedDetalles() { $detalles_forms = new sfForm(); if (false === sfContext::getInstance()->getRequest()->isXmlHttpRequest()) { $detalles_solicitudes = $this->getObject()->getDetalleSolicitud(); if (count($detalles_solicitudes) == 0) { for ($i = 0; $i < 1; $i++) { $detalle_solicitud = new detalle_solicitud(); $detalle_solicitud->solicitud_id = $this->getObject(); $detalles_solicitudes[] = $detalle_solicitud; } } foreach ($detalles_solicitudes as $key => $v) { $detalle_solicitud_form = new detalle_solicitudForm($v); $detalles_forms->embedForm('Articulo ' . ($key + 1), $detalle_solicitud_form); $detalles_forms->widgetSchema['Articulo ' . ($key + 1)]->setLabel('Artículo ' . ($key + 1)); } } $this->embedForm('Articulos', $detalles_forms); $this->widgetSchema['Articulos']->setLabel('Artículos Solicitados'); }
public function configure() { $this->useFields(array('version', 'summary', 'stability', 'api_versions_list')); if ($plugin = $this->getOption('plugin')) { $this->widgetSchema['plugin_id'] = new sfWidgetFormInputHidden(); $this->setDefault('plugin_id', $plugin->id); } $this->setDefault('date', date('Y-m-d H:i:s')); $this->validatorSchema['version'] = new sfValidatorVersion(); $apiVersions = Doctrine::getTable('SymfonyApiVersion')->findAll(); $choices = $apiVersions->toKeyValueArray('id', 'name'); $this->mergeWidgets(array('date' => new sfWidgetFormInputHidden(), 'api_versions_list' => new sfWidgetFormChoice(array('choices' => $choices, 'multiple' => true, 'expanded' => true)))); // Embed Dependencies $dependencyForm = new sfForm(); foreach ($this->object['Dependencies'] as $i => $dependency) { $dependencyForm->embedForm('dependency_' . $i, new PluginReleaseDependencyForm($dependency)); } $this->embedForm('dependencies', $dependencyForm); // Set Labels $this->widgetSchema->setLabels(array('api_versions_list' => 'Api Versions')); }
$t->fail('renderUsing() throws an exception if formatter name does not exist'); } catch (InvalidArgumentException $e) { $t->pass('renderUsing() throws an exception if formatter name does not exist'); } // renderHiddenFields() $t->diag('->renderHiddenFields()'); $f = new sfForm(); $f->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText(), 'is_admin' => new sfWidgetFormInputHidden())); $output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />'; $t->is($f->renderHiddenFields(), $output, 'renderHiddenFields() renders all hidden fields, no visible fields'); $t->is(count($f->getFormFieldSchema()), 3, 'renderHiddenFields() does not modify the form fields'); $author = new sfForm(); $author->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText())); $company = new sfForm(); $company->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText())); $author->embedForm('company', $company); $output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="company[id]" id="company_id" />'; $t->is($author->renderHiddenFields(), $output, 'renderHiddenFields() renders hidden fields from embedded forms'); $output = '<input type="hidden" name="id" id="id" />'; $t->is($author->renderHiddenFields(false), $output, 'renderHiddenFields() does not render hidden fields from embedded forms if the first parameter is "false"'); // ->embedForm() $t->diag('->embedForm()'); $author = new FormTest(array('first_name' => 'Fabien')); $author->setWidgetSchema($author_widget_schema = new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText()))); $author->setValidatorSchema($author_validator_schema = new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2))))); $company = new FormTest(); $company->setWidgetSchema($company_widget_schema = new sfWidgetFormSchema(array('name' => new sfWidgetFormInputText()))); $company->setValidatorSchema($company_validator_schema = new sfValidatorSchema(array('name' => new sfValidatorString(array('min_length' => 2))))); $article = new FormTest(); $article->setWidgetSchema($article_widget_schema = new sfWidgetFormSchema(array('title' => new sfWidgetFormInputText()))); $article->setValidatorSchema($article_validator_schema = new sfValidatorSchema(array('title' => new sfValidatorString(array('min_length' => 2)))));
/** * Embed a Doctrine_Collection relationship in to a form * * [php] * $userForm = new UserForm($user); * $userForm->embedRelation('Groups AS groups'); * * @param string $relationName The name of the relation and an optional alias * @param string $formClass The name of the form class to use * @param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front) * @param string $innerDecorator A HTML decorator for each embedded form * @param string $decorator A HTML decorator for the main embedded form * * @throws InvalidArgumentException If the relationship is not a collection */ public function embedRelation($relationName, $formClass = null, $formArgs = array(), $innerDecorator = null, $decorator = null) { if (false !== ($pos = stripos($relationName, ' as '))) { $fieldName = substr($relationName, $pos + 4); $relationName = substr($relationName, 0, $pos); } else { $fieldName = $relationName; } $relation = $this->getObject()->getTable()->getRelation($relationName); $r = new ReflectionClass(null === $formClass ? $relation->getClass() . 'Form' : $formClass); if (Doctrine_Relation::ONE == $relation->getType()) { $this->embedForm($fieldName, $r->newInstanceArgs(array_merge(array($this->getObject()->{$relationName}), $formArgs)), $decorator); } else { $subForm = new sfForm(); foreach ($this->getObject()->{$relationName} as $index => $childObject) { $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs)); $subForm->embedForm($index, $form, $innerDecorator); $subForm->getWidgetSchema()->setLabel($index, (string) $childObject); } $this->embedForm($fieldName, $subForm, $decorator); } }
/** * Embed a Doctrine_Collection relationship in to a form * * [php] * $userForm = new UserForm($user); * $userForm->embedRelation('Groups'); * * @param string $relationName The name of the relation * @param string $formClass The name of the form class to use * @param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front) * * @throws InvalidArgumentException If the relationship is not a collection */ public function embedRelation($relationName, $formClass = null, $formArgs = array()) { // FIXME: Where exactly is getTable() declared? // It triggers __call() which retrieves a property called $table, // which doesn't seem to be declared anywhere so it triggers __get() // which then again tries to call getTable() (if it exists) or // returns $this->table, which eventually doesn't exists? // I don't think this is works throw new sfException('Not implemented'); $relation = $this->object->getTable()->getRelation($relationName); if ($relation->getType() !== Doctrine_Relation::MANY) { throw new InvalidArgumentException('You can only embed a relationship that is a collection.'); } $r = new ReflectionClass(null === $formClass ? $relation->getClass() . 'Form' : $formClass); $subForm = new sfForm(); foreach ($this->object[$relationName] as $index => $childObject) { $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs)); $subForm->embedForm($index, $form); $subForm->getWidgetSchema()->setLabel($index, (string) $childObject); } $this->embedForm($relationName, $subForm); }
public function addInitialRows($numberOfRows) { $timesheetRows = new sfForm(); $count = 0; for ($i = 0; $i <= $numberOfRows; $i++) { $rowForm = new TimesheetForm(); $timesheetRows->embedForm($count, $rowForm); $count++; } $this->embedForm('initialRows', $timesheetRows); }
} catch (LogicException $e) { $t->pass('"sfForm" Trying to set a validator for an embedded form field throws a LogicException'); } // tests for ticket #4754 $f1 = new TestForm1(); $f2 = new TestForm2(); $f1->embedForm('f2', $f2); $t->is($f1['f2']['c']->render(), '<textarea rows="4" cols="30" name="f2[c]" id="f2_c"></textarea>', '->embedForm() generates a correct id in embedded form fields'); $t->is($f1['f2']['c']->renderLabel(), '<label for="f2_c">2_c</label>', '->embedForm() generates a correct label id correctly in embedded form fields'); // bind too many values for embedded forms $t->diag('bind too many values for embedded forms'); $list = new FormTest(); $list->setWidgets(array('title' => new sfWidgetFormInputText())); $list->setValidators(array('title' => new sfValidatorString())); $containerForm = new sfForm(); $containerForm->embedForm('0', clone $list); $containerForm->embedForm('1', clone $list); $list->embedForm('items', $containerForm); $list->bind(array('title' => 'list title', 'items' => array(array('title' => 'item 1'), array('title' => 'item 2'), array('title' => 'extra item')))); $t->isa_ok($list['items'][0]->getError(), 'sfValidatorErrorSchema', '"sfFormFieldSchema" is given an error schema when an extra embedded form is bound'); // does this trigger a fatal error? $list['items']->render(); $t->pass('"sfFormFieldSchema" renders when an extra embedded form is bound'); // ->getEmbeddedForms() $t->diag('->getEmbeddedForms()'); $article = new FormTest(); $company = new FormTest(); $author = new FormTest(); $article->embedForm('company', $company); $article->embedForm('author', $author); $forms = $article->getEmbeddedForms();
/** * Embed a Doctrine_Collection relationship in to a form * * [php] * $userForm = new UserForm($user); * $userForm->embedRelation('Groups'); * * @param string $relationName The name of the relation * @param string $formClass The name of the form class to use * @param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front) * * @throws InvalidArgumentException If the relationship is not a collection */ public function embedRelation($relationName, $formClass = null, $formArgs = array()) { $relation = $this->getObject()->getTable()->getRelation($relationName); if ($relation->getType() !== Doctrine_Relation::MANY) { throw new InvalidArgumentException('You can only embed a relationship that is a collection.'); } $r = new ReflectionClass(null === $formClass ? $relation->getClass() . 'Form' : $formClass); $subForm = new sfForm(); foreach ($this->getObject()->{$relationName} as $index => $childObject) { $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs)); $subForm->embedForm($index, $form); $subForm->getWidgetSchema()->setLabel($index, (string) $childObject); } $this->embedForm($relationName, $subForm); }
public function embedRelations(array $relations) { $this->embedRelations = $relations; $this->getEventDispatcher()->connect('form.post_configure', array($this, 'listenToFormPostConfigureEvent')); foreach ($relations as $relationName => $relationSettings) { $relationSettings = $this->addDefaultRelationSettings($relationSettings); $relation = $this->getObject()->getTable()->getRelation($relationName); if (!$relationSettings['noNewForm']) { $containerName = 'new_' . $relationName; $formLabel = $relationSettings['newFormLabel']; if (!$relation->isOneToOne()) { if ($relationSettings['multipleNewForms']) { $newFormsCount = $relationSettings['newFormsInitialCount']; $subForm = $this->newFormsContainerFormFactory($relationSettings, $containerName); for ($i = 0; $i < $newFormsCount; $i++) { // we need to create new forms with cloned object inside (otherwise only the last new values would be saved) $newForm = $this->embeddedFormFactory($relationName, $relationSettings, $relation, $i + 1); $subForm->embedForm($i, $newForm); } $subForm->getWidgetSchema()->setLabel($formLabel); $this->embedForm($containerName, $subForm); } else { $newForm = $this->embeddedFormFactory($relationName, $relationSettings, $relation, $formLabel); $this->embedForm($containerName, $newForm); } } elseif ($relation->isOneToOne() && !$this->getObject()->relatedExists($relationName)) { $newForm = $this->embeddedFormFactory($relationName, $relationSettings, $relation, $formLabel); $this->embedForm($containerName, $newForm); } } $formClass = null === $relationSettings['formClass'] ? $relation->getClass() . 'Form' : $relationSettings['formClass']; $formArgs = null === $relationSettings['formClassArgs'] ? array() : $relationSettings['formClassArgs']; if (isset($formArgs[0]) && !array_key_exists('ah_add_delete_checkbox', $formArgs[0]) || !isset($formArgs[0])) { $formArgs[0]['ah_add_delete_checkbox'] = true; } if ($relation->isOneToOne()) { $form = new $formClass($this->getObject()->{$relationName}, $formArgs[0]); $this->embedForm($relationName, $form); //maybe we need this: if (!$this->getObject()->relatedExists($relationName)) unset($this[$relation->getLocalColumnName()]); } else { $subForm = new sfForm(); foreach ($this->getObject()->{$relationName} as $index => $childObject) { $form = new $formClass($childObject, $formArgs[0]); $subForm->embedForm($index, $form); // check if existing embedded relations should have a different label if (null === $relationSettings['customEmbeddedFormLabelMethod'] || !method_exists($childObject, $relationSettings['customEmbeddedFormLabelMethod'])) { $subForm->getWidgetSchema()->setLabel($index, (string) $childObject); } else { $subForm->getWidgetSchema()->setLabel($index, $childObject->{$relationSettings}['customEmbeddedFormLabelMethod']()); } } $this->embedForm($relationName, $subForm); } if ($relationSettings['formFormatter']) { $this->switchFormatter($relationName, $relationSettings['formFormatter']); } /* * Unset the relation form(s) if: * (1. One-to-many relation and there are no related objects yet (count of embedded forms is 0) OR * 2. One-to-one relation and embedded form is new (no related object yet)) * AND * (3. Option `displayEmptyRelations` was either not set by the user or was set by the user and is false) */ if ((!$relation->isOneToOne() && count($this->getEmbeddedForm($relationName)->getEmbeddedForms()) === 0 || $relation->isOneToOne() && $this->getEmbeddedForm($relationName)->isNew()) && !$relationSettings['displayEmptyRelations']) { unset($this[$relationName]); } if ($relationSettings['newFormAfterExistingRelations'] && isset($this[$relationName]) && isset($this['new_' . $relationName])) { $this->getWidgetSchema()->moveField('new_' . $relationName, sfWidgetFormSchema::AFTER, $relationName); } } $this->getEventDispatcher()->disconnect('form.post_configure', array($this, 'listenToFormPostConfigureEvent')); }
/** * Adds a new NameValueForm into the specified location for a 'generic' settings form. * @param string to Location where to insert the item * Ex: config['taxes'][new_1234567890][<name_or_value>] * |_ 'to' parameter |_ from NameValueForm * @return void * @author Carlos Escribano <*****@*****.**> **/ public function executeAddNewNameValueItem(sfWebRequest $request) { $this->forward404Unless($to = $request->getParameter('to')); $configForm = new sfForm(); $configForm->getWidgetSchema()->setNameFormat('config[%s]'); $index = 'new_' . time(); switch ($to) { case 'taxes': $subform = new FormsContainer(array($index => new TaxForm()), 'TaxForm'); break; case 'seriess': $subform = new FormsContainer(array($index => new SeriesForm()), 'SeriesForm'); break; } $configForm->embedForm($to, $subform); return $this->renderText($configForm[$to][$index]); }