/**
  * Update project
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true);
     }
     // if
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_project->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $project_data = $this->request->post('project');
     if (!is_array($project_data)) {
         $project_data = array('name' => $this->active_project->getName(), 'overview' => $this->active_project->getOverview(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'leader_id' => $this->active_project->getLeaderId(), 'group_id' => $this->active_project->getGroupId(), 'company_id' => $this->active_project->getCompanyId(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'starts_on' => $this->active_project->getStartsOn());
     }
     // if
     $this->smarty->assign('project_data', $project_data);
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $old_name = $this->active_project->getName();
         $this->active_project->setAttributes($project_data);
         if ($this->active_project->isModified('leader_id') && $this->active_project->getLeaderId()) {
             $leader = Users::findById($this->active_project->getLeaderId());
             if (instance_of($leader, 'User')) {
                 $this->active_project->setLeader($leader);
             }
             // if
         }
         // if
         if ($this->active_project->isModified('company_id')) {
             cache_remove('project_icons');
         }
         // if
         $save = $this->active_project->save();
         if ($save && !is_error($save)) {
             db_commit();
             if ($this->request->isApiCall()) {
                 $this->serveData($this->active_project, 'project');
             } else {
                 flash_success('Project :name has been updated', array('name' => $old_name));
                 $this->redirectToUrl($this->active_project->getOverviewUrl());
             }
             // if
         } else {
             db_rollback();
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 $this->smarty->assign('errors', $save);
             }
             // if
         }
         // if
     }
     // if
 }
Example #2
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->aProject !== null) {
             if ($this->aProject->isModified() || $this->aProject->isNew()) {
                 $affectedRows += $this->aProject->save($con);
             }
             $this->setProject($this->aProject);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = BuildPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = BuildPeer::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 += BuildPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }