public static function isOwner($jobId, $userId) { $c = new Criteria(); $c->add(ClientPeer::USER_ID, $userId); $client = ClientPeer::doSelectOne($c); if (is_null($client)) { return false; } $cid = $client->getId(); if (!array_key_exists($cid, self::$clientJobIdCache)) { self::$clientJobIdCache[$cid] = array(); self::$clientJobIdCache[$cid] = self::getJobsByClientId($cid); } return in_array($jobId, self::$clientJobIdCache[$cid]); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->page = $this->getRequest()->getParameter("page"); $this->sortedBy = $this->getRequest()->getParameter("sortBy"); $this->invert = $this->getRequest()->getParameter("invert"); $own = $request->getParameter("own"); $all = $request->getParameter("all"); $this->all = $all; $this->own = $own; $profile = $this->getUser()->getProfile(); if (is_null($all)) { $all = false; } if (is_null($own)) { $own = false; } $c = new Criteria(); if ($own) { $crit = new Criteria(); $crit->add(ClientPeer::USER_ID, $profile->getId()); $client = ClientPeer::doSelectOne($crit); if (is_null($client)) { $this->forward404("Please contact Tufts Photo support."); } $crit = new Criteria(); $ids = array(); $crit->add(JobClientPeer::CLIENT_ID, $client->getId()); $jobs = JobClientPeer::doSelectJoinAll($crit); foreach ($jobs as $ph) { $ids[] = $ph->getJobId(); } $c->add(JobPeer::ID, $ids, Criteria::IN); } else { // $c->add(JobPeer::STATUS_ID, sfConfig::get("job_status_pending")); $c = new Criteria(); $crit0 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_pending")); $crit1 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_accepted")); $crit2 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_completed")); // Perform OR at level 0 ($crit0 $crit1 $crit2 ) $crit0->addOr($crit1); $crit0->addOr($crit2); // Remember to change the peer class here for the correct one in your model $c->add($crit0); } // restrict to only their jobs if they are photogs if ($profile->getUserType()->getId() == sfConfig::get("app_user_type_photographer")) { $crit = new Criteria(); $crit->add(PhotographerPeer::USER_ID, $profile->getId()); $photo = PhotographerPeer::doSelectOne($crit); if (is_null($photo)) { $this->forward404("Please contact Tufts Photo support."); } $crit = new Criteria(); $crit->add(JobPhotographerPeer::PHOTOGRAPHER_ID, $photo->getId()); $ids = array(); $photos = JobPhotographerPeer::doSelectJoinAll($crit); foreach ($photos as $ph) { $ids[] = $ph->getJobId(); } $c->add(JobPeer::ID, $ids, Criteria::IN); } if (is_null($this->sortedBy)) { $this->sortedBy = JobPeer::DATE; } if (is_null($this->invert) || $this->invert == "false") { $this->invert = false; $c->addAscendingOrderByColumn($this->sortedBy); } else { $c->addDescendingOrderByColumn($this->sortedBy); $this->invert = true; } if (!is_numeric($this->page)) { $this->page = 1; } $this->pager = new sfPropelPager("Job", sfConfig::get("app_items_per_page")); $this->pager->setCriteria($c); $this->pager->setPage($this->page); $this->pager->setPeerMethod("doSelectJoinAll"); $this->pager->init(); $this->results = $this->pager->getResults(); sfPropelActAsTaggableBehavior::preloadTags($this->results); $sortUrls = array(); foreach (JobPeer::$LIST_VIEW_SORTABLE as $key => $val) { $sortUrls[$key]["true"] = $this->generateUrl("client_myjobs_own", array("own" => $own, "all" => $all, "sortBy" => $key, "invert" => "true")); $sortUrls[$key]["false"] = $this->generateUrl("client_myjobs_own", array("own" => $own, "all" => $all, "sortBy" => $key, "invert" => "false")); } $this->sortUrlJson = json_encode($sortUrls); }
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(); }
/** * Executes the create action. * Displays a form to the user or deals with the save. * * @param sfWebRequest $request */ public function executeCreate(sfWebRequest $request) { $this->isAdmin = $this->getUser()->hasCredential("admin"); $this->form = new RequestJobForm(); $this->attachForm = new JobAttachmentFormCustom(); if ($this->getUser()->getProfile()->getUserTypeId() == sfConfig::get("app_user_type_client")) { $c = new Criteria(); $c->add(ClientPeer::USER_ID, $this->getUser()->getProfile()->getId()); $profile = ClientPeer::doSelectOne($c); $this->isReadonly = !is_null($profile); } else { $profile = null; $this->isReadonly = false; } if ($request->isMethod("POST")) { $this->processForm($request, $this->form, $this->attachForm); } else { if (!is_null($profile)) { $this->form->setDefault("name", $profile->getName()); $this->form->setDefault("department", $profile->getDepartment()); $this->form->setDefault("address", $profile->getAddress()); $this->form->setDefault("email", $profile->getEmail()); $this->form->setDefault("phone", $profile->getPhone()); $this->form->setDefault("clientId", $profile->getId()); } } }
/** * Get the associated Client object * * @param PropelPDO Optional Connection object. * @return Client The associated Client object. * @throws PropelException */ public function getClient(PropelPDO $con = null) { if ($this->aClient === null && $this->client_id !== null) { $c = new Criteria(ClientPeer::DATABASE_NAME); $c->add(ClientPeer::ID, $this->client_id); $this->aClient = ClientPeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aClient->addJobClients($this); */ } return $this->aClient; }