/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Photographer();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Photographer'])) {
         $model->attributes = $_POST['Photographer'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->idph));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * 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->aPhotographer !== null) {
             if ($this->aPhotographer->isModified() || $this->aPhotographer->isNew()) {
                 $affectedRows += $this->aPhotographer->save($con);
             }
             $this->setPhotographer($this->aPhotographer);
         }
         if ($this->aJob !== null) {
             if ($this->aJob->isModified() || $this->aJob->isNew()) {
                 $affectedRows += $this->aJob->save($con);
             }
             $this->setJob($this->aJob);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = JobPhotographerPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = JobPhotographerPeer::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 += JobPhotographerPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Serialize the form into the database.
  **/
 public function save($con = null)
 {
     if (!is_null($this->getValue("photographer_id"))) {
         $p = $this->getObject();
     } else {
         $sfUser = new sfGuardUser();
         $sfUser->setUsername($this->getValue("email"));
         $sfUser->setPassword($this->getValue("password"));
         $sfUser->save();
         if (strpos($this->getValue("name"), " ") !== false) {
             list($firstName, $lastName) = explode(" ", $this->getValue("name"));
         } else {
             $firstName = "";
             $lastName = "";
         }
         $sfProfile = new sfGuardUserProfile();
         $sfProfile->setUserTypeId(sfConfig::get("app_user_type_photographer"));
         $sfProfile->setUserId($sfUser->getId());
         $sfProfile->setEmail($this->getValue("email"));
         $sfProfile->setFirstName($firstName);
         $sfProfile->setLastName($lastName);
         $sfProfile->save();
         $p = new Photographer();
         $p->setUserId($sfProfile->getId());
     }
     $p->setName($this->getValue("name"));
     $p->setEmail($this->getValue("email"));
     $p->setPhone($this->getValue("phone"));
     $p->setAffiliation($this->getValue("affiliation"));
     $p->setWebsite($this->getValue("website"));
     $p->setDescription($this->getValue("description"));
     $p->setBillingAddress($this->getValue("billing_info"));
     $p->save();
     if ($this->getValue("reset_password")) {
         $user = $p->getsfGuardUserProfile()->getsfGuardUser();
         $user->setPassword($this->getValue("password"));
         $user->save();
     }
 }
 public function transformPhotographers()
 {
     $this->photogKeys = array();
     $dom = DOMDocument::load("tuftsph_jm2db.xml");
     $photogs = $dom->getElementsByTagName("photogs");
     $total = $photogs->length;
     $count = 1;
     echo "Converting Photographers \n";
     foreach ($photogs as $pr) {
         echo $count . "/" . $total . "\n";
         $count += 1;
         $childNodes = $pr->childNodes;
         $i = array();
         foreach ($childNodes as $child) {
             $i[$child->nodeName] = $child->textContent;
         }
         list($firstName, $lastName) = explode(" ", $i["name"]);
         if (strlen($i["email"]) == 0 || is_null($i["email"])) {
             $i["email"] = "NO_EMAIL_" . $count . "@TUFTS.EDU";
         }
         $user = new sfGuardUser();
         $user->setUsername($i["email"]);
         $user->setPassword("");
         $user->setAlgorithm("sha1");
         $user->save();
         $profile = new sfGuardUserProfile();
         $profile->setUserId($user->getId());
         $profile->setUserTypeId(sfConfig::get("app_user_type_photographer"));
         $profile->setEmail($i["email"]);
         $profile->setFirstName($firstName);
         $profile->setLastName($lastName);
         $profile->save();
         $ph = new Photographer();
         $ph->setUserId($profile->getId());
         $ph->setName($i["name"]);
         $ph->setPhone($i["phone"]);
         $ph->setEmail($i["email"]);
         $ph->setAffiliation($i["affiliation"]);
         $ph->save();
         $this->photogKeys[$i["photog_id"]] = $ph->getId();
     }
 }