예제 #1
0
파일: Module.php 프로젝트: arbi/MyCode
 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);
 }
예제 #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";
     //}
 }
예제 #3
0
파일: Module.php 프로젝트: arbi/MyCode
 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);
 }
예제 #4
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;
 }
예제 #5
0
파일: ToBeSettled.php 프로젝트: arbi/MyCode
 /**
  * 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;
 }
예제 #6
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;
 }
예제 #7
0
 /**
  * @return ZF-8863
  */
 public function testExcludeConstructor()
 {
     AbstractTable::setDefaultAdapter($this->_adapterHasResult);
     $validator = new RecordExistsValidator('users', 'field1', 'id != 1');
     $this->assertTrue($validator->isValid('value3'));
 }
예제 #8
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]);
 }
예제 #9
0
 /**
  * Test that schemas are supported and run without error
  *
  * @return void
  */
 public function testWithSchemaNoResult()
 {
     $validator = new RecordExists(array('table' => 'users', 'schema' => 'my'), 'field1', null, $this->getMockNoResult());
     $this->assertFalse($validator->isValid('value1'));
 }
예제 #10
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]);
 }
예제 #11
0
 /**
  * @param string $reservationNumber
  * @return bool
  */
 public function isValid($reservationNumber)
 {
     return parent::isValid($reservationNumber);
 }