Beispiel #1
0
/** Function getInfoFilm
	return all movies with all information. It's possible to precised an attribute of the movie

	@param db connector PDO of the db
	@param attr array of filter for table movies /!\ Special syntax !!!  Look example /!\
	@param filter array of filter for other table /!\ Special syntax

	@return Success = array of Movies, Echec = False

	@example
	Example of attributes
	- field is the field in database
	- value : is the value for the test ('%r%' or '1', ...)
	- sign : is the sign for the comparation for permit compart string with special test % or _ ( '=' or 'LIKE', ...)
	$attr = array(
			'field' => array(
				'value', 'sign'
		);

	Example of filter
	- field is the type of filter ('genres', 'countries', 'studios', 'actor', 'writer', 'director', 'producer', )
	- value is the value for make filter /!\ add % caracter where you want for actor, writer, director and producer
	$filter = array(
				'field' => value,
				'actor' => %sara%toto%
	)
	*/
function getInfoMovies($db, $attr = array(), $filter = array())
{
    //recure filter array
    $secur = array('genres' => false, 'studios' => false, 'countries' => false, 'actor' => false, 'writer' => false, 'producer' => false, 'director' => false);
    $filter = array_merge($secur, $filter);
    $query = 'SELECT * FROM movies ';
    $query .= 'INNER JOIN files ON files.`fkMovies` = movies.`idMovies` ';
    $first = true;
    foreach ($attr as $key => $value) {
        $sign = $value[1];
        if ($first) {
            $first = false;
            $query .= "WHERE movies.{$key} {$sign} '{$value[0]}' ";
        } else {
            $query .= "AND movies.{$key} {$sign} '{$value[0]}' ";
        }
    }
    $query .= "GROUP BY movies.`idMovies`";
    $req = $db->prepare($query);
    if (!$req->execute()) {
        $error = $req->errorCode();
        $error = "Error occurred during the execution of the request ('{$error}')";
        //echo $error;
        return false;
    }
    if ($req->rowCount() >= 1) {
        $result = $req->fetchAll();
    } else {
        return false;
    }
    for ($i = 0, $size = count($result); $i < $size; $i++) {
        $id = $result[$i]["idMovies"];
        /* Need REWORK ! */
        if (($result[$i]["genres"] = getGenres($db, $id, $filter['genres'])) === false && $filter['genres'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["countries"] = getCountries($db, $id, $filter['countries'])) === false && $filter['countries'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["writer"] = getPeople($db, $id, DB_WRITER_TYPE, $filter['writer'])) === false && $filter['writer'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["director"] = getPeople($db, $id, DB_DIRECTOR_TYPE, $filter['director'])) === false && $filter['director'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["actor"] = getPeople($db, $id, DB_ACTOR_TYPE, $filter['actor'])) === false && $filter['actor'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["producer"] = getPeople($db, $id, DB_PRODUCER_TYPE, $filter['producer'])) === false && $filter['producer'] !== false) {
            unset($result[$i]);
            continue;
        }
        if (($result[$i]["studios"] = getStudios($db, $id, $filter['studios'])) === false && $filter['studios'] !== false) {
            unset($result[$i]);
            continue;
        }
    }
    return $result;
}
Beispiel #2
0
/**
 * Generate studios array for use with studio checkboxes
 *
 * @param  array $selected  selected studio IDs
 * @return                  string HTML for studio checkboxes
 */
function out_studios2($item_studios = null)
{
    // get detailed studios
    $all_studios = getStudios();
    $studios = array();
    foreach ($all_studios as $stud) {
        // selected?
        if ($item_studios) {
            $stud['checked'] = @in_array($stud['id'], $item_studios) ? 1 : 0;
        }
        $studios[] = $stud;
    }
    return $studios;
}