/**
  * testDeleteDependentWithConditions method
  *
  * @return void
  */
 public function testDeleteDependentWithConditions()
 {
     $this->loadFixtures('Cd', 'Book', 'OverallFavorite');
     $Cd = new Cd();
     $Book = new Book();
     $OverallFavorite = new OverallFavorite();
     $Cd->delete(1);
     $result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
     $expected = array(array('OverallFavorite' => array('model_type' => 'Book', 'model_id' => 1, 'priority' => 2)));
     $this->assertTrue(is_array($result));
     $this->assertEquals($expected, $result);
     $Book->delete(1);
     $result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
     $expected = array();
     $this->assertTrue(is_array($result));
     $this->assertEquals($expected, $result);
 }
Example #2
0
 public function getDeleteCd($id)
 {
     $cd = Cd::where('id', '=', $id)->first();
     if ($cd) {
         $cd->delete();
         return Redirect::to('/browse-cds')->with('flash_message', 'Delete successfuly!');
     } else {
         return Redirect::to('/browse-cds')->with('flash_message', 'Delete failed! Try again...!');
     }
 }
Example #3
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Cd the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Cd::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #4
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Cd.php";
session_start();
$cds = array();
if (empty($_SESSION['list_of_cds'])) {
    $_SESSION['list_of_cds'] = $cds;
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//ROOT ROUTE
$app->get("/", function () use($app) {
    return $app['twig']->render('cd.html.twig', array('cds' => Cd::getAll()));
});
$app->get('/new_cd', function () use($app) {
    return $app['twig']->render('new_cd.html.twig', array('cds' => Cd::getAll()));
});
$app->get('/searchbyartist', function () use($app) {
    return $app['twig']->render('searchbyartist.html.twig', array('cds' => Cd::getAll()));
});
$app->post('/cd_confirm', function () use($app) {
    $cd = new Cd($_POST['artist'], $_POST['title'], $_POST['price']);
    $cd->save();
    return $app['twig']->render('cd_confirm.html.twig', array('newcd' => $cd));
});
return $app;
Example #5
0
    return $app['twig']->render('cds.html.twig', array('cds' => Cd::getAll()));
});
/**Enter CD webpage**/
$app->get("/enter_music", function () use($app) {
    return $app['twig']->render('enter_music.twig.html');
});
/**Add New CD**/
$app->post("/add", function () use($app) {
    $cd = new Cd($_POST['artist'], $_POST['album_name'], $_POST['year'], $_POST['cover_art']);
    $cd->save();
    return $app['twig']->render('review_cd.html.twig', array('newcd' => $cd));
});
/**View Search**/
$app->get("/results", function () use($app) {
    $user_artist = strtolower($_GET['user_artist']);
    $cds = $_SESSION['list_of_cds'];
    $cds_match = $_SESSION['matching_cds'];
    foreach ($cds as $cd) {
        if ($user_artist == strtolower($cd->getArtist())) {
            array_push($cds_match, $cd);
        }
    }
    var_dump($cds_match);
    return $app['twig']->render('search_results.html.twig', array('matching_cds' => $cds_match));
});
/**Delete CDs**/
$app->post("/delete_cds", function () use($app) {
    Cd::deleteAll();
    return $app['twig']->render('delete_cds.html.twig');
});
return $app;
Example #6
0
session_start();
if (empty($_SESSION['list_of_cds'])) {
    $_SESSION['list_of_cds'] = array();
}
if (empty($_SESSION['list_of_artists'])) {
    $_SESSION['list_of_artists'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// routes
$app->get("/", function () use($app) {
    return $app['twig']->render('cds.html.twig', array('cds' => Cd::getAll()));
});
$app->post("/cds", function () use($app) {
    $new_artist = new Artist($_POST['artist']);
    $new_cd = new Cd($new_artist, $_POST['title'], $_POST['cover']);
    $new_cd->saveCd();
    $new_artist->saveArtist();
    return $app['twig']->render('cds.html.twig', array('cds' => Cd::getAll()));
});
$app->get("/search", function () use($app) {
    return $app['twig']->render('search.html.twig');
});
$app->post("/search", function () use($app) {
    $cds = Cd::getAll();
    $artist_matching_search = array();
    foreach ($cds as $cd) {
        if ($cd->search($_POST['user_input'])) {
            array_push($artist_matching_search, $cd);
        }
    }
Example #7
0
 /**
  * Creates or updates the track in database getting data from file.
  * Used in /album/actions/executeRefreshAlbum
  *
  * @param Cd $cd_object ex: CD(Cd 1)
  * @param Array $track_info[] ex: [3, Beat it, MICHAEL JACKSON, 4:32, 128 kbps, 3,4 MB]
  * @return Track
  */
 public static function createTrack($cd_object, $track_info)
 {
     //looking for this episode in db
     $track_object = NULL;
     foreach ($cd_object['Tracks'] as $track) {
         if ($track->title == $track_info['title']) {
             $track_object = $track;
         }
     }
     //if there is no episode
     if ($track_object == NULL) {
         $track_object = new Track();
         $track_object->title = $track_info['title'];
     }
     $track_object->num_track = $track_info['num_track'];
     $track_object->duration = $track_info['duration'];
     $track_object->bitrate = $track_info['bitrate'];
     $track_object->filesize = $track_info['filesize'];
     $track_object->rating = $track_info['rating'];
     $track_object->lyrics = $track_info['lyrics'];
     $track_object->file_rel = $track_info['file_rel'];
     /*********************************   YEAR   *********************************/
     if ($track_info['year'] == "") {
         $track_object->Year = NULL;
     } else {
         $year_object = Doctrine::getTable('Year')->findOneByName($track_info['year']);
         if ($year_object == NULL) {
             $year_object = Util::createYear($track_info['year']);
         }
         $track_object->Year = $year_object;
     }
     /*********************************   GENRE   *********************************/
     if ($track_info['genre'] == "") {
         $track_object->Genre = NULL;
     } else {
         $genre_object = Doctrine::getTable('Genre')->findOneByName($track_info['genre']);
         if ($genre_object == NULL) {
             $genre_object = Util::createGenre($track_info['genre']);
         }
         $track_object->Genre = $genre_object;
     }
     /*********************************   SINGER   *********************************/
     if ($track_info['artist'] == "") {
         $track_object->Singer = NULL;
     } else {
         $singer_object = Doctrine::getTable('Singer')->findOneByName(Util::formatName($track_info['artist']));
         if ($singer_object == NULL) {
             $singer_object = Util::createSinger(Util::formatName($track_info['artist']));
         }
         $track_object->Singer = $singer_object;
     }
     $track_object->save();
     $cd_object->Tracks[] = $track_object;
     $cd_object->save();
     return $track_object;
 }
Example #8
0
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Cd.php';
session_start();
if (empty($_SESSION['list_of_cds'])) {
    $_SESSION['list_of_cds'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('cd_organizer.html.twig', array('cds' => Cd::getAll()));
});
$app->get('/new_cd', function () use($app) {
    return $app['twig']->render('create_cd.html.twig');
});
$app->post('/create_cd', function () use($app) {
    $album = new Cd($_POST['newCd'], $_POST['newArtist']);
    $album->save();
    return $app['twig']->render('new_cd.html.twig', array('newcd' => $album));
});
$app->get('/delete_cds', function () use($app) {
    Cd::deleteAll();
    return $app['twig']->render('delete_cds.html.twig');
});
$app->get('/search_by_artist', function () use($app) {
    return $app['twig']->render('search_by_artist.html.twig');
});
$app->post('/results', function () use($app) {
    $results = array();
    $searched_artist = strtolower($_POST['artistSearch']);
    foreach ($_SESSION['list_of_cds'] as $cd) {
        if (strtolower($cd->getArtist()) == $searched_artist) {