Пример #1
0
 public function executeSelect(sfWebRequest $request)
 {
     if ($request->isXmlHttpRequest()) {
         // steps 1-3 requests & restart
         $this->setLayout(false);
         sfProjectConfiguration::getActive()->loadHelpers('Partial');
         $agent = new CircuitBreakerSelectionAgent($request->getGetParameters());
         if ($data = $agent->executeStep()) {
             $partial = 'filter' . ucfirst($request->getParameter('step')) . 'Step';
             $html = get_partial($partial, array('selection' => $request->getParameter($request->getParameter('step'), NULL), 'back_qs' => $data['back_qs'], 'data' => $data['data'], 'results_so_far' => $data['results_so_far'], 'search_params' => $agent->getSearchParameters()));
         } else {
             /*
              * Would only get here if LWS DB is incomplete.
              * In this case we need to use the query string to retrieve the relevant
              * data set from teh DB and then fill in the missing values.
              * 
              * Do not throw 404 from Ajax request, 
              * just send error messgae back to user.
              * 
              * !! I should log the query string in these cases to facilitate
              * updating of DB.
              */
             $html = "<p id='tech_prob'>Sorry, we our experiencing technical difficulties. Please contact technical support at <a href='mailto:webmaster@livewiresupply.com'>webmaster@livewiresupply.com</a></p>";
         }
         $response = $this->getResponse();
         $response->addCacheControlHttpHeader('no-cache');
         $response->setContentType('text/html');
         $response->sendHttpHeaders();
         return $this->renderText($html);
     } else {
         // ONLY FOR VOLTS/LAST STEP, or graceful degradation for non JavaScript enabled browsers
         $this->manuf_slug = LWS::getManufSlug($request->getParameter('manuf_id'));
         $this->manuf = LWS::unslugify($this->manuf_slug, true);
         $template = 'Filter' . ucfirst($request->getParameter('step')) . 'Step';
         $this->selection = $request->getParameter($request->getParameter('step'));
         $agent = new CircuitBreakerSelectionAgent($request->getGetParameters());
         /*
          * $agent would not return data only if LWS DB is incomplete.
          * Sequence of steps dictate that once LWS DB is complete,
          * server should throw a 404.  User may have be url surfing.
          * 
          * !!! be sure to update DB if necessary.
          */
         $this->forward404Unless($this->data = $agent->executeStep());
         if ($request->getParameter('step') == 'volts') {
             $this->redirect("@part?cat_slug=circuit-breakers&manuf_slug={$this->manuf_slug}&part_no=" . LWS::encode($this->data[0]['part']['part_no']));
         } else {
             // remove unecessary ajax 'back a step' query string from end of data array
             unset($this->data['back_qs']);
             $this->results_so_far = $this->data['results_so_far'];
             $this->data = $this->data['data'];
             $this->search_params = $agent->getSearchParameters();
             $response = $this->getResponse();
             $response->setTitle("{$this->manuf} Circuit Breakers Selection Process");
             $response->setSlot('body_class', 'cb_manuf');
             return $template;
         }
     }
 }
 private function filterForAmps()
 {
     $this->_search_parameters['Frame Type'] = $this->_selections['frame'];
     $this->_search_parameters['Poles'] = $this->_selections['poles'];
     $this->_search_parameters['Amperage'] = $amps = rawurldecode($this->_selections['amps']);
     $this->query("\r\n\t\t\t(\r\n\t\t\tSELECT DISTINCT(volts) AS data, 'data' AS label\r\n\t\t\tFROM part\r\n\t\t\tWHERE cat_id='cb' AND manuf_id ={$this->_selections['manuf_id']} AND frame_type='{$this->_selections['frame']}' AND poles='{$this->_selections['poles']}' AND amps='{$amps}' AND volts IS NOT NULL \r\n\t\t\t)\r\n\t\t\tUNION \r\n\t\t\t(\r\n\t\t\tSELECT part.part_no, 'results_so_far' AS label\r\n\t\t\tFROM part\r\n\t\t\tWHERE cat_id='cb' AND manuf_id ={$this->_selections['manuf_id']} AND frame_type='{$this->_selections['frame']}' AND poles='{$this->_selections['poles']}' AND amps='{$amps}' AND volts IS NOT NULL  \r\n\t\t\t)\r\n\t\t\tORDER BY label ASC, data ASC \r\n\t\t");
     if ($this->queryOK()) {
         $this->notifyObserver('default');
         /*
          * Using 1-based counting facilitates corresponding template development.
          * SQL ORDER BY statement dictates 'data' item is first record in result set.
          * Use this first record to initilialize array at 1 instead of 0.
          */
         $row = $this->next();
         $this->_data['data'][1] = array('AT' => $row['data'], 'QS' => "manuf_id={$this->_selections['manuf_id']}&frame={$this->_selections['frame']}&poles={$this->_selections['poles']}&amps={$this->_selections['amps']}&volts=" . rawurlencode($row['data']) . '&step=volts');
         while ($row = $this->next()) {
             if ($row['label'] == 'data') {
                 $this->_data['data'][] = array('AT' => $row['data'], 'QS' => "manuf_id={$this->_selections['manuf_id']}&frame={$this->_selections['frame']}&poles={$this->_selections['poles']}&amps={$this->_selections['amps']}&volts=" . rawurlencode($row['data']) . '&step=volts');
             } else {
                 // should always be at least 1 'result so far' unless LWS DB is incomplete!
                 $this->_data['results_so_far'][] = array('part_no' => $row['data'], 'manuf_slug' => LWS::getManufSlug($this->_selections['manuf_id']));
             }
         }
         $this->_data['back_qs'] = "manuf_id={$this->_selections['manuf_id']}&frame={$this->_selections['frame']}&poles={$this->_selections['poles']}&step=poles";
         return $this->_data;
     } else {
         return NULL;
     }
 }