protected function initProject()
 {
     $projectDAO = new ProjectDAO();
     $siteDAO = new SiteDAO();
     $wellDAO = new WellDAO();
     foreach ($this->company as $company) {
         $this->project[$company['id']] = $projectDAO->getProjectByCompanyIdAndUserId($company['id'], $this->currentUser['id']);
         foreach ($this->project[$company['id']] as $project) {
             $this->site[$project['id']] = $siteDAO->getSiteByProjectIdAndUserId($project['id'], $this->currentUser['id']);
             foreach ($this->site[$project['id']] as $site) {
                 $this->well[$site['id']] = $wellDAO->getWellBySiteIdAndUserId($site['id'], $this->currentUser['id']);
             }
         }
     }
     //print_r($this->project);
     //print_r($this->site);
 }
 protected function getMenuData()
 {
     if (!empty($this->record['id'])) {
         $this->pagePath = $this->dao->getRecordPath($this->record['id']);
     } else {
         $daoClass = $this->getDAOClass();
         if ($daoClass == 'CompanyDAO') {
             $this->pagePath['companyName'] = 'New Comapny';
             $this->pagePath['comanyId'] = 0;
         } elseif ($daoClass == 'ProjectDAO') {
             $comapanyId = CoreServices2::getRequest()->getFromGet('comp');
             if (!empty($comapanyId)) {
                 $companyDAO = new CompanyDAO();
                 $this->pagePath = $companyDAO->getRecordPath($comapanyId);
             }
             $this->pagePath['projectName'] = 'New Project';
             $this->pagePath['projectId'] = 0;
         } elseif ($daoClass == 'SiteDAO') {
             $projectId = CoreServices2::getRequest()->getFromGet('proj');
             if (!empty($projectId)) {
                 $projectDAO = new ProjectDAO();
                 $this->pagePath = $projectDAO->getRecordPath($projectId);
             }
             $this->pagePath['siteName'] = 'New Site';
             $this->pagePath['siteId'] = 0;
         } elseif ($daoClass == 'WellDAO') {
             $siteId = CoreServices2::getRequest()->getFromGet('site');
             if (!empty($siteId)) {
                 $siteDAO = new SiteDAO();
                 $this->pagePath = $siteDAO->getRecordPath($siteId);
             }
             $this->pagePath['wellName'] = 'New Well';
             $this->pagePath['wellId'] = 0;
         }
     }
 }
Example #3
0
 /**
  * Delete the given NGI and cascade delete all of the NGI's child entities. 
  * These include Sites, Services, EndpointLocations, Downtimes that will be 
  * orphaned, CertificationStatusLogs and Roles that previously linked to the 
  * deleted owned entities. 
  *  
  * @param \NGI $ngi
  * @param \User $user - must be an admin user 
  * @param boolean $logNgiSiteServiceInArchives Record the deletion of the ngi, 
  * its child sites and services in the archive tables. 
  * @throws \org\gocdb\services\Exception
  */
 public function deleteNgi(\NGI $ngi, \User $user = null, $logNgiSiteServiceInArchives = true)
 {
     require_once __DIR__ . '/../DAOs/SiteDAO.php';
     require_once __DIR__ . '/../DAOs/ServiceDAO.php';
     require_once __DIR__ . '/../DAOs/NGIDAO.php';
     require_once __DIR__ . '/ServiceService.php';
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     //Throws exception if user is not an administrator
     $this->checkUserIsAdmin($user);
     $this->em->getConnection()->beginTransaction();
     try {
         $ngiDAO = new \NGIDAO();
         $ngiDAO->setEntityManager($this->em);
         $siteDAO = new \SiteDAO();
         $siteDAO->setEntityManager($this->em);
         $serviceDAO = new \ServiceDAO();
         $serviceDAO->setEntityManager($this->em);
         //Archive ngi
         if ($logNgiSiteServiceInArchives) {
             $ngiDAO->addNGIToArchive($ngi, $user);
         }
         //delete each child site
         foreach ($ngi->getSites() as $site) {
             //Archive site
             if ($logNgiSiteServiceInArchives) {
                 $siteDAO->addSiteToArchive($site, $user);
             }
             //delete each child service
             foreach ($site->getServices() as $service) {
                 //archive the srvice
                 if ($logNgiSiteServiceInArchives) {
                     $serviceDAO->addServiceToArchive($service, $user);
                 }
                 //remove the service (and any downtimes only associated with it)
                 $serviceDAO->removeService($service);
             }
             //remove the site
             $siteDAO->removeSite($site);
         }
         //remove the NGI
         $ngiDAO->removeNGI($ngi);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }
 /**
  * Delete both Services but not the ngi  
  * @see testRolesCascadeDelete_OnOwnedEntityDeletion1
  */
 public function testRolesCascadeDelete_OnOwnedEntityDeletion2()
 {
     print __METHOD__ . "\n";
     include __DIR__ . '/resources/sampleFixtureData1.php';
     $siteDAO = new SiteDAO();
     $serviceDAO = new ServiceDAO();
     $ngiDAO = new NGIDAO();
     $siteDAO->setEntityManager($this->em);
     $serviceDAO->setEntityManager($this->em);
     $ngiDAO->setEntityManager($this->em);
     // ordering of removal is NOT significant here !
     $serviceDAO->removeService($service1);
     $serviceDAO->removeService($service2);
     $siteDAO->removeSite($site1);
     $siteDAO->removeSite($site2);
     //$ngiDAO->removeNGI($ngi); // don't remove NGI
     $this->em->flush();
     // Need to clear the identity map (all objects become detached) so that
     // when we re-fetch the user, it will be looked from db not served by entity map
     $this->em->clear();
     // Need to re-fetch the user from the DB again, if don't, then user already
     // has his eargerly fetched roles present in UserProxy object
     $userWithRoles = $this->em->find("User", $userId);
     // user should have 2 remaining roles still from ngi
     $this->assertEquals(2, count($userWithRoles->getRoles()));
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Roles");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM NGIs");
     $this->assertTrue($result->getRowCount() == 1);
 }
 public function testCertStatusLogDeleted_OnSiteDeletion()
 {
     print __METHOD__ . "\n";
     include __DIR__ . '/resources/sampleFixtureData1.php';
     // delete site2 - the certStatusLogs
     $siteDAO = new SiteDAO();
     $siteDAO->setEntityManager($this->em);
     $siteDAO->removeSite($site2);
     $this->em->flush();
     // Need to clear the identity map (all objects become detached) so that
     // when we re-fetch the user, it will be looked from db not served by entity map
     $this->em->clear();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Sites");
     $this->assertTrue($result->getRowCount() == 1);
     // site1 not deleted
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM CertificationStatusLogs");
     $this->assertTrue($result->getRowCount() == 0);
 }