Пример #1
0
 /**
  * Method for determining helpful search routes based on the current
  * derived similar parts result set.  Should really calculate the running time
  * for this algorithm.  Right now the largest input array has 
  * sfConfig::get('app_search_max_pagination_items') items.
  * @param Array $similar_parts
  */
 protected function setSearchRoutes($similar_parts = array())
 {
     $manuf_slugs = $cat_slugs = $routes = array();
     foreach ($similar_parts as $part) {
         $manuf_slugs[$part['manuf']] = $part['manuf_slug'];
         $cat_slugs[$part['category']] = $part['cat_slug'];
     }
     foreach ($cat_slugs as $category => $cat_slug) {
         foreach ($manuf_slugs as $manuf => $manuf_slug) {
             if (in_array($category . ':' . $manuf, $this->_cat_manuf_map)) {
                 $routes[] = array('anchor_txt' => $manuf . ' ' . $category, 'route' => '@' . LWS::getCategoryPk($cat_slug) . '_manuf?manuf_slug=' . $manuf_slug);
             }
             //$routes[$manuf . ' ' . $category] = '@' . LWS::getCategoryPk($cat_slug) . '_manuf?manuf_slug=' . $manuf_slug;
         }
     }
     $this->_search_routes = $routes;
 }
Пример #2
0
 /**
  * 
  * Retrieves part information using appropriate DAO object for each parts landing page.
  * 
  * IMPORTANT:  Since adding the use of sessions to manage the transformer selection tool
  * 						 voltage swap, I can no longer cache this entire template with layout, but
  * 						 instead only parts of the template.  THIS SUCKS!  Seriously consider refactoring
  * 						 our DB to avoid any sort of hack due to bad planning, or find a hack without
  * 					   using sessions but instead query parameters.
  * @param sfWebRequest $request
  */
 public function executePart(sfWebRequest $request)
 {
     $cat_slug = $request->getParameter('cat_slug');
     $cat_id = LWS::getCategoryPk($cat_slug);
     $part_no = LWS::unencode($request->getParameter('part_no'));
     $part = PartFactory::make(array('cat_id' => $cat_id, 'part_no' => $part_no));
     $this->param = array();
     $this->param['cat_id'] = $cat_id;
     $this->param['part'] = $part->getDetails();
     // If I opt to move this whole piece of TR logic to TRPart by passing in the sfUser object
     // Then I'd have to update the constructor for all DAO's to include an optional construction
     // parameter. Unless I can get it from within the TRPart.
     if ($cat_id == 'tr' && str_replace('/frontend_dev.php', '', parse_url($request->getReferer(), PHP_URL_PATH)) == '/electrical-transformers/select') {
         /*
          * See if user has stored voltages in session (they should unless an error occured).
          * Use these instead of DB values since the selection tool allows for reversing 
          * input/output voltages.
          */
         if ($this->getUser()->hasAttribute('tr_volt_order')) {
             // session value has form [chosen input]:[chosen output]
             $volts = explode(':', $this->getUser()->getAttribute('tr_volt_order'));
             //print_r($volts); die();
             // Remember that TRPart (and all Part DAO's) uses an Alias to store field values
             $this->param['part']['Primary Voltage'] = $volts[0];
             $this->param['part']['Secondary Voltage'] = $volts[1];
             // removing these does not allow the user to move back and forth in the selection tool
             //$this->getUser()->getAttributeHolder()->remove('tr_volt_order');
         }
     }
     /*
      * Two options for dealing with lowercase part numbers in URLs:
      * A:  Just throw a 404 for these requests
      * B:  Show the page, but use a <link> canonical tag
      */
     $this->forward404Unless($part_no == strtoupper($part_no));
     // Option A
     /* B:
       	if($part_no != strtoupper($part_no)) {
       		$pn = $request->getParameter('part_no');
       		$url = str_replace($pn, strtoupper($pn), $request->getUri());
       		$this->getResponse()->setSlot('links', "<link rel='canonical' href='{$url}' />");
       	}
       	*/
     $this->forward404Unless($this->param['part']);
     $this->param['part']['part_no'] = $part_no;
     $this->param['part']['db_fields'] = $part->getDbFields();
     $this->param['h1Txt'] = $part->getH1Txt();
     $this->param['store'] = $part->getPricing();
     $this->param['category'] = LWS::getCategoryName($cat_slug);
     $this->param['manuf_route'] = $cat_id . '_manuf';
     /*
      * doing this for now since changing the route's name would involve updating more files
      * this is necessary because at some point adam wanted to change 'transformers'
      * to 'electrical-transformers'.  should clean it up later to remove this conditional statement.
      */
     $this->param['cat_route'] = str_replace('-', '_', $cat_slug);
     $this->param['meta_keywords'] = $part->getMetaKeywords();
     $this->param['shipping_needed'] = $this->param['store'] != 'emptyStore' && $cat_id == 'cb' ? true : false;
     $response = $this->getResponse();
     $response->setSlot('body_class', 'part');
     $response->setSlot('body_id', str_replace('-', '_', $cat_slug));
     $response->setTitle($part->getPageTitle());
     return sfView::SUCCESS;
 }