public function selectAction() { $request = new \Phalcon\Http\Request(); $response = new \Phalcon\Http\Response(); $previousURL = 'mapfile/load'; $data = null; if ($request->isPost() == true) { if ($mapfileData = $this->session->get('mapfileData')) { $excludes = $request->getPost('exclude', null); $excludes = $excludes ? $excludes : array(); //Check if all layers are unique after excluding some of them $layers = array(); $layerNames = array(); foreach ($mapfileData['notDistinctLayers'] as $notDistinctLayer) { if (!array_key_exists($notDistinctLayer['id'], $excludes)) { if (in_array($notDistinctLayer['name'], $layerNames)) { //Some layers are still duplicated so we redirect to the previous page $this->flashSession->error('Des couches sont toujours en double.'); return $response->redirect($previousURL); } else { $layers[] = $notDistinctLayer; $layerNames[] = $notDistinctLayer['name']; } } } foreach ($mapfileData['distinctLayers'] as $distinctLayer) { if (!array_key_exists($distinctLayer['id'], $excludes)) { $layers[] = $distinctLayer; } } //Identify the layers that exist already and their group $existingLayers = array(); $newLayers = array(); foreach ($layers as $layer) { $layerQuery = 'mf_layer_name="' . $layer['name'] . '"'; $igoLayer = IgoCouche::findFirst($layerQuery); $layer['currentGroup'] = null; $layer['selectClass'] = null; if (!$igoLayer) { $layer['exists'] = false; // Quelques couches n'ont pas de wms_group_title... utiliser le GROUP dans ces rare cas. if (!isset($layer['wms_group_title']) || strlen($layer['wms_group_title']) == 0) { $layer['wms_group_title'] = $layer['group']; } $newLayers[] = $layer; } else { $layer['exists'] = true; $existingLayers[] = $layer; } } //Find all the possible groups $groups = array(); foreach (IgoGroupe::getNomsComplet(true) as $group) { $groups[] = $group->nom; } //Store some data into the session $data = array('existingLayers' => $existingLayers, 'newLayers' => $newLayers, 'groups' => $groups); $this->session->set('selectData', $data); } } else { if ($this->session->get('selectData')) { $data = $this->session->get('selectData'); } } if ($data) { $this->view->setVar("layers", array_merge($data['newLayers'], $data['existingLayers'])); $this->view->setVar("nNewLayers", count($data['newLayers'])); $this->view->setVar("nExistingLayers", count($data['existingLayers'])); $this->view->setVar("groups", $data['groups']); } else { return $response->redirect($this->cancelURL); } }