protected function createAdvancedSearchCriteria($arr) { $c = new Criteria(); if (strlen($arr['jobStatus'])) { $c->add(JobPeer::STATUS_ID, $arr["jobStatus"]); } if (!is_null($arr["dueDateStart"])) { $c->add(JobPeer::DUE_DATE, $arr["dueDateStart"], Criteria::GREATER_EQUAL); } if (!is_null($arr["dueDateEnd"])) { $c->addAnd(JobPeer::DUE_DATE, $arr["dueDateEnd"], Criteria::LESS_EQUAL); } if (!is_null($arr["shootDateStart"])) { $c->add(JobPeer::DATE, $arr["shootDateStart"], Criteria::GREATER_EQUAL); } if (!is_null($arr["shootDateEnd"])) { $c->addAnd(JobPeer::DATE, $arr["shootDateEnd"], Criteria::LESS_EQUAL); } if (strlen($arr["clientId"])) { $jobIds = JobClientPeer::getJobsByClientId($arr["clientId"]); $c->add(JobPeer::ID, $jobIds, Criteria::IN); } if (strlen($arr["photographerId"])) { $jobIds = JobPhotographerPeer::getJobsByPhotographerId($arr["photographerId"]); $c->addAnd(JobPeer::ID, $jobIds, Criteria::IN); } if ($arr["sortDirection"] == 1) { $c->addDescendingOrderByColumn($arr["sortOn"]); } else { $c->addAscendingOrderByColumn($arr["sortOn"]); } return $c; }
public static function deleteClient($client) { $c1 = new Criteria(); $c1->add(JobClientPeer::CLIENT_ID, $client->getId()); JobClientPeer::doDelete($c1); $client->delete(); }
public function executeViewJobs(sfWebRequest $request) { $this->client = $this->getRoute()->getObject(); $ids = JobClientPeer::getJobsByClientId($this->client->getId()); $c = new Criteria(); $c->add(JobPeer::ID, $ids, Criteria::IN); $this->getPager($c, array("route" => "client_view_jobs", "slugOn" => "slug", "slug" => $this->client->getSlug())); }
private function reloadByClient($clientId) { $c = new Criteria(); $this->routeObject = ClientPeer::retrieveByPK($clientId); $ids = JobClientPeer::getJobsByClientId($this->routeObject->getId()); $c->add(JobPeer::ID, $ids, Criteria::IN); $this->route = "client_view_jobs"; $this->propelType = "slug"; $this->renderStatus = true; $this->viewingCaption = " jobs owned by " . $this->routeObject->getName(); return $c; }
/** * 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); }
function renderClientJobListView($job, $classNum, $canAdd) { ?> <div class="job-list-item-<?php echo $classNum; ?> "> <?php $sTime = $job->getStartTime(); $eTime = $job->getEndTime(); $sTime = substr($sTime, -8, 5); $eTime = substr($eTime, -8, 5); ?> <table class="job-table" width="100%"> <col width="33%"></col> <col width="33%"></col> <tr> <td> <?php if (sfContext::getInstance()->getUser()->hasCredential("client")) { ?> <?php if (JobClientPeer::isOwner($job->getId(), sfContext::getInstance()->getUser()->getProfile()->getId())) { ?> Job <?php echo link_to($job->getId(), "clientview_job_show", $job); ?> <?php } else { ?> Job <?php echo $job->getId(); ?> <?php } ?> <?php } ?> <?php if (sfContext::getInstance()->getUser()->hasCredential("photographer")) { ?> <?php if (JobPhotographerPeer::isOwner($job->getId(), sfContext::getInstance()->getUser()->getProfile()->getId())) { ?> Job <?php echo link_to($job->getId(), "clientview_job_show", $job); ?> <?php } else { ?> Job <?php echo $job->getId(); ?> <?php } ?> <?php } ?> </td> <td><?php echo $job->getEvent(); ?> </td> <?php if ($canAdd && sfContext::getInstance()->getUser()->hasCredential("client")) { ?> <td><?php echo link_to_function("Add me as client", "addClient(" . $job->getId() . ")"); ?> </td> <?php } ?> <td><?php if ($job->getProjectId()) { $title = $job->getProject()->getName(); $title = substr($title, 0, 30) == $title ? $title : substr($title, 0, 30) . "..."; echo "In " . $job->getProject(); } ?> </td> </tr> <tr> <td><?php echo $job->getDate("F j, Y") . " " . $sTime . " - " . $eTime; ?> </td> <td><?php $clients = $job->getClients(); if (count($clients) == 0) { echo "No Clients"; } else { echo "For "; foreach ($clients as $c) { echo $c->getName() . " "; } } ?> </td> <?php $photogs = $job->getPhotographers(); if (count($photogs) == 1) { foreach ($photogs as $i) { ?> <td> <?php echo $i . " "; ?> </td> <?php } ?> <?php } ?> <?php if (count($photogs) == 0) { ?> <td> <?php echo "No Photographer"; ?> </td> <?php } ?> <?php if (count($photogs) > 1) { ?> <td> <?php echo count($photogs) . " Photographers"; ?> </td> <?php } ?> </tr> </table> </div> <?php }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Client is new, it will return * an empty collection; or if this Client has previously * been saved, it will retrieve related JobClients from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Client. */ public function getJobClientsJoinJob($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(ClientPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collJobClients === null) { if ($this->isNew()) { $this->collJobClients = array(); } else { $criteria->add(JobClientPeer::CLIENT_ID, $this->id); $this->collJobClients = JobClientPeer::doSelectJoinJob($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(JobClientPeer::CLIENT_ID, $this->id); if (!isset($this->lastJobClientCriteria) || !$this->lastJobClientCriteria->equals($criteria)) { $this->collJobClients = JobClientPeer::doSelectJoinJob($criteria, $con, $join_behavior); } } $this->lastJobClientCriteria = $criteria; return $this->collJobClients; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(JobClientPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(JobClientPeer::DATABASE_NAME); $criteria->add(JobClientPeer::ID, $pks, Criteria::IN); $objs = JobClientPeer::doSelect($criteria, $con); } return $objs; }
public function removeClient($client) { $c = new Criteria(); $c->add(JobClientPeer::CLIENT_ID, $client->getId()); $c->add(JobClientPeer::JOB_ID, $this->getId()); JobClientPeer::doDelete($c); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage($client->getName() . " removed from job."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_remove_client")); $logEntry->setPropelId($this->getId()); $logEntry->save(); }
public function getNumberOfJobs() { $c = new Criteria(); $c->add(JobClientPeer::CLIENT_ID, $this->getId()); return JobClientPeer::doCount($c); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = JobClientPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setClientId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setJobId($arr[$keys[2]]); } }