示例#1
0
 public function count()
 {
     $query = "SELECT COUNT(*) FROM `{$this->tableName}`";
     if ($query = DbManager::getConnection()->query($query)) {
         return intval($query->fetchColumn(0));
     }
     return false;
 }
示例#2
0
 /**
  * @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";
 }
示例#3
0
 /**
  * @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";
 }
 /**
  * @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
 /**
  * @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";
 }
 /**
  * @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;
 }
示例#7
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";
 }
示例#8
0
 /**
  * @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";
 }