예제 #1
0
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $trimmedValues = array();
     foreach ($taintedValues as $key => $value) {
         $trimmedValues[$key] = is_string($value) ? trim($value) : $value;
     }
     parent::bind($trimmedValues, $taintedFiles);
 }
 public function setup()
 {
     parent::setup();
     $this->useFields();
     $options = array('file_src' => '', 'is_image' => true, 'with_delete' => true, 'delete_label' => sfContext::getInstance()->getI18N()->__('remove the current photo'), 'label' => false, 'edit_mode' => !$this->isNew());
     $key = 'photo';
     if (!$this->isNew()) {
         sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
         $options['template'] = get_partial('communityTopic/formEditImage', array('image' => $this->getObject()));
         $this->setValidator($key . '_delete', new sfValidatorBoolean(array('required' => false)));
     }
     $this->setWidget($key, new sfWidgetFormInputFileEditable($options, array('size' => 40)));
     $this->setValidator($key, new opValidatorImageFile(array('required' => false)));
 }
 /**
  * Override sfFormDoctrine to prepare the
  * values: FORMNAME|FIELDNAME has to be transformed
  * to FORMNAME[FIELDNAME]
  */
 public function updateObject($values = null)
 {
     if (is_null($values)) {
         $values = $this->values;
         foreach ($this->embeddedForms as $name => $form) {
             foreach ($form as $field => $f) {
                 if (isset($values["{$name}|{$field}"])) {
                     // Re-rename the form field and remove
                     // the original field
                     $values[$name][$field] = $values["{$name}|{$field}"];
                     unset($values["{$name}|{$field}"]);
                 }
             }
         }
     }
     // Give the request to the original method
     parent::updateObject($values);
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $this->cleanEmbedded($taintedValues, $taintedFiles);
     parent::bind($taintedValues, $taintedFiles);
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $ret = parent::bind($taintedValues, $taintedFiles);
     foreach ($this->embeddedForms as $name => $form) {
         $this->embeddedForms[$name]->isBound = true;
         if (isset($this->values[$name])) {
             $this->embeddedForms[$name]->values = $this->values[$name];
         }
     }
     return $ret;
 }
예제 #6
0
 public function embedForm($name, sfForm $form, $decorator = null, $savingTime = self::EMBEDDED_FORM_SAVE_AFTER)
 {
     parent::embedForm($name, $form, $decorator);
     $this->setEmbeddedFormSavingTime($name, $savingTime);
     return $this;
 }
 /**
  * Make array from Doctrine object suitable for supplied form
  *
  * @param  Doctrine_Record $model
  * @param  sfFormDoctrine  $form
  * @return array
  */
 public function extractFormData(Doctrine_Record $model, sfFormDoctrine $form)
 {
     $fields = $form->getWidgetSchema()->getFields();
     $props = $model->toArray();
     return array_intersect_key($props, $fields);
 }
 /**
  * Updates object with provided values, dealing with eventual relation deletion
  *
  * @see sfFormDoctrine::doUpdateObject()
  */
 protected function doUpdateObject($values)
 {
     if (count($this->getScheduledForDeletion()) > 0) {
         foreach ($this->getScheduledForDeletion() as $relationName => $ids) {
             $relation = $this->getObject()->getTable()->getRelation($relationName);
             foreach ($ids as $index => $id) {
                 if ($relation->isOneToOne()) {
                     unset($values[$relationName]);
                 } else {
                     unset($values[$relationName][$index]);
                 }
                 if (!$relation->isOneToOne()) {
                     unset($this->object[$relationName][$index]);
                 } else {
                     $this->object->clearRelated($relationName);
                 }
                 Doctrine::getTable($relation->getClass())->findOneById($id)->delete();
             }
         }
     }
     if (count($this->scheduledForInsertion) > 0) {
         $mainObject = $this->getObject();
         foreach ($this->scheduledForInsertion as $containerName => $newFormList) {
             foreach ($newFormList as $insertionSpec) {
                 $relatedObject = $insertionSpec['form']->getObject();
                 $relation = $insertionSpec['relation'];
                 $relationName = $insertionSpec['relationName'];
                 if ($relation->isOneToOne()) {
                     $mainObject->{$relationName} = $relatedObject;
                 } else {
                     $relatedObjectList = $mainObject->{$relationName};
                     $relatedObjectList[] = $relatedObject;
                 }
                 // $relatedObject->setRelated($relation->getForeignColumnName(), $mainObject);
             }
         }
     }
     parent::doUpdateObject($values);
     // set foreign key here
 }
 /**
  * Updates object with provided values, dealing with eventual relation deletion
  *
  * @see sfFormDoctrine::doUpdateObject()
  */
 protected function doUpdateObject($values)
 {
     if (count($this->getScheduledForDeletion()) > 0) {
         foreach ($this->getScheduledForDeletion() as $relationName => $ids) {
             $relation = $this->getObject()->getTable()->getRelation($relationName);
             foreach ($ids as $index => $id) {
                 if ($relation->isOneToOne()) {
                     unset($values[$relationName]);
                 } else {
                     unset($values[$relationName][$index]);
                 }
                 if (!$relation->isOneToOne()) {
                     unset($this->object[$relationName][$index]);
                 } else {
                     $this->object->clearRelated($relationName);
                 }
                 Doctrine::getTable($relation->getClass())->findOneById($id)->delete();
             }
         }
     }
     parent::doUpdateObject($values);
     // set foreign key here
 }
 protected function handleForm(sfFormDoctrine $form, $uri = null, $action = null, $params = null)
 {
     if ($this->getRequest()->isMethod('post')) {
         $request = $this->getRequest();
         $formname = $form->getName();
         $form->bind($request->getPostParameter($formname), $form->isMultipart() ? $request->getFiles($formname) : null);
         if ($form->isValid()) {
             $form->save();
             if (is_array($action)) {
                 $params = $action;
             }
             if (is_array($params)) {
                 $url = $this->getContext()->getRouting()->generate($uri . (is_string($action) ? '/' . $action : ''), $params, true);
                 $this->redirect($url);
             }
             if (is_string($uri)) {
                 if ($action === null) {
                     $this->redirect($uri);
                 } else {
                     $this->forward($uri, $action);
                 }
             }
         }
     }
 }
 protected function doSave($con = null)
 {
     $this->saveAllManyToMany($con);
     parent::doSave($con);
 }
예제 #12
0
 public function removeFile($field)
 {
     parent::removeFile($field);
     $this->clearCache($field);
 }
예제 #13
0
 /**
  * (non-PHPdoc)
  * @see sfForm::configure()
  * @return dmFormDoctrine
  */
 public function configure()
 {
     $this->embeddedFormsSaveTime = array(self::EMBEDDED_FORM_SAVE_BEFORE => array(), self::EMBEDDED_FORM_SAVE_AFTER => array());
     $this->setupNestedSet();
     return parent::configure() || $this;
 }