Beispiel #1
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();
     }
 }
 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);
     //Create
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $success = $song->create();
     $this->assertTrue($success);
     //Update
     $song = new Songs();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $success = $song->update();
     $this->assertFalse($success);
     $song = Songs::findFirst();
     $song->artist = 'Massive Attack';
     $song->name = 'Paradise Circus';
     $success = $song->update();
     $this->assertTrue($success);
 }
Beispiel #3
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";