protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $notice = $form->getObject()->isNew() ? 'Категория создана успешно.' : 'Категория изменена успешно.'; $Category = $form->save(); foreach ((array) $request->getParameter('category_preference') as $key => $value) { if (isset($value['id']) and $value['id'] != 0) { $category_preference = CategoryPreferencePeer::retrieveByPk(intval($value['id'])); } else { $category_preference = new CategoryPreference(); $category_preference->setCategoryId($form->getObject()->getId()); } if (isset($value['delete'])) { $category_preference->delete(); } elseif ($value['name'] != '') { $category_preference->setKey($value['name']); $category_preference->setPreferenceType($value['preference_type']); $category_preference->setPreferenceUnit($value['preference_unit']); $category_preference->setFilterStatus(isset($value['filter_status']) ? $value['filter_status'] : 0); $category_preference->save(); } } $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Category))); if ($request->hasParameter('_save_and_add')) { $this->getUser()->setFlash('notice', $notice . ' Вы можете создать еще одну.'); $this->redirect('@category_new'); } else { $this->getUser()->setFlash('notice', $notice); $this->redirect(array('sf_route' => 'category_edit', 'sf_subject' => $Category)); } } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCategoryPreference !== null) { if ($this->aCategoryPreference->isModified() || $this->aCategoryPreference->isNew()) { $affectedRows += $this->aCategoryPreference->save($con); } $this->setCategoryPreference($this->aCategoryPreference); } if ($this->aElement !== null) { if ($this->aElement->isModified() || $this->aElement->isNew()) { $affectedRows += $this->aElement->save($con); } $this->setElement($this->aElement); } if ($this->isNew()) { $this->modifiedColumns[] = PreferencePeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = PreferencePeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += PreferencePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.'; $Category = $form->save(); foreach ((array) $request->getParameter('category_preference') as $key => $value) { if (isset($value['id'])) { $category_preference = CategoryPreferencePeer::retrieveByPk(intval($value['id'])); } else { $category_preference = new CategoryPreference(); $category_preference->setCategoryId($form->getObject()->getId()); } if (isset($value['delete'])) { $category_preference->delete(); } elseif ($value['name'] != '') { $category_preference->setKey($value['name']); $category_preference->setFilterStatus(isset($value['filter_status']) ? $value['filter_status'] : 0); $category_preference->save(); } } $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Category))); if ($request->hasParameter('_save_and_add')) { $this->getUser()->setFlash('notice', $notice . ' You can add another one below.'); $this->redirect('@category_new'); } else { $this->getUser()->setFlash('notice', $notice); $this->redirect(array('sf_route' => 'category_edit', 'sf_subject' => $Category)); } } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }