public function myroutesAction()
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     $routes = new Application_Model_Routes();
     $users = new Application_Model_Users();
     $bind = new Application_Model_Bind();
     $query = $db->select()->from($routes->getTableName());
     $query->join($users->getTableName(), $routes->getTableName() . '.driver_id = ' . $users->getTableName() . '.id');
     //        $query->join($drivers->getTableName(),
     //                $users->getTableName().'.id = '.$drivers->getTableName().'.user_id');
     $query->where($users->getTableName() . '.id = ?', $this->user->id);
     $results = $db->fetchAll($query);
     $this->view->results = $results;
     $query2 = $db->select()->from($users->getTableName(), array('driver_flag'));
     $query2->where($users->getTableName() . '.id = ?', $this->user->id);
     $driver = $db->fetchOne($query2);
     $query3 = $db->select()->from($routes->getTableName());
     $query3->join($bind->getTableName(), $routes->getTableName() . '.route_id = ' . $bind->getTableName() . '.route_id');
     $query3->where($bind->getTableName() . '.user_id = ?', $this->user->id);
     $passangers = $db->fetchAll($query3);
     $this->view->results = $results;
     $this->view->driver = $driver;
     $this->view->passangerResults = $passangers;
 }
 public function registerAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $db = Zend_Db_Table::getDefaultAdapter();
     $users = new Application_Model_Users();
     $registerForm = new Application_Form_Registration();
     if ($this->_request->isPost()) {
         foreach ($this->_request->getPost('dataPost') as $dataArray) {
             $name = $dataArray['name'];
             $formDataForValidation["{$name}"] = $dataArray['value'];
         }
         if ($formDataForValidation['driverCheck'] === "1") {
             $carModel = $registerForm->getElement('carModel');
             $carModel->setRequired(true)->addErrorMessage('Required');
             $carMake = $registerForm->getElement('carMake');
             $carMake->setRequired(true)->addErrorMessage('Required');
             $driverLicense = $registerForm->getElement('driverLicense');
             $driverLicense->setRequired(true)->addErrorMessage('Required');
         }
         if ($registerForm->isValid($formDataForValidation)) {
             $userDataInsert = array('id' => null, 'email' => $formDataForValidation['emailRegister'], 'password' => $formDataForValidation['passwordRegister'], 'last_name' => $formDataForValidation['lastName'], 'first_name' => $formDataForValidation['firstName'], 'driver_flag' => $formDataForValidation['driverCheck'], 'telephone' => $formDataForValidation['telephone']);
             try {
                 $db->insert($users->getTableName(), $userDataInsert);
                 $last_id = $users->getAdapter()->lastInsertId();
             } catch (Zend_Exception $e) {
                 $this->redirect('/error/error');
             }
             if ($formDataForValidation['driverCheck']) {
                 //if the user is a driver => need to update driver data
                 $driver = new Application_Model_Driver();
                 $driverDataInsert = array('id' => null, 'user_id' => $last_id, 'make' => $formDataForValidation['carMake'], 'model' => $formDataForValidation['carModel'], 'license' => $formDataForValidation['driverLicense'], 'completed' => 0);
                 try {
                     $db->insert($driver->getTableName(), $driverDataInsert);
                 } catch (Zend_Exception $e) {
                     $this->redirect('/error/error');
                 }
             }
             $this->_helper->json(0);
         } else {
             $errorMessages = $registerForm->getMessages();
             $this->_helper->json($errorMessages);
         }
     }
 }