_db->select(); $select->from($this->pair, array('id', 'name')); $select->where('`type` = ?', App_Product_AbstractObj::UTILITY_POLE); $select->group('specie'); $select->order('sorter'); return $this->_db->fetchPairs($select); } public function getProductParams($ids) { foreach ($ids as &$id) { $id = (string) $id; } $select = $this->_db->select(); $select->from($this->_getPair('DCalculatorParams')); $select->where('`id` IN (?)', $ids); return $this->_db->fetchAssoc($select); } /** * @param array $productsData * @return array */ public function prepareTruckResult($productsData) { return array( 'selfUnload' => $this->_prepareSubTruck($productsData, 'selfUnload'), 'conventional' => $this->_prepareSubTruck($productsData, 'conventional') ); } protected function _prepareSubTruck($products, $trackKey) { $items = array(); $productObj = new App_Product_Obj(); foreach ($products as $i => $input) { //product id - $input['specie'] $productObj->setPrimaryKey($input['specie']); $productData = $productObj->clearData()->getData(); $trackParams = array( 'weight' => (float) App_Settings_Obj::get($trackKey . 'Weight'), 'meter' => (float) $productData[$trackKey . 'Meter'], 'foot' => (float) $productData[$trackKey . 'Foot'] ); $params = array('weight', 'meter', 'foot'); $item = array(); foreach ($params as $param) { $item['truckCount'][$param] = ceil($input['productSum'][$param] / $trackParams[$param]); } bcscale(self::BC_SCALE); $item['truckCount'] = max($item['truckCount']); foreach ($params as $param) { if ($input['productSum'][$param]) { $paramDiff = bcsub(bcmul($item['truckCount'], $trackParams[$param]), $input['productSum'][$param]); $item['add'][$param] = floor(bcdiv($paramDiff, $input['productSum']['max' . ucFirst($param)])); } } $item['add'] = min($item['add']); $item['specieName'] = $productData['name']; $item['totalWeight'] = $input['productSum']['weight']; foreach ($params as $param) { $item[$param] = $trackParams[$param]; } $items[$i] = $item; } return $items; } protected function _getProductObj() { } protected function _getTrackParams($trackKey, $productId) { $productObj = new App_Product_Obj(); $productObj->setPrimaryKey($productId); $productData = $productObj->getData(); return array( 'weight' => (float) App_Settings_Obj::get($trackKey . 'Weight'), 'meter' => (float) $productData[$trackKey . 'Meter'], 'foot' => (float) $productData[$trackKey . 'Foot'] ); } public function getProducts($productId, $class) { $this->setPrimaryKey($productId); $specie = $this->getData('specie'); $select = $this->_db->select(); $select->from($this->_getPair('DCalculatorParams')); if ($specie) { $select->where('`DCalculatorParams`.`id` LIKE "%' . $specie . $class . '%"'); } else { $select->where('`DCalculatorParams`.`id` REGEXP "^([0-9, H])"'); $select->where('`DCalculatorParams`.`id` LIKE "%' . $class . '%"'); } $select->order('id'); $products = $this->_db->fetchAll($select); return $this->_parseParams($products); } protected function _parseParams($products) { $specie = $this->getData('specie'); $productsParams = array(); foreach ($products as $product) { if (substr($product['id'], 0, 3) == self::DOUG_RATE) { continue; } $classLength = substr($product['id'], strlen($specie)); if (substr($classLength, 0, 1) == self::SYMBOL_CLASS_BEGIN || substr($classLength, 0, 2) == self::DOUBLE_CLASS) { $class = substr($classLength, 0, 2); $length = substr($classLength, 2); } else { $class = substr($classLength, 0, 1); $length = substr($classLength, 1); } $productsParams['classVal'][$class] = $class; $productsParams['lengthVal'][$length] = $length; } asort($productsParams['classVal']); arsort($productsParams['lengthVal']); return $productsParams; } }