Beispiel #1
0
 public function getMoviesFromDb($columnsNames = ["id", "name", "description", "rating"])
 {
     if (is_array($columnsNames) && !empty($columnsNames)) {
         $columns = implode(",", $columnsNames);
         $sqlQuery = "SELECT " . $columns . " FROM movies";
         $conn = parent::getConnection();
         $result = $conn->query($sqlQuery);
         if ($result->num_rows > 0) {
             while ($row = $result->fetch_assoc()) {
                 $movie = new Movie(parent::getConnection());
                 if (array_key_exists("id", $row)) {
                     $movie->setId($row["id"]);
                 }
                 if (array_key_exists("name", $row)) {
                     $movie->setName($row["name"]);
                 }
                 if (array_key_exists("description", $row)) {
                     $movie->setDescription($row["description"]);
                 }
                 if (array_key_exists("rating", $row)) {
                     $movie->setRating($row["rating"]);
                 }
                 $this->setArrayWithMovies($movie);
             }
         }
     }
 }
Beispiel #2
0
include 'database_connection.php';
include 'classes/MediaItem.php';
include 'classes/Game.php';
include 'classes/Book.php';
include 'classes/Music.php';
include 'classes/Movie.php';
$game = new Game();
$game->setTitle('Watch Dogs');
$game->setDesc('Crappy shit wannabe hacker game');
$game->setRating(1);
$game->setTags(['dnt']);
print '<p>' . ($game->save() ? "Saving successful" : "Saving unsuccessful") . '</p>';
$book = new Book();
$book->setTitle('Momo');
$book->setDesc('Dreamy and so on');
$book->setRating(4);
$book->setTags(['tc']);
print '<p>' . ($book->save() ? "Saving successful" : "Saving unsuccessful") . '</p>';
$movie = new Movie();
$movie->setTitle('The big short');
$movie->setDesc('Capitalism');
$movie->setRating(3);
$movie->setTags(['tc', 'wtf']);
print '<p>' . ($movie->save() ? "Saving successful" : "Saving unsuccessful") . '</p>';
$music = new Music();
$music->setTitle('Bravo Hits 666');
$music->setDesc('Diabolic Bullshit');
$music->setRating(1);
$music->setTags(['dnt']);
print '<p>' . ($music->save() ? "Saving successful" : "Saving unsuccessful") . '</p>';
foreach (match_all('/<tr class="(even|odd)">(.*?)<\\/tr>/ms', $html, 2) as $m) {
    $rank++;
    $id = match('/<td class="titleColumn">.*?<a href="\\/title\\/(tt\\d+)\\/.*?"/msi', $m, 1);
    $title = match('/<td class="titleColumn">.*?<a.*?>(.*?)<\\/a>/msi', $m, 1);
    $year = match('/<td class="titleColumn">.*?<span.*?>\\((.*?)\\)<\\/span>/msi', $m, 1);
    $rating = match('/<td class="ratingColumn">.*?<strong.*?>(.*?)<\\/strong>/msi', $m, 1);
    $poster = match('/<td class="posterColumn">.*?<img src="(.*?)"/msi', $m, 1);
    $votesURL = "http://www.imdb.com/title/" . $id . "/";
    $votes = getvotes($votesURL);
    // create each movie object and set the variables
    $movie = new Movie();
    $movie->setId($id);
    $movie->setRank($rank);
    $movie->setTitle($title);
    $movie->setYear($year);
    $movie->setRating($rating);
    $movie->setVotes($votes);
    // insert $movie objects into an array
    array_push($top10Movies, $movie);
    // stop at 10
    if ($rank == 10) {
        break;
    }
}
$date = $db->select("movies", "date_added");
// insert into database using medoo if it does not exist
foreach ($top10Movies as $movie) {
    // check database for matching date, if same day update, else insert
    if (in_array($today, $date)) {
        $db->update("movies", ["imdb_id" => $movie->getId(), "rank" => $movie->getRank(), "rating" => $movie->getRating(), "title" => $movie->getTitle(), "year" => $movie->getYear(), "number_of_votes" => $movie->getVotes(), "date_added" => $today], ["date_added" => $today, "rank" => $movie->getRank()]);
    } else {