public function prepareData() { parent::prepareData(); $this->wellId = CoreServices2::getRequest()->getFromPost('wellId'); $this->wellType = CoreServices2::getRequest()->getFromPost('wellType'); $this->wellPoints = CoreServices2::getRequest()->getFromPost('wellPoints'); $this->messageManager = new CoreFormValidationMessageContainer(); CoreServices2::getDB()->transactionStart(); if (!$this->hasUserPermissionsForRecord()) { $this->messageManager->addMessage('fileDeleteErrorNoPermission'); return; } $pointsData = json_decode($this->wellPoints); foreach ($pointsData as $key => $pointData) { if ($pointData == "") { return false; } $keyValue = explode("_", $key); if ($keyValue[1] != "rowOrder") { $wellPoints[$keyValue[2]][$keyValue[1]] = $pointData; } else { $pointsOrder = explode(',', $pointData); } } // find old points connectet with welll $well3dDAO = new Well3DPointDAO(); $oldPoints = $well3dDAO->getWellPointsByWellId($this->wellId); // delete old points if (!empty($oldPoints)) { foreach ($oldPoints as $point) { $well3dDAO->delete($point); } } $pointsCounter = 1; foreach ($pointsOrder as $order) { // save new points into table $recordTemplate = $well3dDAO->getRecordTemplate(); $recordTemplate['wellId'] = $this->wellId; $recordTemplate['number'] = $pointsCounter; $recordTemplate['X'] = $wellPoints[$order]['X']; $recordTemplate['Y'] = $wellPoints[$order]['Y']; $recordTemplate['Z'] = $wellPoints[$order]['Z']; $recordTemplate['LP'] = $wellPoints[$order]['LP']; $recordTemplate['alfa'] = $wellPoints[$order]['alfa']; $recordTemplate['beta'] = $wellPoints[$order]['beta']; $well3dDAO->save($recordTemplate); $pointsCounter++; } CoreServices2::getDB()->transactionCommit(); }
protected function afterSave() { // save 3D points $well3DPints = $this->form->getField('well3DPints')->getValue(); $pointsData = json_decode(str_replace('"', '"', $well3DPints), true); if (!empty($pointsData)) { foreach ($pointsData as $key => $pointData) { if ($pointData == "") { return false; } $keyValue = explode("_", $key); if ($keyValue[1] != "rowOrder") { $wellPoints[$keyValue[2]][$keyValue[1]] = $pointData; } else { $pointsOrder = explode(',', $pointData); } } // find old points connectet with welll $well3dDAO = new Well3DPointDAO(); $oldPoints = $well3dDAO->getWellPointsByWellId($this->record['id']); // delete old points if (!empty($oldPoints)) { foreach ($oldPoints as $point) { $well3dDAO->delete($point); } } $pointsCounter = 1; foreach ($pointsOrder as $order) { // save new points into table $recordTemplate = $well3dDAO->getRecordTemplate(); $recordTemplate['wellId'] = $this->record['id']; $recordTemplate['number'] = $pointsCounter; $recordTemplate['X'] = $wellPoints[$order]['X']; $recordTemplate['Y'] = $wellPoints[$order]['Y']; $recordTemplate['Z'] = $wellPoints[$order]['Z']; $recordTemplate['LP'] = $wellPoints[$order]['LP']; $recordTemplate['alfa'] = $wellPoints[$order]['alfa']; $recordTemplate['beta'] = $wellPoints[$order]['beta']; $well3dDAO->save($recordTemplate); $pointsCounter++; } } }