public function indexAction() { $branch_order = 0; $branch = new PAP_Model_Branch(); $form = new PAP_Form_BranchForm(); $this->view->form = $form; //$user = $this->_helper->Session->getUserSession(); $comboProvinces = $form->getElement('province'); $this->loadProvinces($comboProvinces); $comboProvinces->setAttrib('onChange', 'loadCities();'); $comboCities = $form->getElement('city'); $branchMapper = new PAP_Model_BranchMapper(); $branchMapper->findByUserId($this->user, $branch_order, $branch); if ($this->getRequest()->isPost()) { if ($form->isValidPartial($_POST)) { $data = $form->getValues(); $branch = $this->saveBranch($data, 'update'); $this->loadForm($branch, 'update'); $this->loadCities($comboCities, $branch->getProvince(), $branch->getCity()); } } else { if (isset($branch)) { $this->loadProvinces($comboProvinces, $branch->getProvince()); $this->loadCities($comboCities, $branch->getProvince(), $branch->getCity()); $this->loadForm($branch, 'update'); $this->_helper->Session->setBranchSession($branch); } else { $form->name->setValue($this->user->getName()); $form->user->setValue($this->user->getId()); $form->email->setValue($this->user->getEmail()); } } }
public function getBranches() { $branches = array(); $branchMapper = new PAP_Model_BranchMapper(); $branches = $branchMapper->findAllByUserId($this); return $branches; }
public function getBranches($promotion_id) { $promotionBrancheTable = new PAP_Model_DbTable_PromotionBranch(); $select = $promotionBrancheTable->select(); $select->where('promotion_id = ?', $promotion_id); $rows = $promotionBrancheTable->fetchAll($select); $branches = array(); $branchMapper = new PAP_Model_BranchMapper(); foreach ($rows as $row) { $branch = new PAP_Model_Branch(); $branchMapper->find($row['branch_id'], $branch); $branches[] = $branch; } return $branches; }
public static function getBranchesByRange($latE, $latO, $lngN, $lngS) { $mapper = new PAP_Model_BranchMapper(); $branches = $mapper->getBranchesByRange($latE, $latO, $lngN, $lngS); return $branches; }
public function getPromotionsByCoords($lat, $lng, $categories = '') { $promomapper = new PAP_Model_PromotionMapper(); $branchmapper = new PAP_Model_BranchMapper(); $kmlat = 0.009003753; $kmlng = 0.01093571; $klat = $kmlat * $this->_radius; $klng = $kmlng * $this->_radius; $latO = $lat - $klat; $latE = $lat + $klat; $lngS = $lng - $klng; $lngN = $lng + $klng; $branches = $branchmapper->getBranchesByRange($latE, $latO, $lngN, $lngS); if (count($branches) == 0) { return array(); } $promotions = $promomapper->getPromotionsByBranches($branches, $categories); $i = 0; foreach ($promotions as $promo) { $plat = $promo['latitude']; $deltalat = ($lat - $plat) * 1000 / $kmlat; $plng = $promo['longitude']; $deltalng = ($lng - $plng) * 1000 / $kmlng; $distance = round(sqrt(pow($deltalat, 2) + pow($deltalng, 2))); $valor = substr($promo['promo_cost'], strrpos($promo['promo_cost'], '-') + 1); $valor = $valor == '0.00' ? 1.0 : floatval($valor); $indiceord = abs($distance * $valor * 1000 / (1 - $distance) + ($valor - 1) * 1000) - 1000; $promotions[$i]['distance'] = $distance; $promotions[$i]['ord'] = $indiceord; if (!isset($promo['path'])) { $promotions[$i]['path'] = $this->getBranchImage($promo['promotion_id']); } unset($promotions[$i]['promo_cost']); $i += 1; } if (count($promotions) != 0) { $promotions = $this->sortPromotions($promotions); } else { if ($this->_radius != 4) { $this->_radius = 4; $promotions = $this->getPromotionsByCoords($lat, $lng, $categories); } } return $promotions; }