Example #1
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('sg', 'r', 'u', 'rt')->from('ServiceGroup', 'sg')->leftJoin('sg.roles', 'r')->leftJoin('r.user', 'u')->leftJoin('r.roleType', 'rt')->orderBy('sg.id', 'ASC');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'ServiceGroup', 'sg');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #2
0
 public function testBuild()
 {
     $builder = new ParameterBuilder();
     $parameters = $builder->setDescription('foobar')->addOption('bar', Parameter::TYPE_REQUIRED, 'bar description')->addOption('foo', Parameter::TYPE_OPTIONAL, 'foo description')->addOption('v', Parameter::TYPE_FLAG, 'verbose')->getParameters();
     $this->assertInstanceOf('PSX\\Command\\Parameters', $parameters);
     $this->assertEquals('foobar', $parameters->getDescription());
     $this->assertEquals(3, count($parameters));
     $this->assertEquals(null, $parameters->get('unknown'));
     $this->assertInstanceOf('PSX\\Command\\Parameter', $parameters[0]);
     $this->assertEquals('bar', $parameters[0]->getName());
     $this->assertEquals(Parameter::TYPE_REQUIRED, $parameters[0]->getType());
     $this->assertEquals('bar description', $parameters[0]->getDescription());
     $this->assertEquals(false, $parameters[0]->hasValue());
     $this->assertEquals(null, $parameters[0]->getValue());
     $this->assertInstanceOf('PSX\\Command\\Parameter', $parameters[1]);
     $this->assertEquals('foo', $parameters[1]->getName());
     $this->assertEquals(Parameter::TYPE_OPTIONAL, $parameters[1]->getType());
     $this->assertEquals('foo description', $parameters[1]->getDescription());
     $this->assertEquals(false, $parameters[1]->hasValue());
     $this->assertEquals(null, $parameters[1]->getValue());
     $this->assertInstanceOf('PSX\\Command\\Parameter', $parameters[2]);
     $this->assertEquals('v', $parameters[2]->getName());
     $this->assertEquals(Parameter::TYPE_FLAG, $parameters[2]->getType());
     $this->assertEquals('verbose', $parameters[2]->getDescription());
     $this->assertEquals(false, $parameters[2]->hasValue());
     $this->assertEquals(null, $parameters[2]->getValue());
     foreach ($parameters as $parameter) {
         $this->assertInstanceOf('PSX\\Command\\Parameter', $parameter);
     }
 }
 /**
  * Tests build().
  *
  * @param string $expectedSignature The expected signature parameters.
  * @param string $expectedBody      The expected body parameters.
  * @param string $function          The function name.
  *
  * @dataProvider provideTestBuild
  * @test
  */
 public function testBuild($expectedSignature, $expectedBody, $function)
 {
     $builder = new ParameterBuilder();
     $builder->build($function);
     $this->assertEquals($expectedBody, $builder->getBodyParameters());
     $this->assertEquals($expectedSignature, $builder->getSignatureParameters());
 }
Example #4
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('n')->from('NGI', 'n')->orderBy('n.id', 'ASC');
     /**This is used to filter the reults at the point
      * of building the XML to only show the correct roletypes.
      * Future work could see this build into the query.
      */
     if (isset($parameters['roletype'])) {
         $this->roleT = $parameters['roletype'];
     } else {
         $this->roleT = '%%';
     }
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #5
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters 
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('s')->from('Site', 's')->join('s.certificationStatus', 'cs')->join('s.ngi', 'n')->leftJoin('s.scopes', 'sc')->join('s.infrastructure', 'i')->andWhere($qb->expr()->like('i.name', '?' . ++$bc))->orderBy('s.id', 'ASC');
     $binds[] = array($bc, 'Production');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     $dql = $qb->getDql();
     //for testing
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #6
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('s')->from('SubGrid', 's')->orderBy('s.id', 'ASC');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #7
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('se', 'sp', 's', 'sc', 'el', 'c', 'n', 'st', 'elp')->from('Service', 'se')->leftjoin('se.parentSite', 's')->leftjoin('s.certificationStatus', 'cs')->leftJoin('s.scopes', 'sc')->leftJoin('se.serviceProperties', 'sp')->leftjoin('se.endpointLocations', 'el')->leftjoin('el.endpointProperties', 'elp')->leftjoin('s.country', 'c')->leftjoin('s.ngi', 'n')->leftjoin('se.serviceType', 'st')->andWhere($qb->expr()->neq('cs.name', '?' . ++$bc))->orderBy('se.id', 'ASC');
     //Add closed parameter to binds
     $binds[] = array($bc, 'Closed');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'Service', 'se');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     /* Pass the properties to the properties class.
      * It will return a query with a clause based on the provided LDAP
      */
     if (isset($parameters['extensions'])) {
         $ExtensionsQueryBuilder = new ExtensionsQueryBuilder($parameters['extensions'], $qb, $this->em, $bc, 'Service');
         //Get the modified query
         $qb = $ExtensionsQueryBuilder->getQB();
         $bc = $ExtensionsQueryBuilder->getBindCount();
         //Get the binds and store them in the local bind array
         foreach ($ExtensionsQueryBuilder->getValuesToBind() as $value) {
             $binds[] = $value;
         }
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     /*
      $dql = $qb->getDql(); //for testing
     $query = $qb->getQuery();
     echo "\n\n\n\n";
     $parameters=$query->getParameters();
     print_r($parameters);
     echo $dql;
     echo "\n\n\n\n";
     */
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #8
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     $qb->select('s', 'sc', 'sp', 'i', 'cs', 'c', 'n', 'sgrid', 'ti')->from('Site', 's')->leftJoin('s.siteProperties', 'sp')->leftJoin('s.scopes', 'sc')->leftJoin('s.ngi', 'n')->leftJoin('s.country', 'c')->leftJoin('s.certificationStatus', 'cs')->leftJoin('s.infrastructure', 'i')->leftJoin('s.subGrid', 'sgrid')->leftJoin('s.tier', 'ti')->orderBy('s.shortName', 'ASC');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'Site', 's');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     /* Pass the properties to the extensions class.
      * It will return a query with a clause based on the provided LDAP style query
      */
     if (isset($parameters['extensions'])) {
         $ExtensionsQueryBuilder = new ExtensionsQueryBuilder($parameters['extensions'], $qb, $this->em, $bc, 'Site');
         //Get the modified query
         $qb = $ExtensionsQueryBuilder->getQB();
         $bc = $ExtensionsQueryBuilder->getBindCount();
         //Get the binds and store them in the local bind array
         foreach ($ExtensionsQueryBuilder->getValuesToBind() as $value) {
             $binds[] = $value;
         }
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     //Testing
     /*
     	$dql = $qb->getDql(); //for testing
     $query = $qb->getQuery();
     echo "\n\n\n\n";
     $parameters=$query->getParameters();
     print_r($parameters);
     echo $dql;
     echo "\n\n\n\n";
     */
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #9
0
 /**
  * Defines the mock function.
  *
  * @SuppressWarnings(PHPMD)
  */
 public function defineFunction()
 {
     $name = $this->mock->getName();
     $parameterBuilder = new ParameterBuilder();
     $parameterBuilder->build($name);
     $data = ["namespace" => $this->mock->getNamespace(), "name" => $name, "fqfn" => $this->mock->getFQFN(), "signatureParameters" => $parameterBuilder->getSignatureParameters(), "bodyParameters" => $parameterBuilder->getBodyParameters()];
     $this->template->setVar($data, false);
     $definition = $this->template->render();
     eval($definition);
 }
Example #10
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('sg', 's', 'st', 'sp', 'sc', 'els', 'elp', 'servp')->from('ServiceGroup', 'sg')->leftJoin('sg.serviceGroupProperties', 'sp')->leftJoin('sg.services', 's')->leftJoin('s.serviceProperties', 'servp')->leftJoin('s.serviceType', 'st')->leftJoin('s.scopes', 'sc')->leftJoin('s.endpointLocations', 'els')->leftjoin('els.endpointProperties', 'elp')->orderBy('sg.id', 'ASC');
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'ServiceGroup', 'sg');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     /* Pass the properties to the extensions class.
      * It will return a query with a clause based on the provided LDAP style query
      */
     if (isset($parameters['extensions'])) {
         $ExtensionsQueryBuilder = new ExtensionsQueryBuilder($parameters['extensions'], $qb, $this->em, $bc, 'ServiceGroup');
         //Get the modified query
         $qb = $ExtensionsQueryBuilder->getQB();
         $bc = $ExtensionsQueryBuilder->getBindCount();
         //Get the binds and store them in the local bind array
         foreach ($ExtensionsQueryBuilder->getValuesToBind() as $value) {
             $binds[] = $value;
         }
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters 
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Main query
     $qb->select('COUNT(c.name) as cCount', 'c.name')->from('Site', 's')->leftJoin('s.scopes', 'sc')->join('s.ngi', 'n')->join('s.country', 'c')->join('s.certificationStatus', 'cs')->join('s.infrastructure', 'i')->groupBy('c.name')->orderBy('c.name');
     //If a scope was specified attach the sub query to query by EGI scope
     if (isset($parameters['scope'])) {
         /**
          * We are using a simplified scope query here that only supports a single scope
          * instead of using the scope-query builder. When using the scope query builder (SQB)
          * the sub query created by the SQB will count sites with more than one scope and this
          * can cause an error in the results. To combat this you can put a distinct within the 
          * select clause: "COUNT (DISTINCT c.name)" and this will fix that issue. However we 
          * still are not using the SQB as this supports comma seperated lists and scope matching
          * which is not supported by the NGI scope sub query. In conclusion this PI query supports
          * only a single scope. 
          */
         $sQ = $this->em->createQueryBuilder();
         $sQ->select('n2')->from('NGI', 'n2')->leftJoin('n2.scopes', 'sqsc2')->where($sQ->expr()->eq('sqsc2.name', '?' . ++$bc));
         $qb->andWhere($qb->expr()->eq('sc.name', '?' . $bc))->andWhere($qb->expr()->in('n', $sQ->getDQL()));
         $binds[] = array($bc, $parameters['scope']);
     }
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters. */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //echo $qb->getDql(); //for testing
     $query[0] = $qb->getQuery();
     $qb = $this->em->createQueryBuilder();
     $qb->select('c.name')->from('Country', 'c')->orderBy('c.name');
     $query[1] = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #12
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('s', 'n', 'r', 'u', 'rt')->from('Site', 's')->leftJoin('s.ngi', 'n')->leftJoin('s.country', 'c')->leftJoin('s.roles', 'r')->leftJoin('r.user', 'u')->leftJoin('r.roleType', 'rt')->orderBy('s.shortName', 'ASC');
     /**This is used to filter the reults at the point
      * of building the XML to only show the correct roletypes.
      * Future work could see this build into the query.
      */
     if (isset($parameters['roletype'])) {
         $this->roleT = $parameters['roletype'];
     } else {
         $this->roleT = '%%';
     }
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'Site', 's');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #13
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters 
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('log', 's')->from('CertificationStatusLog', 'log')->Join('log.parentSite', 's')->Join('s.certificationStatus', 'cs')->leftJoin('s.scopes', 'sc')->Join('s.infrastructure', 'i')->orderBy('log.id', 'ASC');
     if (isset($parameters['enddate'])) {
         $endDate = new \DateTime($parameters['enddate']);
     } else {
         $endDate = null;
     }
     $qb->andWhere($qb->expr()->orX($qb->expr()->isNull('?' . ++$bc), $qb->expr()->gt('log.addedDate', '?' . $bc)));
     $binds[] = array($bc, $endDate);
     if (isset($parameters['startdate'])) {
         $startDate = new \DateTime($parameters['startdate']);
     } else {
         $startDate = null;
     }
     $qb->andWhere($qb->expr()->orX($qb->expr()->isNull('?' . ++$bc), $qb->expr()->lt('log.addedDate', '?' . $bc)));
     $binds[] = array($bc, $startDate);
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     $dql = $qb->getDql();
     //for testing
     //echo $dql;
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #14
0
 public function testFillParametersFlag()
 {
     $builder = new ParameterBuilder();
     $builder->addOption('bar', Parameter::TYPE_FLAG);
     $builder->addOption('test', Parameter::TYPE_FLAG);
     $parser = $this->getParameterParser();
     $parameters = $builder->getParameters();
     $this->assertEquals(null, $parameters->get('bar'));
     $this->assertEquals(false, $parameters->has('bar'));
     $this->assertEquals(null, $parameters->get('test'));
     $this->assertEquals(false, $parameters->has('test'));
     $parser->fillParameters($parameters);
     $this->assertEquals(true, $parameters->get('bar'));
     $this->assertEquals(true, $parameters->has('bar'));
     $this->assertEquals(false, $parameters->get('test'));
     $this->assertEquals(false, $parameters->has('test'));
 }
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters 
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     define('DATE_FORMAT', 'Y-m-d H:i');
     //Set the interval
     if (isset($parameters['interval'])) {
         if (is_numeric($parameters['interval'])) {
             $interval = $parameters['interval'];
         } else {
             echo '<error>interval is not a number</error>';
             die;
         }
     } else {
         // Default: downtimes declared in the last day
         $interval = '1';
     }
     $nowMinusIntervalDays = new \DateTime();
     $nowMinusIntervalDays->sub(new \DateInterval('P' . $interval . 'D'));
     $qb = $this->em->createQueryBuilder();
     $qb->select('d', 'els', 'se', 's', 'st')->from('Downtime', 'd')->join('d.services', 'se')->leftJoin('d.endpointLocations', 'els')->join('se.serviceType', 'st')->join('se.parentSite', 's')->leftJoin('se.scopes', 'sc')->join('s.ngi', 'n')->join('s.country', 'c')->andWhere($qb->expr()->gt('d.insertDate', '?' . ++$bc))->orderBy('d.startDate', 'DESC');
     //->orderBy('se.id', 'DESC');
     //Bind interval days
     $binds[] = array($bc, $nowMinusIntervalDays);
     if (isset($parameters['id'])) {
         $qb->andWhere($qb->expr()->eq('d.id', '?' . ++$bc));
         $binds[] = array($bc, $parameters['id']);
     }
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Run ScopeQueryBuilder regardless of if scope is set.
     $scopeQueryBuilder = new ScopeQueryBuilder(isset($parameters['scope']) ? $parameters['scope'] : null, isset($parameters['scope_match']) ? $parameters['scope_match'] : null, $qb, $this->em, $bc, 'Service', 'se');
     //Get the result of the scope builder
     $qb = $scopeQueryBuilder->getQB();
     $bc = $scopeQueryBuilder->getBindCount();
     //Get the binds and store them in the local bind array only if any binds are fetched from scopeQueryBuilder
     foreach ((array) $scopeQueryBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }
Example #16
0
 /** Creates the query by building on a queryBuilder object as
  *  required by the supplied parameters
  */
 public function createQuery()
 {
     $parameters = $this->validParams;
     $binds = array();
     $bc = -1;
     $qb = $this->em->createQueryBuilder();
     //Initialize base query
     $qb->select('u', 'r')->from('User', 'u')->leftJoin('u.roles', 'r')->orderBy('u.id', 'ASC');
     if (isset($parameters['roletype']) && isset($parameters['roletypeAND'])) {
         echo '<error>Only use either roletype or roletypeAND not both</error>';
         die;
     }
     /*If the user has specified a role type generate a new subquery
      * and join this to the main query with "where r.roleType in"
      */
     if (isset($parameters['roletype'])) {
         $qb1 = $this->em->createQueryBuilder();
         $qb1->select('rt.id')->from('roleType', 'rt')->where($qb1->expr()->in('rt.name', '?' . ++$bc));
         //Add to main query
         $qb->andWhere($qb->expr()->in('r.roleType', $qb1->getDQL()));
         //If user provided comma seprated values explode it and bind the resulting array
         if (strpos($parameters['roletype'], ',')) {
             $exValues = explode(',', $parameters['roletype']);
             $qb->setParameter($bc, $exValues);
         } else {
             $qb->setParameter($bc, $parameters['roletype']);
         }
     }
     /*Pass parameters to the ParameterBuilder and allow it to add relevant where clauses
      * based on set parameters.
      */
     $parameterBuilder = new ParameterBuilder($parameters, $qb, $this->em, $bc);
     //Get the result of the scope builder
     $qb = $parameterBuilder->getQB();
     $bc = $parameterBuilder->getBindCount();
     //Get the binds and store them in the local bind array - only runs if the returned value is an array
     foreach ((array) $parameterBuilder->getBinds() as $bind) {
         $binds[] = $bind;
     }
     //Bind all variables
     $qb = $this->helpers->bindValuesToQuery($binds, $qb);
     //Get the dql query from the Query Builder object
     $query = $qb->getQuery();
     $this->query = $query;
     return $this->query;
 }