'Process_'), array('type' => 'default'), 'url') . '?action=viewResults&id=%d&partId=%d&setId=%d'; $urlParams = array('processId', 'partId', 'setId'); if ($this->_getDataObj()->getFilter('currentRevision') != 'y') { $url .= '&revisionId=%d'; $urlParams[] = 'versionId'; } $linkColumnOptions = array( 'text' => 'View', 'title' => 'View', 'urlParams' => $urlParams, 'linkAttribs' => array('target' => '_blank'), 'url' => $url) ; $list->addColumn('text', 'processName', array('title' => 'Process Name', 'orderBy' => 'processName')); $list->addColumn('text', 'partNumber', array('title' => 'Part Number', 'orderBy' => 'partNumber')); $list->addColumn('text', 'partName', array('title' => 'Part Name', 'orderBy' => 'partName')); $suffix = ''; if ($this->_getDataObj()->getFilter('currentRevision') == 'y') { $suffix = 'Current'; } $list->addColumn('text', 'revision' . $suffix , array('title' => 'Revision', 'orderBy' => 'revision' . $suffix )); $list->addColumn('date', 'revisionDate' . $suffix , array('title' => 'Revision Date', 'orderBy' => 'revisionDate' . $suffix , 'format' => '%B %d, %y')); $list->addColumn('text', 'element', array('title' => 'Element', 'orderBy' => 'element')); $list->addColumn('link_advanced', 'link', $linkColumnOptions); return $this; } protected function _bindFilterFields(Qs_Form $form) { parent::_bindFilterFields($form); $form->addElement('text', 'partNumber', array('label' => 'Part Number')); $form->addElement('text', 'element', array('label' => 'Element')); $form->addElement('text', 'process', array('label' => 'Process')); $form->addElement('checkbox', 'currentRevision', array('label' => 'Current Revision Only')); return $this; } protected function _addListItem($list = null, $template = 'list.tpl') { if ($this->_getDataObj()->getFilter('query')) { if (null == $list) { $list = $this->list; } if ($this->list->getItemsCount()) { $params = array_merge( $this->_getDataObj()->getFilter(), array('orderBy' => Qs_Request::getGetValue('orderBy')) ); $item = array( 'url' => $this->url(array_merge(array('action' => 'pdf'), $params)), 'csvUrl' => $this->url(array_merge(array('action' => 'csv'), $params)), 'tpl' => $this->getTemplate('pdfLink.tpl') ); $this->_addItem($item); } parent::_addListItem($list, $template); } return $this; } protected function _doPdf() { $form = $this->_getFilterForm(); if ($form->validate()) { $filter = $form->getValues(); $this->dataObj->addFilter($filter); if ($filter['query']) { $filter['action'] = 'pdfTpl'; $filter['orderBy'] = Qs_Request::getGetValue('orderBy'); //'Search result for AMS-A-21180|Part Number 250D00120-2| Search for element values and labels $title = 'Search result for ' . $filter['query'] . ($filter['partNumber'] ? (' | Part Number ' . $filter['partNumber']) : '') . ($filter['element'] ? (' | Element ' . $filter['element']) : ''); $options = array('pageHeader' => $title); $file = App_Pdf_Renderer::render($this->url($filter), $title, $options); $this->_sendTempFile($file, 'search_results'); } } return $this; } protected function _doPdfTpl() { $this->_doc->setTemplatePath(array('PrintDoc', 'Doc')); $this->_setTemplatePath(array('Search/Tool/Pdf', 'Search/Tool', 'ViewController')); $form = $this->_getFilterForm(); if ($form->validate()) { $filter = $form->getValues(); $this->dataObj->addFilter($filter); if ($filter['query']) { $this->_listOptions = array('ipp' => 1000 * 1000); parent::_addListItem(); } } return $this; } protected function _doCsv() { $form = $this->_getFilterForm(); if ($form->validate()) { $this->dataObj->addFilter($form->getValues()); } $options = array(); $options['order'] = array($this->list->getOrderBy()); $stmt = $this->dataObj->getListStatement($options); $fp = fopen('php://output', 'w'); ; header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-type: text/comma-separated-values'); header('Content-Disposition: attachment; filename="Search Results ' . date('M d Y g:i A') . '.csv' . '"'); $columns = array( 'processName' => 'Process Name', 'partNumber' => 'Part Number', 'partName' => 'Part Name', 'revision' => 'Revision', 'revisionDate' => 'Revision Date', 'element' => 'Element' ); fputcsv($fp, $columns); $blankRow = array_combine(array_keys($columns), array_fill(0, count($columns), '')); while ($row = $stmt->fetch()) { $row = str_replace(array("\n", "\r"), ' ', $row); $row = array_intersect_key($row, $columns); $row = array_merge($blankRow, $row); fputcsv($fp, $row); } fclose($fp); exit; } }