public function testCollectionsEvents()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $songs = Store\Songs::find();
     $this->assertTrue(is_array($songs));
     foreach ($songs as $song) {
         $this->assertTrue($song->delete());
     }
     $trace = array();
     $song = new Songs();
     $song->artist = 'Radiohead';
     $song->name = 'Lotus Flower';
     $this->assertTrue($song->save());
     $serialized = serialize($song);
     $song = unserialize($serialized);
     $this->assertEquals($song->artist, 'Radiohead');
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertTrue($song->save());
     $song = Songs::findFirst();
     $serialized = serialize($song);
     $song = unserialize($serialized);
     $this->assertEquals($song->artist, 'Radiohead');
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertTrue($song->save());
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $this->assertTrue($song->save());
     $songs = Songs::find();
     $this->assertEquals(count($songs), 2);
     $serialized = serialize($songs);
     $songs = unserialize($serialized);
     $this->assertEquals(count($songs), 2);
 }
Example #2
0
 public function testCollections()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     foreach ($songs as $song) {
         $this->assertTrue($song->delete());
     }
     $song = new Songs();
     $song->artist = 'Radiohead';
     $song->name = 'Lotus Flower';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $firstSongId = $song->_id;
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Lotus Flower');
     $this->assertEquals($songs[0]->artist, 'Radiohead');
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Teardrop';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $this->assertNotEquals((string) $firstSongId->{'$id'}, (string) $song->_id->{'$id'});
     $secondSongId = $song->_id;
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Lotus Flower');
     $this->assertEquals($songs[0]->artist, 'Radiohead');
     $this->assertEquals($songs[1]->name, 'Teardrop');
     $this->assertEquals($songs[1]->artist, 'Massive Attack');
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $success = $song->save();
     $this->assertTrue($success);
     $this->assertInstanceOf('MongoId', $song->_id);
     $this->assertNotEquals((string) $firstSongId->{'$id'}, (string) $song->_id->{'$id'});
     $this->assertNotEquals((string) $secondSongId->{'$id'}, (string) $song->_id->{'$id'});
     $songs = Songs::find();
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 3);
     $song = Songs::findFirst();
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Lotus Flower');
     $this->assertEquals($song->artist, 'Radiohead');
     $song = Songs::findFirst(array(array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->artist, 'Massive Attack');
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->artist, 'Massive Attack');
     $song = Songs::findFirst(array('conditions' => array('name' => 'Paradise Circus')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Paradise Circus');
     //No results
     $song = Songs::findFirst(array(array('artist' => 'Lana')));
     $this->assertFalse($song);
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Lana')));
     $this->assertFalse($song);
     $song = Songs::findFirst(array(array('artist' => 'Lana')));
     $this->assertFalse($song);
     //Passing parameters to find
     $songs = Songs::find(array(array('artist' => 'Massive Attack')));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     $this->assertEquals($songs[1]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     $this->assertEquals($songs[1]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'sort' => array('name' => 1)));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 2);
     $this->assertEquals($songs[0]->name, 'Paradise Circus');
     $this->assertEquals($songs[1]->name, 'Teardrop');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'sort' => array('name' => 1), 'limit' => 1));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Paradise Circus');
     $songs = Songs::find(array('conditions' => array('artist' => 'Massive Attack'), 'limit' => 1));
     $this->assertTrue(is_array($songs));
     $this->assertEquals(count($songs), 1);
     $this->assertEquals($songs[0]->name, 'Teardrop');
     //Find first
     $song = Songs::findFirst(array(array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Teardrop');
     $song = Songs::findFirst(array('conditions' => array('artist' => 'Massive Attack')));
     $this->assertInstanceOf('Songs', $song);
     $this->assertEquals($song->name, 'Teardrop');
     //Count
     $this->assertEquals(Songs::count(), 3);
     $this->assertEquals(Songs::count(array(array('artist' => 'Massive Attack'))), 2);
 }
Example #3
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');
echo "<pre>";
$config = parse_ini_file('config.ini');
require_once 'lib/Model/composers.php';
require_once 'lib/Model/songs.php';
require_once 'lib/Model/musicalForms.php';
$song = new Songs();
$song->setTitle('blaat');
$song->setMusicalForm(1);
$song->setLength('10:00:00');
$song->setDifficulty(5);
$song->setWantToPlay(2);
$song->setConcertReady(2);
$song->add();
/*
// Quick and dirty demo how to use object array in a view
$songs = new Songs;
foreach($songs->fetch() as $song){
    echo "<table>";
    echo "<tr>";
    echo "<td>";
    echo $song->getId();
    echo "</td>";
    echo "<td>";
    echo $song->getTitle();
    echo "</td>";
    echo "</tr>";
    echo "</table>";
Example #4
0
 public function run()
 {
     if (!isset($_POST["action"])) {
         return;
     }
     if ($_POST["action"] == "addComposer") {
         $composer = new composers();
         $composer->setComposerFirstname($_POST["ComposerFirstname"]);
         $composer->setComposerLastname($_POST["ComposerLastname"]);
         $composer->setDateOfBirth($_POST["DateOfBirth"]);
         $composer->setPlaceOfBirth($_POST["PlaceOfBirth"]);
         $composer->setBirthCountry($_POST["BirthCountry"]);
         $composer->setDeceased($_POST["Deceased"]);
         $composer->add();
     } elseif ($_POST["action"] == "updateComposer") {
         $composer = new composers();
         $composer->setComposerFirstname($_POST["ComposerFirstname"]);
         $composer->setComposerLastname($_POST["ComposerLastname"]);
         $composer->setDateOfBirth($_POST["DateOfBirth"]);
         $composer->setPlaceOfBirth($_POST["PlaceOfBirth"]);
         $composer->setBirthCountry($_POST["BirthCountry"]);
         $composer->setDeceased($_POST["Deceased"]);
         $composer->setID($_POST["id"]);
         $composer->update();
     } elseif ($_POST["action"] == "addSong") {
         $song = new Songs();
         $song->setComposersID($_POST["ComposersID"]);
         $song->setMusicalForm($_POST["MusicalForm"]);
         $song->setTitle($_POST["Title"]);
         $song->setOpus($_POST["Opus"]);
         $song->setMovement($_POST["Movement"]);
         $song->setLength($_POST["Length"]);
         $song->setDifficulty($_POST["Difficulty"]);
         $song->setWantToPlay($_POST["WantToPlay"]);
         $song->setConcertReady($_POST["ConcertReady"]);
         $song->add();
     } elseif ($_POST["action"] == "updateSong") {
         $song = new Songs();
         $song->setComposersID($_POST["ComposersID"]);
         $song->setMusicalForm($_POST["MusicalForm"]);
         $song->setTitle($_POST["Title"]);
         $song->setOpus($_POST["Opus"]);
         $song->setMovement($_POST["Movement"]);
         $song->setLength($_POST["Length"]);
         $song->setDifficulty($_POST["Difficulty"]);
         $song->setWantToPlay($_POST["WantToPlay"]);
         $song->setConcertReady($_POST["ConcertReady"]);
         $song->setID($_POST["id"]);
         $song->update();
     }
 }
Example #5
0
<?php

require_once '1trainSongs.php';
require_once '1trainArtists.php';
require_once '1trainUsers.php';
$songid = $_REQUEST['id'];
$artistid = $_REQUEST['user_id'];
$title = $_REQUEST['title'];
$artist = $_REQUEST['user']['username'];
$art = $_REQUEST['artwork_url'];
$avatar = $_REQUEST['user']['avatar_url'];
$user_id = $_REQUEST['whoLikedID'];
$profile = $_REQUEST['whoLiked'];
Artists::create($artistid, $artist);
Users::create($user_id, $profile);
if ($art == "") {
    $avatar = explode("large", $avatar)[0] . "crop.jpg";
    //gets a higher quality image
    Songs::create($songid, $title, $artistid, $avatar, $user_id);
} elseif ($art == "https://sndcdn.com/images/default_avatar_crop.jpg") {
    //if no song art or user avatar
    $art = "photoshop/carousel-headphones-black-red.png";
    Songs::create($songid, $title, $artistid, $art, $user_id);
} else {
    $art = explode("large", $art)[0] . "crop.jpg";
    //gets a higher quality image
    Songs::create($songid, $title, $artistid, $art, $user_id);
}
header('Content-type: application/json');
print "success from uploadToDB";
exit;
Example #6
0
 public function testExecute()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped("Mongo class does not exist, test skipped");
         return;
     }
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('mongo', function () {
         $mongo = new MongoClient();
         return $mongo->phalcon_test;
     });
     $di->set('collectionManager', function () {
         return new Phalcon\Mvc\Collection\Manager();
     });
     $ret = Songs::execute("function() { return 'Hello, world!';}");
     $this->assertEquals($ret['retval'], 'Hello, world!');
 }
Example #7
0
 /**
  * Fetch all from Songs DB and set all fetched data to parameters
  */
 public function fetch()
 {
     $sql = 'SELECT * FROM Songs';
     $songs = [];
     foreach ($this->con->query($sql) as $row) {
         $song = new Songs();
         $song->setID($row['ID']);
         $song->setComposersID($row['ComposersID']);
         $song->setMusicalForm($row['MusicalForm']);
         $song->setTitle($row['Title']);
         $song->setOpus($row['Opus']);
         $song->setMovement($row['Movement']);
         $song->setLength($row['Length']);
         $song->setDifficulty($row['Difficulty']);
         $song->setWantToPlay($row['WantToPlay']);
         $song->setConcertReady($row['ConcertReady']);
         $songs[] = $song;
     }
     return $songs;
 }
Example #8
0
                } elseif ($art == "https://sndcdn.com/images/default_avatar_crop.jpg") {
                    //if no song art or user avatar
                    $art = "photoshop/carousel-headphones-black-red.png";
                    Songs::create($songid, $title, $artistid, $art, $user_id);
                } else {
                    $art = explode("large", $art)[0] . "crop.jpg";
                    //gets a higher quality image
                    Songs::create($songid, $title, $artistid, $art, $user_id);
                }
                header('Content-type: application/json');
                print "success from uploadToDB";
                exit;
            } else {
                if ($resource_type == 'update') {
                    print $_REQUEST['artist_id'];
                    $songid = $_REQUEST['id'];
                    $title = $_REQUEST['song_name'];
                    $artistid = $_REQUEST['artist_id'];
                    $artistname = $_REQUEST['artistname'];
                    Songs::update($songid, $title);
                    Artists::update($artistid, $artistname);
                    header('Content-type: application/json');
                    print "successful update";
                    exit;
                }
            }
        }
    }
}
header("HTTP/1.1 400 Bad Request");
print "Did not understand URL last";