コード例 #1
0
 /**
  * Run the migrations
  * @return mixed
  */
 public function up()
 {
     $query = "ALTER TABLE `" . App::getDbName() . "`.`" . Vessel::$tableName . "` " . "ADD COLUMN `" . Vessel::$columnTypeId . "` INT NULL, " . "ADD INDEX `" . Vessel::$indexTypesVessels . "` (`" . Vessel::$columnTypeId . "` ASC);";
     $this->db->getConnection()->prepare($query)->execute();
     $query = "ALTER TABLE `" . App::getDbName() . "`.`" . Vessel::$tableName . "` " . "ADD CONSTRAINT `" . Vessel::$foreignTypesVessels . "` " . "FOREIGN KEY (`" . Vessel::$columnTypeId . "`) " . "REFERENCES `" . App::getDbName() . "`.`" . Type::$tableName . "` (`" . Type::$columnPrimaryKey . "`) " . "ON DELETE RESTRICT ON UPDATE CASCADE;";
     $this->db->getConnection()->prepare($query)->execute();
     echo "Added type to vessels table.\n";
 }
コード例 #2
0
 /**
  * Run the migrations
  * @return mixed
  */
 public function up()
 {
     $query = "ALTER TABLE `" . App::getDbName() . "`.`" . Company::$tableName . "` " . "ADD COLUMN `" . Company::$columnUserId . "` INT NULL, " . "ADD UNIQUE INDEX `" . Company::$indexCompaniesUsers . "` (`" . Company::$columnUserId . "` ASC);";
     $this->db->getConnection()->prepare($query)->execute();
     $query = "ALTER TABLE `" . App::getDbName() . "`.`" . Company::$tableName . "` " . "ADD CONSTRAINT `" . Company::$foreignCompaniesUsers . "` " . "FOREIGN KEY (`" . Company::$columnUserId . "`) " . "REFERENCES `" . App::getDbName() . "`.`" . User::$tableName . "` (`" . User::$columnPrimaryKey . "`) " . "ON DELETE RESTRICT\tON UPDATE CASCADE;";
     $this->db->getConnection()->prepare($query)->execute();
     echo "Added user to company table.\n";
 }
コード例 #3
0
ファイル: CompaniesSeeder.php プロジェクト: rdok/dnmrn-exam
 /**
  * @return mixed
  */
 public function run()
 {
     foreach (range(1, 3) as $index) {
         $name = $this->faker->unique()->randomElement($this->popularCompanies);
         $query = "INSERT INTO `" . App::getDbName() . "`.`" . Company::$tableName . "` " . "(`" . Company::$columnName . "`) " . "VALUES ('{$name}')";
         DbManager::getConnection()->query($query);
     }
     echo "Seed for '" . Company::$tableName . "' table complete.\n";
 }
コード例 #4
0
 /**
  * @param $userId
  * @return mixed
  */
 public function getById($userId)
 {
     $query = "SELECT * FROM `" . App::getDbName() . "`.`" . User::$tableName . "` " . "INNER JOIN `" . Company::$tableName . "` ON `" . Company::$tableName . "`.`" . Company::$columnUserId . "` = `" . User::$tableName . "`.`" . User::$columnPrimaryKey . "` " . "WHERE `" . User::$tableName . "`.`" . User::$columnPrimaryKey . "` = :user_id ";
     $query = DbManager::getConnection()->prepare($query);
     $query->bindParam(':user_id', $userId, PDO::PARAM_STR);
     if ($query->execute()) {
         return $query->fetch(PDO::FETCH_ASSOC);
     }
     return false;
 }
コード例 #5
0
ファイル: VesselsSeeder.php プロジェクト: rdok/dnmrn-exam
 /**
  * @return mixed
  */
 public function run()
 {
     foreach (range(0, sizeof($this->popularNames) - 1) as $index) {
         $imo = "IMO" . $this->faker->unique()->randomNumber(7);
         $name = $this->faker->unique()->randomElement($this->popularNames);
         $query = "INSERT INTO `" . App::getDbName() . "`.`" . Vessel::$tableName . "` " . "(`" . Vessel::$columnImo . "`, `" . Vessel::$columnName . "`) " . "VALUES ('{$imo}', '{$name}')";
         $query = DbManager::getConnection()->query($query);
     }
     echo "Seed for '" . Vessel::$tableName . "' table complete.\n";
 }
コード例 #6
0
ファイル: DbManager.php プロジェクト: rdok/dnmrn-exam
 public function __construct()
 {
     try {
         $this->dbConnection = new PDO("mysql:host=" . App::getDbHost() . ";" . "dbname=" . App::getDbName() . ";" . "port=" . App::getDbPort(), App::getDbUsername(), App::getDbPassword());
         $this->dbConnection->setAttribute(PDO::ATTR_ERRMODE, App::getPDOErrorMode());
         // CHANGE THE ERROR MODE, THROW AN EXCEPTION WHEN AN ERROR IS FOUND
         $this->dbConnection->exec("SET NAMES 'utf8'");
     } catch (PDOException $e) {
         throw new Exception("Could not connect to the database.\n" . $e->getMessage() . "\n\n");
     }
 }
コード例 #7
0
ファイル: UsersSeeder.php プロジェクト: rdok/dnmrn-exam
 /**
  * @return mixed
  */
 public function run()
 {
     foreach (range(0, 3) as $index) {
         $firstName = $this->faker->firstName();
         $lastName = $this->faker->lastName();
         $email = $this->faker->unique()->email();
         $password = password_hash($this->faker->password(), PASSWORD_DEFAULT);
         $query = "INSERT INTO `" . App::getDbName() . "`.`" . User::$tableName . "` " . "(`" . User::$columnFirstName . "`, `" . User::$columnLastName . "`," . "`" . User::$columnEmail . "`, `" . User::$columnPassword . "`) " . "VALUES ('{$firstName}', '{$lastName}', '{$email}', '{$password}')";
         $query = DbManager::getConnection()->query($query);
     }
     echo "Seed for '" . User::$tableName . "' table complete.\n";
 }
コード例 #8
0
 /**
  * @param int $from
  * @param int $to
  * @return mixed
  */
 public function getWithRelations($from = 1, $to = 10)
 {
     $offset = $from - 1;
     $rows = $to - $from + 1;
     $query = "SELECT * FROM `" . App::getDbName() . "`.`" . Company::$tableName . "` " . "LEFT JOIN `" . User::$tableName . "` ON `" . Company::$tableName . "`.`" . Company::$columnUserId . "` = `" . User::$tableName . "`.`" . User::$columnPrimaryKey . "` " . "LIMIT {$from}, {$to}";
     $query = DbManager::getConnection()->prepare($query);
     $query->bindParam(1, $offset, PDO::PARAM_INT);
     $query->bindParam(2, $rows, PDO::PARAM_INT);
     if ($query->execute()) {
         return $query->fetchAll(PDO::FETCH_ASSOC);
     }
     return false;
 }
コード例 #9
0
 /**
  * @return mixed
  */
 public function run()
 {
     $companyIds = $this->companyRepository->getAll([Company::$columnPrimaryKey]);
     $vesselIds = $this->vesselRepository->getAll([Vessel::$columnPrimaryKey]);
     foreach (range(0, 33) as $index) {
         $companyId = $this->faker->randomElement($companyIds)[Company::$columnPrimaryKey];
         $vesselId = $this->faker->randomElement($vesselIds)[Vessel::$columnPrimaryKey];
         $query = "UPDATE `" . App::getDbName() . "`.`" . Vessel::$tableName . "` " . "SET `" . Vessel::$columnCompanyId . "`= :company_id " . "WHERE `" . Vessel::$columnPrimaryKey . "` = :vessel_id";
         $query = DbManager::getConnection()->prepare($query);
         $query->bindParam(':company_id', $companyId, PDO::PARAM_INT);
         $query->bindParam(':vessel_id', $vesselId, PDO::PARAM_INT);
         $query->execute();
     }
     echo "Seed for '" . Company::$tableName . "' and '" . Vessel::$tableName . "' tables complete.\n";
 }
コード例 #10
0
ファイル: TypeVesselSeeder.php プロジェクト: rdok/dnmrn-exam
 /**
  * @return mixed
  */
 public function run()
 {
     $typeIds = $this->typeRepository->getAll([Type::$columnPrimaryKey]);
     $vesselIds = $this->vesselRepository->getAll([Vessel::$columnPrimaryKey]);
     foreach ($vesselIds as $vesselId) {
         $vesselId = $vesselId[Vessel::$columnPrimaryKey];
         $typeId = $this->faker->randomElement($typeIds)[Type::$columnPrimaryKey];
         $query = "UPDATE `" . App::getDbName() . "`.`" . Vessel::$tableName . "` " . "SET `" . Vessel::$columnTypeId . "`= :type_id " . "WHERE `" . Vessel::$columnPrimaryKey . "` = :vessel_id";
         $query = DbManager::getConnection()->prepare($query);
         $query->bindParam(':type_id', $typeId, PDO::PARAM_INT);
         $query->bindParam(':vessel_id', $vesselId, PDO::PARAM_INT);
         $query->execute();
     }
     echo "Seed for '" . Vessel::$tableName . "' and '" . Type::$tableName . "' tables complete.\n";
 }
コード例 #11
0
ファイル: MySqlMigration.php プロジェクト: rdok/dnmrn-exam
 /**
  * Reverse the migrations
  */
 public function down()
 {
     $tableDeleted = $this->db->getConnection()->prepare("DESCRIBE `" . App::getDbName() . "`.`" . $this->getTableName() . "`")->execute();
     if ($tableDeleted === false) {
         return;
     }
     $this->db->getConnection()->prepare("SET FOREIGN_KEY_CHECKS=0")->execute();
     $this->db->getConnection()->prepare("TRUNCATE TABLE `" . App::getDbName() . "`.`" . $this->getTableName() . "`")->execute();
     $this->db->getConnection()->prepare("DROP TABLE IF EXISTS `" . App::getDbName() . "`.`" . $this->getTableName() . "`")->execute();
     $this->db->getConnection()->prepare("SET FOREIGN_KEY_CHECKS=1")->execute();
     if ($tableDeleted === false) {
         echo "Error: Unable to delete '" . $this->getTableName() . "'.\n";
     } else {
         echo "'" . $this->getTableName() . "' table destroyed.\n";
     }
 }
コード例 #12
0
ファイル: CreateTypesTable.php プロジェクト: rdok/dnmrn-exam
 /**
  * Run the migrations
  * @return mixed
  */
 public function up()
 {
     $query = "CREATE TABLE `" . App::getDbName() . "`.`" . Type::$tableName . "` (" . "`" . Type::$columnPrimaryKey . "` INT NOT NULL AUTO_INCREMENT," . "`" . Type::$columnName . "` VARCHAR(45) NOT NULL," . "PRIMARY KEY (`" . Type::$columnPrimaryKey . "`) ," . "UNIQUE INDEX `" . Type::$columnName . "_UNIQUE` (`" . Type::$columnName . "` ASC));";
     $this->db->getConnection()->prepare($query)->execute();
     echo "Table '" . Type::$tableName . "' created.\n";
 }
コード例 #13
0
ファイル: AppTest.php プロジェクト: rdok/dnmrn-exam
 /**
  * @test
  */
 public function it_returns_db_error_mode()
 {
     $randomDbErrorMode = "random-db-error-mode";
     putenv("PDO_ERROR_MODE={$randomDbErrorMode}");
     $this->assertSame($randomDbErrorMode, App::getPDOErrorMode());
 }
コード例 #14
0
ファイル: HtmlTest.php プロジェクト: rdok/dnmrn-exam
 /** @test */
 public function it_returns_absolute_url()
 {
     $html = new Html();
     $this->assertSame(App::getBaseURL() . "/random-url", $html->url("random-url"));
 }
コード例 #15
0
ファイル: BaseTest.php プロジェクト: rdok/dnmrn-exam
 protected function tearDown()
 {
     unset($_SERVER['REQUEST_URI']);
     unset($_SERVER['SERVER_NAME']);
     App::setBaseUrl(null);
 }
コード例 #16
0
ファイル: Html.php プロジェクト: rdok/dnmrn-exam
 /**
  * @param $src
  */
 public function script($src)
 {
     echo "<script src='" . App::getBaseURL() . "/{$src}'></script>";
 }