Example #1
0
 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;
     }
 }
Example #2
0
 if (strlen($email) >= 30) {
     Message::register(new Message(Message::DANGER, i18n(array("en" => "Max length for email is 30", "zh" => "email 不能超过30个字符"))));
     $error_flag = true;
 }
 if ($email != $retype_email) {
     Message::register(new Message(Message::DANGER, i18n(array("en" => "Retype value does not match for email", "zh" => "再次输入的email与原值不匹配"))));
     $error_flag = true;
 }
 // validation for $keyuan
 $keyuan = isset($_POST["keyuan"]) ? strip_tags($_POST["keyuan"]) : null;
 // validation for $beizhu
 $beizhu = isset($_POST["beizhu"]) ? $_POST["beizhu"] : null;
 /// proceed submission
 // proceed for $user_id
 if (!empty($user_id)) {
     $object->setUserId($user_id);
 }
 // proceed for $type
 if (!empty($type)) {
     $object->setType($type);
 }
 // proceed for $name
 $object->setName($name);
 // proceed for $dob
 $object->setDob($dob);
 // proceed for $chushengriqi
 $object->setChushengriqi($chushengriqi);
 // proceed for $xueli
 if (!empty($xueli)) {
     $object->setXueli($xueli);
 }
 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();
 }
Example #4
0
<?php

require_once __DIR__ . DS . '..' . DS . '..' . DS . 'bootstrap.php';
if (is_cli()) {
    $names = array('ZHENG XIAOHONG', 'WANG LIANGLIANG', 'LI YUNQIAN', 'LIU SHITAO', 'CHENG LANLAN', 'SUN XINWEI', 'QIAN WUCHAO', 'ZHAO LIUYUN', 'TAN GUOQIANG', 'WEI BEIFEI', 'XIA FEIFEI');
    $shengs = array('上海市', '江苏省', '湖南省', '四川省', '云南省', '广西省', '广东省', '台湾省');
    $qus = array('宝山区', '周口店', '宁乡', '沩水镇', '张家界', '小四通', '黄埔区', '晋安区');
    $address = rand(10, 99) . '村' . rand(300, 900) . '号';
    $dob_range_start = 381416400;
    $dob_range_end = 917874000;
    foreach ($names as $name) {
        $client = new Client();
        $client->setType(array_rand(Client::$TYPEs));
        $client->setName($name);
        $client->setDob(rand($dob_range_start, $dob_range_end));
        $client->setXueli(array_rand(Client::$XUELIs));
        $client->setYasichengji(array_rand(Client::$YASIs));
        $client->setDianhua('+86 ' . rand(2156299999, 2156292999));
        $client->setDizhi($shengs[array_rand($shengs)] . ' ' . $qus[array_rand($qus)] . ' ' . $address);
        $client->setEmail(get_random_string(5) . '@gmail.com');
        $client->setKeyuan(array_rand(Client::$KEYUANs));
        $client->setCreatedAt(rand(1439164648, 1439264648));
        $client->setUserId(rand(3, 4));
        $client->save();
    }
}