Exemplo n.º 1
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $routeMatch = $e->getRouteMatch();
         $parkingLotId = $routeMatch->getParam('parking_lot_id', 0);
         // get the parking lot id
         if (method_exists($controller, 'setParkingLotId')) {
             $serviceManager = $e->getApplication()->getServiceManager();
             $dbAdapter = $serviceManager->get('Zend\\Db\\Adapter\\Adapter');
             $parkingLotExistsValidator = new RecordExists(['adapter' => $dbAdapter, 'table' => DbTables::TBL_PARKING_LOTS, 'field' => 'id']);
             if (!$parkingLotExistsValidator->isValid($parkingLotId) && $parkingLotId != 0) {
                 $url = $e->getRouter()->assemble(['controller' => 'parking', 'action' => 'index'], ['name' => 'parking']);
                 $response = $e->getResponse();
                 $response->getHeaders()->addHeaderLine('Location', $url);
                 $response->setStatusCode(302);
                 $response->sendHeaders();
                 return $response;
             }
             $controller->setParkingLotId($parkingLotId);
         }
     }, 100);
 }
Exemplo n.º 2
0
 public function isExistName($name)
 {
     // $rowset = $this->tableGateway->select(array('name' => $name));
     //$row = $rowset->current();
     // if (!$row) {
     //return false;
     //throw new \Exception("Could not find row $id");
     //}
     //return true;
     $valid = true;
     $name = trim($name);
     $adapter = $this->tableGateway->getAdapter();
     //$adapter = null;
     if (null === $adapter) {
         throw new \Exception('No database adapter present');
     }
     $validator = new RecordExists(array('table' => 'kill_type', 'field' => 'name', 'adapter' => $adapter));
     // We still need to set our database adapter
     $validator->setAdapter($adapter);
     // Validation is then performed as usual
     if ($validator->isValid($name)) {
         $valid = true;
     } else {
         $valid = false;
     }
     return $valid;
     // username is invalid; print the reason
     //$//messages = $validator->getMessages();
     //foreach ($messages as $message) {
     //echo "$message\n";
     //}
 }
Exemplo n.º 3
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, [$this, 'onViewHelper']);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $routeMatch = $e->getRouteMatch();
         $apartmentId = $routeMatch->getParam('apartment_id', 0);
         // get the apartment ID
         if (method_exists($controller, 'setApartmentID')) {
             $serviceManager = $e->getApplication()->getServiceManager();
             $dbAdapter = $serviceManager->get('Zend\\Db\\Adapter\\Adapter');
             $apartmentExistValidator = new RecordExists(['adapter' => $dbAdapter, 'table' => DbTables::TBL_APARTMENTS, 'field' => 'id']);
             if (!$apartmentExistValidator->isValid($apartmentId) && $apartmentId != 0) {
                 $url = $e->getRouter()->assemble(array('controller' => 'apartment', 'action' => 'search'), ['name' => 'apartments']);
                 $response = $e->getResponse();
                 $response->getHeaders()->addHeaderLine('Location', $url);
                 $response->setStatusCode(302);
                 $response->sendHeaders();
                 return $response;
             }
             $controller->setApartmentID($apartmentId);
         }
     }, 100);
 }
Exemplo n.º 4
0
 public function isExistName()
 {
     $adapter = $this->tableGateway->getAdapter();
     if (null === $adapter) {
         throw new \Exception('No database adapter present');
     }
     $validator = new RecordExists(array('table' => 'screen_shots', 'field' => 'title', 'adapter' => $adapter));
     $validator->setAdapter($adapter);
     return $validator;
 }
Exemplo n.º 5
0
 public function index03Action()
 {
     $adapter = $this->getServiceLocator()->get("db_books");
     $validate = new RecordExists(array("table" => "user", "field" => "email", "adapter" => $adapter, "exclude" => array("field" => "id", "value" => "1")));
     $email = "*****@*****.**";
     if (!$validate->isValid($email)) {
         echo "<pre style='font-weight:bold'>";
         print_r($validate->getMessages());
         echo "</pre>";
     }
     return false;
 }
Exemplo n.º 6
0
 /**
  * Mark as settled
  * @param string $resNumber
  * @return boolean
  */
 public function markAsSettled($resNumber)
 {
     /**
      * @var \DDD\Dao\Booking\Booking $bookingDao
      * @var Logger $logger
      */
     $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $logger = $this->getServiceLocator()->get('ActionLogger');
     $reservationExistValidator = new RecordExists(['adapter' => $dbAdapter, 'table' => DbTables::TBL_BOOKINGS, 'field' => 'res_number']);
     if ($reservationExistValidator->isValid($resNumber)) {
         $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
         $bookingDao->update(['payment_settled' => 1, 'settled_date' => date('Y-m-d H:i:s')], ['res_number' => $resNumber]);
         $bookingDomain = $bookingDao->fetchOne(['res_number' => $resNumber], ['id']);
         $logger->save(Logger::MODULE_BOOKING, $bookingDomain->getId(), Logger::ACTION_RESERVATION_SETTLED);
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 public function isExistName($name)
 {
     $valid = true;
     $name = trim($name);
     $adapter = $this->tableGateway->getAdapter();
     if (null === $adapter) {
         throw new \Exception('No database adapter present');
     }
     $validator = new RecordExists(array('table' => 'deer_activity', 'field' => 'name', 'adapter' => $adapter));
     // We still need to set our database adapter
     $validator->setAdapter($adapter);
     // Validation is then performed as usual
     if ($validator->isValid($name)) {
         $valid = true;
     } else {
         $valid = false;
     }
     return $valid;
 }
Exemplo n.º 8
0
 /**
  * @return ZF-8863
  */
 public function testExcludeConstructor()
 {
     AbstractTable::setDefaultAdapter($this->_adapterHasResult);
     $validator = new RecordExistsValidator('users', 'field1', 'id != 1');
     $this->assertTrue($validator->isValid('value3'));
 }
Exemplo n.º 9
0
 /**
  *
  * @group ZF-10705
  */
 public function testCreatesQueryBasedOnNamedOrPositionalAvailablity()
 {
     AbstractTable::setDefaultAdapter(null);
     $this->_adapterHasResult->setSupportsParametersValues(array('named' => false, 'positional' => true));
     $validator = new RecordExistsValidator('users', 'field1', null, $this->_adapterHasResult);
     $validator->isValid('foo');
     $wherePart = $validator->getSelect()->getPart('where');
     $this->assertEquals('("field1" = ?)', $wherePart[0]);
     $this->_adapterHasResult->setSupportsParametersValues(array('named' => true, 'positional' => true));
     $validator = new RecordExistsValidator('users', 'field1', null, $this->_adapterHasResult);
     $validator->isValid('foo');
     $wherePart = $validator->getSelect()->getPart('where');
     $this->assertEquals('("field1" = :value)', $wherePart[0]);
 }
Exemplo n.º 10
0
 /**
  * @cover Zend\Validator\Db\RecordExists::getSelect
  * @group ZF2-4521
  */
 public function testGetSelectWithSameValidatorTwice()
 {
     $validator = new RecordExists(array('table' => 'users', 'schema' => 'my'), 'field1', array('field' => 'foo', 'value' => 'bar'), $this->getMockHasResult());
     $select = $validator->getSelect();
     $this->assertInstanceOf('Zend\\Db\\Sql\\Select', $select);
     $this->assertEquals('SELECT "my"."users"."field1" AS "field1" FROM "my"."users" WHERE "field1" = \'\' AND "foo" != \'bar\'', $select->getSqlString(new TrustingSql92Platform()));
     // same validator instance with changing properties
     $validator->setTable('othertable');
     $validator->setSchema('otherschema');
     $validator->setField('fieldother');
     $validator->setExclude(array('field' => 'fieldexclude', 'value' => 'fieldvalueexclude'));
     $select = $validator->getSelect();
     $this->assertInstanceOf('Zend\\Db\\Sql\\Select', $select);
     $this->assertEquals('SELECT "otherschema"."othertable"."fieldother" AS "fieldother" FROM "otherschema"."othertable" WHERE "fieldother" = \'\' AND "fieldexclude" != \'fieldvalueexclude\'', $select->getSqlString(new TrustingSql92Platform()));
 }
Exemplo n.º 11
0
 /**
  * Test that we don't get a mix of positional and named parameters
  * @group ZF2-502
  */
 public function testSelectDoesNotMixPositionalAndNamedParameters()
 {
     if (!extension_loaded('sqlite3')) {
         $this->markTestSkipped('Relies on SQLite extension');
     }
     $adapter = new Adapter(array('driver' => 'Pdo_Sqlite', 'database' => 'sqlite::memory:'));
     $validator = new RecordExists(array('table' => 'users', 'schema' => 'my'), 'field1', array('field' => 'foo', 'value' => 'bar'), $adapter);
     $select = $validator->getSelect();
     $this->assertInstanceOf('Zend\\Db\\Sql\\Select', $select);
     $string = $select->getSqlString();
     if (preg_match('/:[a-zA-Z]+/', $string)) {
         $this->assertNotContains(' != ?', $string);
     } else {
         $this->assertContains(' != ?', $string);
     }
 }
Exemplo n.º 12
0
 public function getRecordExistsValidator()
 {
     if ($this->recordExistsValidator === NULL) {
         $validator = new RecordExists($this->getRecordExistsConfig());
         $validator->setMessages(array(NoRecordExists::ERROR_NO_RECORD_FOUND => $this->getErrorMessage('RECORD_EXISTS::ERROR_NO_RECORD_FOUND'), NoRecordExists::ERROR_RECORD_FOUND => $this->getErrorMessage('NO_RECORD_EXISTS::ERROR_RECORD_FOUND')));
         $this->setRecordExistsValidator($validator);
     }
     return $this->recordExistsValidator;
 }
Exemplo n.º 13
0
    /**
     * @testdox Zend\Validator\Db\RecordExists::getSelect
     */
    public function testGetSelect()
    {
        $validator = new RecordExists(
            array(
                'table' => 'users',
                'schema' => 'my'
            ),
            'field1',
            array(
                'field' => 'foo',
                'value' => 'bar'
            ),
            $this->getMockHasResult()
        );
        $select = $validator->getSelect();
        $this->assertInstanceOf('Zend\Db\Sql\Select', $select);
        $this->assertEquals('SELECT "my"."users"."field1" AS "field1" FROM "my"."users" WHERE "field1" = \'\' AND "foo" != \'bar\'', $select->getSqlString());

        $sql = new Sql($this->getMockHasResult());
        $statement = $sql->prepareStatementForSqlObject($select);
        $parameters = $statement->getParameterContainer();
        $this->assertNull($parameters['where1']);
        $this->assertEquals($parameters['where2'], 'bar');
    }
Exemplo n.º 14
0
 /**
  * @group ZF-10642
  */
 public function testCreatesQueryBasedOnNamedOrPositionalAvailability()
 {
     $this->markTestIncomplete('This test (and code) need to be refactored to the new Zend\\Db');
     $adapterHasResult = $this->getMockHasResult();
     //$adapterHasResult->setSupportsParametersValues(array('named' => false, 'positional' => true));
     $validator = new RecordExists('users', 'field1', null, $adapterHasResult);
     $validator->isValid('foo');
     $wherePart = $validator->getSelect()->getPart('where');
     $this->assertEquals('("field1" = ?)', $wherePart[0]);
     //$adapterHasResult->setSupportsParametersValues(array('named' => true, 'positional' => true));
     $validator = new RecordExists('users', 'field1', null, $adapterHasResult);
     $validator->isValid('foo');
     $wherePart = $validator->getSelect()->getPart('where');
     $this->assertEquals('("field1" = :value)', $wherePart[0]);
 }
Exemplo n.º 15
0
 /**
  * @param string $reservationNumber
  * @return bool
  */
 public function isValid($reservationNumber)
 {
     return parent::isValid($reservationNumber);
 }