Example #1
0
 /**
  * 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->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->aBook !== null) {
             if ($this->aBook->isModified() || $this->aBook->isNew()) {
                 $affectedRows += $this->aBook->save($con);
             }
             $this->setBook($this->aBook);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ArticlePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ArticlePeer::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 += ArticlePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collAuthorArticles !== null) {
             foreach ($this->collAuthorArticles as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collAttachments !== null) {
             foreach ($this->collAttachments as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Delete category
  *
  * @param void
  * @return null
  */
 function delete_category()
 {
     if ($this->active_category->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->request->isSubmitted()) {
         $delete = $this->active_category->delete();
         if ($delete && !is_error($delete)) {
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_success('Category :category_name has been deleted', array('category_name' => $this->active_category->getName()));
                 $this->redirectToUrl($this->smarty->get_template_vars('categories_url'));
             } else {
                 $this->serveData($this->active_category, 'category');
             }
             // if
         } else {
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_error('Failed to delete :category_name', array('category_name' => $this->active_category->getName()));
                 $this->redirectToUrl($this->smarty->get_template_vars('categories_url'));
             } else {
                 $this->serveData($delete);
             }
             // if
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
Example #3
0
 /**
  * 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 corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Méthode permettant d'enregistrer une catégorie
  * @param $category La catégorie à enregistrer
  * @return void
  */
 public function save(Category $category)
 {
     if ($category->isValid()) {
         $category->isNew() ? $this->add($category) : $this->modify($category);
     } else {
         throw new RuntimeException('La catégorie doit être valide pour être enregistrée');
     }
 }
 /**
  * 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->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->aProduct !== null) {
             if ($this->aProduct->isModified() || $this->aProduct->isNew()) {
                 $affectedRows += $this->aProduct->save($con);
             }
             $this->setProduct($this->aProduct);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = CategoryHasProductPeer::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->setNew(false);
             } else {
                 $affectedRows += CategoryHasProductPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Redirect to category view
  *
  */
 function view_category()
 {
     $category_id = (int) $this->request->get('object_id');
     if ($category_id) {
         $category = Categories::findById($category_id);
     } else {
         $category = new Category();
     }
     // if
     if ($category->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $project = $category->getProject();
     if (!instance_of($project, 'Project')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $base_url = assemble_url('mobile_access_view_' . $category->getModule(), array('project_id' => $project->getId()));
     $this->redirectToUrl($base_url . '/?category_id=' . $category_id);
 }