public function executeAdvancedRender(sfWebRequest $request) { $this->form = new AdvancedSearchForm(); if (!$request->isMethod("POST")) { $this->forward("Not Supported!"); } $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); $page = $request->getParameter($this->form->getName() . "[page]"); $arr = array(); $arr["jobStatus"] = $request->getParameter($this->form->getName() . "[status_id]"); $arr["dueDateStart"] = $this->getFormattedDate($request->getParameter($this->form->getName() . "[due_date_start]")); $arr["dueDateEnd"] = $this->getFormattedDate($request->getParameter($this->form->getName() . "[due_date_end]")); $arr["shootDateStart"] = $this->getFormattedDate($request->getParameter($this->form->getName() . "[shoot_date_start]")); $arr["shootDateEnd"] = $this->getFormattedDate($request->getParameter($this->form->getName() . "[shoot_date_end]")); $arr["clientId"] = $request->getParameter($this->form->getName() . "[client_id]"); $arr["photographerId"] = $request->getParameter($this->form->getName() . "[photo_id]"); $arr["sortOn"] = $request->getParameter($this->form->getName() . "[sort]"); $arr["sortDirection"] = $request->getParameter($this->form->getName() . "[sort_direction]"); $c = $this->createAdvancedSearchCriteria($arr); $this->pager = new sfPropelPager("Job", sfConfig::get("app_items_per_page")); $this->pager->setCriteria($c); $this->pager->setPage($page); $this->pager->setPeerMethod("doSelectJoinAll"); $this->pager->init(); $this->results = $this->pager->getResults(); sfPropelActAsTaggableBehavior::preloadTags($this->results); }
protected function getPager($c, $urlInfo = null) { $this->page = $this->getRequest()->getParameter("page"); $this->sortedBy = $this->getRequest()->getParameter("sortBy"); $this->invert = $this->getRequest()->getParameter("invert"); 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; } // if this user is only a client // make sure they can only see their jobs $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); if (!is_null($urlInfo)) { $sortUrls = array(); foreach (JobPeer::$LIST_VIEW_SORTABLE as $key => $val) { $sortUrls[$key]["true"] = $this->generateUrl($urlInfo["route"], array($urlInfo["slugOn"] => $urlInfo["slug"], "sortBy" => $key, "invert" => "true")); $sortUrls[$key]["false"] = $this->generateUrl($urlInfo["route"], array($urlInfo["slugOn"] => $urlInfo["slug"], "sortBy" => $key, "invert" => "false")); } $this->sortUrlJson = json_encode($sortUrls); } }
/** * 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); }
$object_2_1 = _create_object_2(); $object_2_1->addTag('tag1,tag3,tag7'); $object_2_1->save(); $object_2_2 = _create_object_2(); $object_2_2->addTag('tag2,tag7'); $object_2_2->save(); $tagged_with_tag4 = TagPeer::getTaggedWith('tag4'); $t->ok(count($tagged_with_tag4) == 2, 'getTaggedWith() returns objects tagged with one specific tag.'); $tagged_with_tag7 = TagPeer::getTaggedWith('tag7'); $t->ok(count($tagged_with_tag7) == 5, 'getTaggedWith() can return several object types.'); $tagged_with_tag17 = TagPeer::getTaggedWith(array('tag1', 'tag7')); $t->ok(count($tagged_with_tag17) == 3, 'getTaggedWith() returns objects tagged with several specific tags.'); $tagged_with_tag127 = TagPeer::getTaggedWith('tag1, tag2, tag7', array('nb_common_tags' => 2)); $t->ok(count($tagged_with_tag127) == 6, 'the "nb_common_tags" option of getTaggedWith() returns objects tagged with a certain number of tags within a set of specific tags.'); // these tests check the preloadTags() method sfPropelActAsTaggableBehavior::preloadTags($tagged_with_tag17); $nb_tags = 0; foreach ($tagged_with_tag17 as $tmp_object) { $nb_tags += count($tmp_object->getTags()); } $t->ok($nb_tags === 10, 'preloadTags() preloads the tags of the objects.'); // these tests check the isTaggable() method $t->diag('detecting if a model is taggable or not'); $t->ok(sfPropelActAsTaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.'); $object = _create_object(); $t->ok(sfPropelActAsTaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.'); $t->ok(sfPropelActAsTaggableToolkit::isTaggable('Tristan\'s cat') === false, 'Tristan\'s cat is not taggable, and that is fine.'); // clean the database TagPeer::doDeleteAll(); TaggingPeer::doDeleteAll(); call_user_func(array(_create_object()->getPeer(), 'doDeleteAll'));
private function reloadByAdvancedSearch($params) { parse_str($params, $obj); $arr = array(); $obj = $obj["advancedsearch"]; $page = $obj["page"]; $arr["jobStatus"] = $obj["status_id"]; $arr["dueDateStart"] = $this->getFormattedDate($obj["due_date_start"]); $arr["dueDateEnd"] = $this->getFormattedDate($obj["due_date_end"]); $arr["shootDateStart"] = $this->getFormattedDate($obj["shoot_date_start"]); $arr["shootDateEnd"] = $this->getFormattedDate($obj["shoot_date_end"]); $arr["clientId"] = $obj["client_id"]; $arr["photographerId"] = $obj["photo_id"]; $arr["sortOn"] = $obj["sort"]; $arr["sortDirection"] = $obj["sort_direction"]; $c = $this->createAdvancedSearchCriteria($arr); $pager = new sfPropelPager("Job", sfConfig::get("app_items_per_page")); $pager->setCriteria($c); $pager->setPage($page); $pager->setPeerMethod("doSelectJoinAll"); $pager->init(); $results = $pager->getResults(); sfPropelActAsTaggableBehavior::preloadTags($results); $this->renderPartial("search/advancedRender", array("pager" => $pager)); return sfView::NONE; }