public function configure() { /* * Record id */ $this->widgetSchema['recordId'] = new sfWidgetFormDoctrineChoice(array('model' => $this->dmModule->getModel(), 'add_empty' => $this->allowAutoRecordId() ? sprintf('(%s) %s', $this->__('contextual'), $this->getAutoRecord()->__toString()) : false)); $this->widgetSchema['recordId']->setLabel($this->getDmModule()->getName()); $this->validatorSchema['recordId'] = new sfValidatorDoctrineChoice(array('model' => $this->dmModule->getModel(), 'required' => !$this->allowAutoRecordId())); $this->setDefaults($this->getDefaultsFromLastUpdated()); if (!$this->allowAutoRecordId() && !$this->getDefault('recordId')) { $this->setDefault('recordId', dmArray::first(array_keys($this->widgetSchema['recordId']->getChoices()))); } parent::configure(); }
public function configure() { /* * Max per page */ $this->widgetSchema['maxPerPage'] = new sfWidgetFormInputText(array(), array('size' => 3)); $this->validatorSchema['maxPerPage'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 99999)); /* * Paginators top & bottom */ $this->widgetSchema['navTop'] = new sfWidgetFormInputCheckbox(); $this->validatorSchema['navTop'] = new sfValidatorBoolean(); $this->widgetSchema['navBottom'] = new sfWidgetFormInputCheckbox(); $this->validatorSchema['navBottom'] = new sfValidatorBoolean(); /* * Order field selection */ $orderFields = $this->getAvailableOrderFields(); $this->widgetSchema['orderField'] = new sfWidgetFormSelect(array('choices' => $orderFields)); $this->validatorSchema['orderField'] = new sfValidatorChoice(array('choices' => array_keys($orderFields))); /* * Order type selection */ $orderTypes = $this->getOrderTypes(); $this->widgetSchema['orderType'] = new sfWidgetFormSelect(array('choices' => $orderTypes)); $this->validatorSchema['orderType'] = new sfValidatorChoice(array('choices' => array_keys($orderTypes))); /* * Filters */ foreach ($this->dmComponent->getOption('filters', array()) as $filter) { if (!($filterModule = $this->dmModule->getAncestor($filter))) { if (!($filterModule = $this->dmModule->getAssociation($filter))) { $filterModule = $this->dmModule->getLocal($filter); } } if ($filterModule) { $filterName = $filterModule->getKey() . 'Filter'; $this->widgetSchema[$filterName] = new sfWidgetFormDoctrineChoice(array('model' => $filterModule->getModel(), 'add_empty' => $this->allowFilterAutoRecordId($filterModule) ? sprintf('(%s) %s', $this->__('contextual'), $this->getFilterAutoRecord($filterModule)->__toString()) : false)); $this->widgetSchema[$filterName]->setLabel($filterModule->getName()); $this->validatorSchema[$filterName] = new sfValidatorDoctrineChoice(array('model' => $filterModule->getModel(), 'required' => !$this->allowFilterAutoRecordId($filterModule))); $this->widgetSchema[$filterName]->setLabel($this->__($filterModule->getName())); } else { throw new dmException(sprintf('Diem can not find a link between %s and %s modules', $this->dmModule, $filter)); } } $this->setDefaults($this->getDefaultsFromLastUpdated(array('maxPerPage', 'navTop', 'navBottom', 'view', 'orderField', 'orderType'))); parent::configure(); }
public function configure() { // Max per page $this->widgetSchema['maxPerPage'] = new sfWidgetFormInputText(array(), array('size' => 3)); $this->validatorSchema['maxPerPage'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 99999)); // Paginators top & bottom $this->widgetSchema['navTop'] = new sfWidgetFormInputCheckbox(); $this->validatorSchema['navTop'] = new sfValidatorBoolean(); $this->widgetSchema['navBottom'] = new sfWidgetFormInputCheckbox(); $this->validatorSchema['navBottom'] = new sfValidatorBoolean(); // Order field selection $orderFields = $this->getAvailableOrderFields(); $this->widgetSchema['orderField'] = new sfWidgetFormSelect(array('choices' => $orderFields)); $this->validatorSchema['orderField'] = new sfValidatorChoice(array('choices' => array_keys($orderFields))); // Order type selection $orderTypes = $this->getOrderTypes(); $this->widgetSchema['orderType'] = new sfWidgetFormSelect(array('choices' => $orderTypes)); $this->validatorSchema['orderType'] = new sfValidatorChoice(array('choices' => array_keys($orderTypes))); // Filters foreach ($this->dmComponent->getOption('filters', array()) as $filter) { if (!($filterModule = $this->dmModule->getAncestor($filter))) { if (!($filterModule = $this->dmModule->getAssociation($filter))) { $filterModule = $this->dmModule->getLocal($filter); } } if ($filterModule) { $filterName = $filterModule->getKey() . 'Filter'; $this->widgetSchema[$filterName] = new sfWidgetFormDoctrineChoice(array('label' => $this->__($filterModule->getName()), 'model' => $filterModule->getModel(), 'add_empty' => $this->allowFilterAutoRecordId($filterModule) ? sprintf('(%s) %s', $this->__('contextual'), $this->getFilterAutoRecord($filterModule)->__toString()) : false)); $this->validatorSchema[$filterName] = new sfValidatorDoctrineChoice(array('model' => $filterModule->getModel(), 'required' => !$this->allowFilterAutoRecordId($filterModule))); } elseif ($column = $this->dmModule->getTable()->getColumn($filter)) { $filterName = $filter . 'Filter'; if ('boolean' !== $column['type']) { throw new dmException(sprintf('Diem can only filter by module or boolean fields, %s given', $column['type'])); } $this->widgetSchema[$filterName] = new sfWidgetFormInputCheckbox(array('label' => $this->__(dmString::humanize($filter)))); $this->validatorSchema[$filterName] = new sfValidatorBoolean(); } else { throw new dmException(sprintf('Diem can not filter %s by %s', $this->dmModule, $filter)); } } $this->setDefaults($this->getDefaultsFromLastUpdated(array('maxPerPage', 'navTop', 'navBottom', 'view', 'orderField', 'orderType'))); parent::configure(); }