Esempio n. 1
0
 public function execute($params)
 {
     $type = $params['type'];
     $query = \Engine\MovieQuery::create();
     if ($type === null) {
         $query = $query->find();
     } elseif ($type === 'title') {
         $value = '%' . $params['value'] . '%';
         $query = $query->filterByTitle($value)->groupByTitle()->find();
     } else {
         $values = preg_split('/\\s+/', $params['value']);
         $num_values = 0;
         $query = $query->useActorQuery();
         //match names and surnames against all param values
         foreach ($values as $key => $value) {
             $values[$key] = '%' . $value . '%';
             $query = $query->where('Actor.Name LIKE ?', $values[$key])->_or();
             ++$num_values;
         }
         --$num_values;
         for ($i = 0; $i < $num_values; ++$i) {
             $query = $query->where('Actor.Surname LIKE ?', $values[$i])->_or();
         }
         $query = $query->where('Actor.Surname LIKE ?', $values[$num_values])->endUse()->groupByTitle()->find();
     }
     foreach ($query as $movie) {
         $movie->getActors();
     }
     return ['Movies' => $query->toArray(), 'Status' => 1];
 }
Esempio n. 2
0
 public function execute($params)
 {
     $id = $params['id'];
     $movie = \Engine\MovieQuery::create()->findPK($id);
     $movie->setTitle($params['title']);
     $movie->setYear($params['year']);
     $movie->setFormat($params['format']);
     $actors = [];
     //generate array of new actors
     foreach ($params['actor_name'] as $key => $name) {
         $actor = new \Engine\Actor();
         $actor->setMovieId($id);
         $actor->setName($name);
         $actor->setSurname($params['actor_surname'][$key]);
         $actors[] = $actor;
     }
     //propel accepts a collection to set related data
     $collection = new \Propel\Runtime\Collection\ObjectCollection($actors);
     $con = \Propel\Runtime\Propel::getWriteConnection(\Engine\Map\MovieTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         //set collection of actors; this automatically deletes old related actors
         $movie->setActors($collection);
         $movie->save($con);
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
     return ['Message' => 'Movie has beed updated successfully.', 'Status' => 1];
 }
Esempio n. 3
0
 public function execute($params)
 {
     $id = (int) $params['id'];
     $movie = \Engine\MovieQuery::create()->filterById($id)->delete();
     if ($movie === null) {
         throw new \Service\X(['Message' => 'Wrong movie index', 'Fields' => '$params[\'id\']', 'Type' => 'Query Error']);
     }
     return ['Message' => 'Movie has beed successfully deleted', 'Status' => 1];
 }
Esempio n. 4
0
 public function execute($params)
 {
     $movie = \Engine\MovieQuery::create()->findPK($params['id']);
     if ($movie === null) {
         throw new \Service\X(['Message' => 'Wrong id', 'Fields' => 'id', 'Type' => 'WRONG_ID']);
     }
     $actors = $movie->getActors();
     $movie = $movie->toArray();
     $movie['Actors'] = $actors->toArray();
     return ['Movie' => $movie, 'Status' => 1];
 }
Esempio n. 5
0
 public function testPositiveMovies()
 {
     $this->get('/api/v1/movies/');
     $response_json = $this->client->response->body();
     $response_obj = json_decode($response_json, 1);
     $movies = \Engine\MovieQuery::create()->find();
     foreach ($movies as $movie) {
         $movie->getActors();
     }
     $movies = json_encode($movies->toArray());
     $rules = ['Status' => ['required', ['equals' => 1]]];
     $this->assertLIVR($response_obj, $rules);
     $this->assertEquals(json_encode($response_obj['Movies']), $movies);
 }
Esempio n. 6
0
 /**
  * Get the associated ChildMovie object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildMovie The associated ChildMovie object.
  * @throws PropelException
  */
 public function getMovie(ConnectionInterface $con = null)
 {
     if ($this->aMovie === null && $this->movie_id !== null) {
         $this->aMovie = ChildMovieQuery::create()->findPk($this->movie_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aMovie->addActors($this);
            */
     }
     return $this->aMovie;
 }
Esempio n. 7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Movie::setDeleted()
  * @see Movie::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(MovieTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildMovieQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Esempio n. 8
0
 /**
  * Performs an INSERT on the database, given a Movie or Criteria object.
  *
  * @param mixed               $criteria Criteria or Movie object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(MovieTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Movie object
     }
     if ($criteria->containsKey(MovieTableMap::ID) && $criteria->keyContainsValue(MovieTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . MovieTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = MovieQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
Esempio n. 9
0
 public static function create($config)
 {
     // Create monolog logger and store logger in container as singleton
     // (Singleton resources retrieve the same log resource definition each time)
     // Prepare app
     $app = new \Slim\Slim($config['slimOptions']);
     $app->config = $config;
     $app->container->singleton('log', function () use($app) {
         $log = new \Monolog\Logger($app->config['loggerOptions']['name']);
         $log->pushHandler(new \Monolog\Handler\StreamHandler($app->config['loggerOptions']['filepath'], \Monolog\Logger::DEBUG));
         return $log;
     });
     $app->get('/:path*', function () use($app) {
         $dirJs = '../public/static/js/min';
         $dirCss = '../public/static/css/min';
         $cssFile = '';
         $jsFile = '';
         if (is_dir($dirJs)) {
             $dirHandler = opendir($dirJs);
             while (false !== ($file = readdir($dirHandler))) {
                 if ($file !== '.' && $file !== '..') {
                     $jsFile = $file;
                 }
             }
             closedir($dirHandler);
         }
         if (is_dir($dirCss)) {
             $dirHandler = opendir($dirCss);
             while (false !== ($file = readdir($dirHandler))) {
                 if ($file !== '.' && $file !== '..') {
                     $cssFile = $file;
                 }
             }
             closedir($dirHandler);
         }
         if (defined('MODE') && MODE == 'DEV') {
             $link = 'head-include-full-links.html.twig';
             $script = 'head-include-full-scripts.html.twig';
         } else {
             $link = 'head-include-min-link.html.twig';
             $script = 'head-include-min-script.html.twig';
         }
         $app->render('main.html', ['link' => $link, 'script' => $script, 'cssFile' => $cssFile, 'jsFile' => $jsFile]);
     });
     /*
      * API routes
      */
     $app->group('/api/v1', function () use($app) {
         $indexActions = new \Controller\Index($app);
         $app->get('/', [$indexActions, 'index'])->name('index');
         $upload = new \Controller\Upload($app);
         $app->post('/upload', [$upload, 'index'])->name('post_upload');
         $app->group('/movies', function () use($app) {
             $movies = new \Controller\Movies($app);
             $app->post('/', [$movies, 'create'])->name('movies_postcreate');
             $app->get('(/(:type(/(:value))))', [$movies, 'index'])->name('movies_show');
             $app->post('/:id', [$movies, 'update'])->name('movies_putupdate');
             $app->delete('/:id', [$movies, 'delete'])->name('movies_delete');
         });
     });
     /*
      * temporary interface for views; to be deleted
      */
     $app->get('/', function () use($app) {
         $query = \Engine\MovieQuery::create()->find();
         $movies = $query->toArray();
         $app->render('/index.php', ['movies' => $movies]);
     })->name('ui_delete');
     //txt uploads
     $app->get('/upload', function () use($app) {
         $app->render('/upload.php', ['result_message' => '']);
     })->name('get_upload');
     //movies creation
     $app->get('/create', function () use($app) {
         $app->render('/create.php', ['message' => '']);
     })->name('movies_getcreate');
     $app->get('/update/:id', function ($id) use($app) {
         $movie = \Engine\MovieQuery::create()->findPK($id);
         $actors = $movie->getActors();
         $movie = $movie->toArray();
         $movie['Actors'] = $actors->toArray();
         $app->render('/update.php', ['movie' => $movie]);
     })->name('movies_getupdate');
     $app->add(new \Slim\Middleware\CSRFProtection());
     return self::$slimInstance = $app;
 }