public function prepareData()
 {
     parent::prepareData();
     $this->id = CoreServices::get('request')->getFromGet('id');
     $this->query = CoreServices::get('request')->getFromGet('query');
     $this->dao = new UserDAO();
     if ($this->query) {
         $this->initRows();
     } elseif ($this->id) {
         $this->initName();
     }
 }
 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();
 }
 public function prepareData()
 {
     parent::prepareData();
     $this->initForm();
     $this->createFormFields();
     $this->setFieldValuesFromRequest();
     $request = CoreServices::get('request');
     $this->A = $this->form->getField('A')->getValue();
     $this->H = $this->form->getField('H')->getValue();
     $this->L1 = $this->form->getField('L1')->getValue();
     $this->DLS = $this->form->getField('DLS')->getValue();
     $this->DLS2 = $this->form->getField('DLS2')->getValue();
     $this->alfa2 = $this->form->getField('alfa2')->getValue();
     $this->L3 = $this->form->getField('L3')->getValue();
     $this->Azimuth = $this->form->getField('Azimuth')->getValue();
     $this->targetInclination = $this->form->getField('targetInclination')->getValue();
     $this->targetAzimuth = $this->form->getField('targetAzimuth')->getValue();
     $this->TR = $this->form->getField('TR')->getValue();
     $this->TL = $this->form->getField('TL')->getValue();
     $this->BR = $this->form->getField('BR')->getValue();
     $this->BL = $this->form->getField('BL')->getValue();
     $this->SR = $this->form->getField('SR')->getValue();
     $this->ST = $this->form->getField('ST')->getValue();
     $this->SM = $this->form->getField('SM')->getValue();
     $this->NOS = $this->form->getField('NOS')->getValue();
     $this->DeltaX = $this->form->getField('DeltaX')->getValue();
     $this->DeltaY = $this->form->getField('DeltaY')->getValue();
     $this->Variant = $this->form->getField('Variant')->getValue();
     $this->Name = $this->form->getField('Name')->getValue();
     $this->siteId = $this->form->getField('SiteId')->getValue();
     if (empty($this->Name)) {
         $this->Name = "Pads";
     }
     if (empty($this->Variant)) {
         throw new Exception("No Trajectory Variant");
     }
     $wellDAO = new WellDAO();
     $well3dpointDAO = new Well3DPointDAO();
     $well = $wellDAO->getRecordTemplate();
     $well['A'] = $this->A;
     $well['H'] = $this->H;
     $well['L1'] = $this->L1;
     $well['DLS'] = $this->DLS;
     $well['DLS2'] = $this->DLS2;
     $well['alfa2'] = $this->alfa2;
     $well['L3'] = $this->L3;
     $well['wellName'] = $this->Name . " W0";
     $well['siteId'] = $this->siteId;
     $well['wellType'] = '2d';
     $well['wellTrajectory'] = "J2";
     $well['wellTrajectoryVariant'] = $this->Variant;
     $wellDAO->save($well);
     $this->trajectory = new TrajectoryVariant();
     $algoritm = new TrajectoryAlgoritm();
     $trajectoryMethod = $this->Variant;
     $methodParameters = array();
     $parameters = explode("_", $this->Variant);
     array_shift($parameters);
     foreach ($parameters as $parameter) {
         $methodParameters[$parameter] = $well[$parameter];
     }
     $this->trajectoryParams = call_user_func_array(array($this->trajectory, $trajectoryMethod), $methodParameters);
     if (!empty($this->trajectoryParams['error'])) {
         //$this->errorMessageContainer = new CoreFormValidationMessageContainer();
         //$this->errorMessageContainer->addMessage('parametrError');
         return 0;
         //!!!!!
     }
     //print_r($this->trajectoryParams);
     $sectionNumber = 3;
     $step = 10;
     $azimut = 0;
     $this->trajectoryTable = $algoritm->calculateCoordinates($sectionNumber, $this->trajectoryParams['A'], $this->trajectoryParams['H'], $this->trajectoryParams['L'], $this->trajectoryParams['alfa'], $this->trajectoryParams['delta'], $this->trajectoryParams['DLS'], $this->trajectoryParams['R'], $azimut, $step);
     //print_r($this->trajectoryTable);
     $firstElements = array_values($this->trajectoryTable);
     $firstElement = $firstElements[0];
     $trayectoryTableLenght = count($this->trajectoryTable);
     $section = $firstElement['section'];
     $hpoints[] = $firstElement;
     $counter = 1;
     foreach ($this->trajectoryTable as $point) {
         if ($point['section'] == 'PP' || $section != $point['section'] && $section != 'PP' || $counter == $trayectoryTableLenght) {
             $section = $point['section'];
             $hpoints[] = $point;
         }
         $counter++;
     }
     //print_r($hpoints);
     if ($this->TR == 'true') {
         // In loop create
         // 1. well 3d with R3Konc
         // 2. calulate points W, HP, TP
         // 3. save well & points
         if ($this->NOS > 0) {
             for ($i = 1; $i <= $this->NOS; $i++) {
                 $padWell = $wellDAO->getRecordTemplate();
                 $padWell['wellName'] = $this->Name . "_W" . $i . "R";
                 $padWell['wellType'] = '3d';
                 $padWell['well3DTrajectory'] = "KONC";
                 $padWell['siteId'] = $this->siteId;
                 $wellDAO->save($padWell);
                 $srSum = $i * $this->SR;
                 $stSum = $i * $this->ST;
                 $BOPX = $firstElement['X'] + $srSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $BOPY = $firstElement['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $HPX = $hpoints[2]['X'] + $stSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $HPY = $hpoints[2]['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $TPX = $hpoints[3]['X'] + $stSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $TPY = $hpoints[3]['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 1;
                 $well3dpoint['X'] = $BOPX;
                 $well3dpoint['Y'] = $BOPY;
                 $well3dpoint['Z'] = 0;
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 2;
                 $well3dpoint['X'] = $HPX;
                 $well3dpoint['Y'] = $HPY;
                 $well3dpoint['Z'] = $hpoints[2]['Z'];
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 3;
                 $well3dpoint['X'] = $TPX;
                 $well3dpoint['Y'] = $TPY;
                 $well3dpoint['Z'] = $hpoints[3]['Z'];
                 $well3dpoint['alfa'] = $this->targetInclination;
                 $well3dpoint['beta'] = $this->targetAzimuth;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
             }
         }
     }
     if ($this->TL == 'true') {
         if ($this->NOS > 0) {
             for ($i = 1; $i <= $this->NOS; $i++) {
                 $padWell = $wellDAO->getRecordTemplate();
                 $padWell['wellName'] = $this->Name . "_W" . $i . "L";
                 $padWell['wellType'] = '3d';
                 $padWell['well3DTrajectory'] = "KONC";
                 $padWell['siteId'] = $this->siteId;
                 $wellDAO->save($padWell);
                 $srSum = $i * $this->SR;
                 $stSum = $i * $this->ST;
                 $BOPX = $firstElement['X'] - $srSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $BOPY = $firstElement['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $HPX = $hpoints[2]['X'] - $stSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $HPY = $hpoints[2]['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $TPX = $hpoints[3]['X'] - $stSum * cos($this->Azimuth * Pi() / 180) + $this->DeltaX;
                 $TPY = $hpoints[3]['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $this->DeltaY;
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 1;
                 $well3dpoint['X'] = $BOPX;
                 $well3dpoint['Y'] = $BOPY;
                 $well3dpoint['Z'] = 0;
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 2;
                 $well3dpoint['X'] = $HPX;
                 $well3dpoint['Y'] = $HPY;
                 $well3dpoint['Z'] = $hpoints[2]['Z'];
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 3;
                 $well3dpoint['X'] = $TPX;
                 $well3dpoint['Y'] = $TPY;
                 $well3dpoint['Z'] = $hpoints[3]['Z'];
                 $well3dpoint['alfa'] = $this->targetInclination;
                 $well3dpoint['beta'] = $this->targetAzimuth;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
             }
         }
     }
     if ($this->BR == 'true') {
         if ($this->NOS > 0) {
             for ($i = 1; $i <= $this->NOS; $i++) {
                 $this->Azimuth = $this->Azimuth + 180;
                 $padWell = $wellDAO->getRecordTemplate();
                 $padWell['wellName'] = $this->Name . "_W" . $i . "MR";
                 $padWell['wellType'] = '3d';
                 $padWell['well3DTrajectory'] = "KONC";
                 $padWell['siteId'] = $this->siteId;
                 $wellDAO->save($padWell);
                 $srSum = $i * $this->SR;
                 $stSum = $i * $this->ST;
                 $DeltaX = $this->DeltaX + $this->SM * sin($this->Azimuth * pi() / 180);
                 $DeltaY = $this->DeltaY + $this->SM * sin($this->Azimuth * pi() / 180);
                 $BOPX = $firstElement['X'] + $srSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $BOPY = $firstElement['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $HPX = $hpoints[2]['X'] + $stSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $HPY = $hpoints[2]['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $TPX = $hpoints[3]['X'] + $stSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $TPY = $hpoints[3]['Y'] - $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 1;
                 $well3dpoint['X'] = $BOPX;
                 $well3dpoint['Y'] = $BOPY;
                 $well3dpoint['Z'] = 0;
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 2;
                 $well3dpoint['X'] = $HPX;
                 $well3dpoint['Y'] = $HPY;
                 $well3dpoint['Z'] = $hpoints[2]['Z'];
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 3;
                 $well3dpoint['X'] = $TPX;
                 $well3dpoint['Y'] = $TPY;
                 $well3dpoint['Z'] = $hpoints[3]['Z'];
                 $well3dpoint['alfa'] = $this->targetInclination;
                 $well3dpoint['beta'] = $this->targetAzimuth;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
             }
         }
     }
     if ($this->BL == 'true') {
         if ($this->NOS > 0) {
             for ($i = 1; $i <= $this->NOS; $i++) {
                 $this->Azimuth = $this->Azimuth + 180;
                 $padWell = $wellDAO->getRecordTemplate();
                 $padWell['wellName'] = $this->Name . "_W" . $i . "ML";
                 $padWell['wellType'] = '3d';
                 $padWell['well3DTrajectory'] = "KONC";
                 $padWell['siteId'] = $this->siteId;
                 $wellDAO->save($padWell);
                 $srSum = $i * $this->SR;
                 $stSum = $i * $this->ST;
                 $DeltaX = $this->DeltaX + $this->SM * sin($this->Azimuth * pi() / 180);
                 $DeltaY = $this->DeltaY + $this->SM * sin($this->Azimuth * pi() / 180);
                 $BOPX = $firstElement['X'] - $srSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $BOPY = $firstElement['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $HPX = $hpoints[2]['X'] - $stSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $HPY = $hpoints[2]['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $TPX = $hpoints[3]['X'] - $stSum * cos($this->Azimuth * Pi() / 180) + $DeltaX;
                 $TPY = $hpoints[3]['Y'] + $srSum * sin($this->Azimuth * Pi() / 180) + $DeltaY;
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 1;
                 $well3dpoint['X'] = $BOPX;
                 $well3dpoint['Y'] = $BOPY;
                 $well3dpoint['Z'] = 0;
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 2;
                 $well3dpoint['X'] = $HPX;
                 $well3dpoint['Y'] = $HPY;
                 $well3dpoint['Z'] = $hpoints[2]['Z'];
                 $well3dpoint['alfa'] = 0;
                 $well3dpoint['beta'] = 0;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
                 $well3dpoint = $well3dpointDAO->getRecordTemplate();
                 $well3dpoint['wellId'] = $padWell['id'];
                 $well3dpoint['number'] = 3;
                 $well3dpoint['X'] = $TPX;
                 $well3dpoint['Y'] = $TPY;
                 $well3dpoint['Z'] = $hpoints[3]['Z'];
                 $well3dpoint['alfa'] = $this->targetInclination;
                 $well3dpoint['beta'] = $this->targetAzimuth;
                 $well3dpoint['LP'] = 0;
                 $well3dpointDAO->save($well3dpoint);
             }
         }
     }
     // +add slot to DB
     // +calculate trajectory
     // +get points 0, HP, TP
     // calculate additional trajectories points
     // create
 }