/** * Serialize the form into the database. * */ public function save($con = null) { $j = new Job(); $j->setEvent($this->getValue("event")); $j->setStartTime($this->getValue("start_time")); $j->setEndTime($this->getValue("end_time")); $j->setDueDate($this->getValue("due_date")); $j->setPublicationId($this->getValue("publication_id")); $j->setStreet($this->getValue("street")); $j->setCity($this->getValue("city")); $j->setState($this->getValue("state")); $j->setZip($this->getValue("zip")); $j->setContactName($this->getValue("contact_name")); $j->setContactPhone($this->getValue("contact_phone")); $j->setContactEmail($this->getValue("contact_email")); $j->setStatusId(sfConfig::get("app_job_status_pending", 1)); $j->setProjectId($this->getValue("project_id")); $j->save(); }
/** * Serialize the form into the database. * */ public function save($con = null) { if ($this->getObject()) { $j = $this->getObject(); } else { $j = new Job(); } $j->setState($this->getValue("state")); $j->setCity($this->getValue("city")); $j->setZip($this->getValue("zip")); $j->setStreet($this->getValue("street")); $j->save(); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Shoot info updated."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_update")); $logEntry->setPropelId($j->getId()); $logEntry->save(); }
public function transformJobs() { $statusHash = array(); $statusObjects = StatusPeer::doSelect(new Criteria()); foreach ($statusObjects as $s) { $statusHash[$s->getState()] = $s->getId(); } $this->jobKeys = array(); $dom = DOMDocument::load("tuftsph_jm2db.xml"); $jobs = $dom->getElementsByTagName("jobs"); $total = $jobs->length; $count = 1; $jobList = array(); foreach ($jobs as $job) { $jid = 0; $childNodes = $job->childNodes; $j = new Job(); $del = new Delivery(); $jid = 1; $startTime = null; $shootStart = null; $shootEnd = null; $endTime = null; $notes = ""; $photog = 0; $slug = ""; $childNodes = $job->childNodes; foreach ($childNodes as $child) { switch ($child->nodeName) { case "id": $jid = $child->textContent; break; case "shoot_name": $j->setEvent($child->textContent); break; case "shoot_date": $j->setDate($child->textContent); break; case "shoot_startT": $startTime = $child->textContent; break; case "shoot_start": $shootStart = $child->textContent; break; case "shoot_endT": $endTime = $child->textContent; break; case "shoot_end": $shootEnd = $child->textContent; break; case "shoot_duedate": $j->setDueDate($child->textContent); break; case "submitted_at": $j->setCreatedAt($child->textContent); break; case "requester_address": $j->setStreet($child->textContent); break; case "requester_campus": $j->setCity($child->textContent); break; case "requester_name": $j->setContactName($child->textContent); break; case "requester_email": $j->setContactEmail($child->textContent); break; case "requester_phone": $j->setContactPhone($child->textContent); break; case "internal_notes": $notes .= $child->textContent . "<br/>"; break; case "billing_notes": $notes .= $child->textContent . "<br/>"; break; case "estimate": $j->setEstimate($child->textContent); break; case "billing_acctnum": $j->setAcctNum($child->textContent); break; case "billing_deptid": $j->setDeptId($child->textContent); break; case "billing_grantid": $j->setGrantId($child->textContent); break; case "shoot_directions": $j->setOther($child->textContent); break; case "status": $j->setStatusId($statusHash[$child->textContent]); break; case "photog_id": $photog = $child->textContent; break; case "delivery_pubname": $del->setPubName($child->textContent); break; case "delivery_pubtype": $del->setPubType($child->textContent); break; case "delivery_other": $del->setOther($child->textContent); break; case "delivery_format": break; case "delivery_color": $del->setColor($child->textContent); break; case "delivery_format": $del->setFormat($child->textContent); break; case "delivery_size": $del->setSize($child->textContent); break; case "delivery_method": $del->setMethod($child->textContent); break; case "delivery_special": $del->setInstructions($child->textContent); break; case "slug": $slug = $child->textContent; break; case "#text": default: break; } } if (is_null($endTime)) { $endTime = $shootEnd; } if (is_null($startTime)) { $startTime = $shootStart; } if ($j->getCity() == "Boston") { $j->setZip("02101"); } else { $j->setZip("02155"); } $j->setNotes($notes); $j->setState("Massachusetts"); list($hour, $min, $sec) = explode(":", $endTime); list($shour, $smin, $ssec) = explode(":", $startTime); $t = new DateTime(); $t->setTime($hour, $min, $sec); $j->setEndTime($t); $t = new DateTime(); $t->setTime($shour, $smin, $ssec); $j->setStartTime($t); $j->addTag($slug); if (isset($this->jobProjectKeys[$jid])) { $j->setProjectId($this->projectKeys[$this->jobProjectKeys[$jid]]); } while (count($jobList) - 1 != $jid) { $jobList[] = false; } $jobList[intval($jid)] = array("job" => $j, "del" => $del, "photog" => $photog); } for ($i = 1; $i < count($jobList); $i++) { sleep(1); $obj = $jobList[$i]; $c = new Criteria(); $c->add(JobPeer::ID, $i); if (JobPeer::doCount($c) > 0) { continue; } echo $i . "/" . $total . "\n"; // keep the ids lined up if ($obj == false) { $myJob = new Job(); try { $myJob->save(); } catch (Exception $ex) { echo $ex->getMessage(); } $myJob->delete(); } else { $j = $obj["job"]; $del = $obj["del"]; $photog = $obj["photog"]; try { $j->save(); } catch (Exception $ex) { echo $ex->getMessage(); echo $ex->getTraceAsString(); } $del->setJobId($j->getId()); $del->save(); $this->jobKeys[$jid] = $j->getId(); if ($photog) { $jp = new JobPhotographer(); $jp->setPhotographerId($this->photogKeys[$photog]); $jp->setJobId($j->getId()); try { $jp->save(); } catch (Exception $ex) { echo $ex->getMessage(); } } // add the requester as a client $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $j->getContactEmail()); if (ClientPeer::doCount($c) == 0 && trim(strlen($j->getContactEmail())) != 0) { $user = new sfGuardUser(); $user->setUsername($j->getContactEmail()); $user->setPassword("admin"); $user->save(); $userProfile = new sfGuardUserProfile(); $userProfile->setUserId($user->getId()); $userProfile->setUserTypeId(sfConfig::get("app_user_type_client")); $userProfile->save(); $clientProfile = new Client(); $clientProfile->setUserId($userProfile->getId()); $clientProfile->setName($j->getContactName()); $clientProfile->setEmail($j->getContactEmail()); $clientProfile->setPhone($j->getContactPhone()); $clientProfile->save(); $jobClient = new JobClient(); $jobClient->setClientId($clientProfile->getId()); $jobClient->setJobId($j->getId()); $jobClient->save(); } } $count += 1; } }
public function save($con = null) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'Object', 'Tag', 'Text', 'PMRender', 'Asset', 'Helper')); $j = new Job(); $j->setEvent($this->getValue("event")); $j->setStartTime($this->getValue("start_time")); $j->setEndTime($this->getValue("end_time")); $j->setDate($this->getValue("date")); $j->setDueDate($this->getValue("due_date")); $j->setAcctNum($this->getValue("acct_num")); $j->setDeptId($this->getValue("dept_id")); $j->setPublicationId($this->getValue("publication_id")); $j->setStreet($this->getValue("street")); $j->setCity($this->getValue("city")); $j->setState($this->getValue("state")); $j->setZip($this->getValue("zip")); if (is_array($this->getValue("photo_type"))) { $j->setPhotoType(implode(", ", $this->getValue("photo_type"))); } else { $j->setPhotoType($this->getValue("photo_type")); } $j->setOther($this->getValue("other")); $j->setQues1($this->getValue("ques1")); $j->setQues2($this->getValue("ques2")); $j->setQues3($this->getValue("ques3")); $j->setContactName($this->getValue("contact_name")); $j->setContactPhone($this->getValue("contact_phone")); $j->setContactEmail($this->getValue("contact_email")); $j->setStatusId(sfConfig::get("app_job_status_pending", 1)); $j->setProjectId($this->getValue("project_id")); $j->save(); $body = "Dear {$this->getValue("name")},\r\n\r\nYour job, {$this->getValue("event")}, has been entered into our system. \r\nIf you wish to track the progress of your job, you may do so at http://jobs.tuftsphoto.com \r\n\r\nThanks for using University Photography; we look forward to working with you! \r\n\r\nThe Tufts Photo Team \r\nUniversity Photography\r\n80 George St., First Floor\r\nMedford, MA 02155\r\nTel: 617.627.4282\r\nFax: 617.627.3549\r\nphoto@tufts.edu\r\n\r\n\r\n" . getJobDetails($j); mail($this->getValue("email") . ", photo@tufts.edu", "University Photography Job #" . $j->getId() . " - " . $j->getEvent(), $body, "From: photo@tufts.edu"); $user = sfContext::getInstance()->getUser(); if ($this->getValue("clientId") > 0 && ($user->hasCredential("client") || $user->hasCredential("admin"))) { $client = ClientPeer::retrieveByPK($this->getValue("clientId")); $j->addClient($client); } // if they are a user lets make them a client if ($user->getProfile()->getUserType()->getId() == sfConfig::get("app_user_type_user")) { $clientProfile = new Client(); $clientProfile->setUserId($user->getProfile()->getId()); $clientProfile->setName($this->getValue("name")); $clientProfile->setDepartment($this->getValue("department")); $clientProfile->setAddress($this->getValue("address")); $clientProfile->setEmail($this->getValue("email")); $clientProfile->setPhone($this->getValue("phone")); $clientProfile->save(); $user->getProfile()->setUserTypeId(sfConfig::get("app_user_type_client")); $user->getProfile()->save(); $user->clearCredentials(); $user->addCredential("client"); } else { if ($user->getProfile()->getUserType()->getId() == sfConfig::get("app_user_type_client")) { $c = new Criteria(); $c->add(ClientPeer::USER_ID, $user->getProfile()->getId()); $clientProfile = ClientPeer::doSelectOne($c); if (is_null($clientProfile)) { $clientProfile = new Client(); } $clientProfile->setUserId($user->getProfile()->getId()); $clientProfile->setName($this->getValue("name")); $clientProfile->setDepartment($this->getValue("department")); $clientProfile->setAddress($this->getValue("address")); $clientProfile->setEmail($this->getValue("email")); $clientProfile->setPhone($this->getValue("phone")); $clientProfile->save(); } } if (isset($clientProfile) && !is_null($clientProfile)) { $j->addClient($clientProfile); } return $j->getId(); }