The problem presented here allowed me to test Tina4 to see how it would handle this task, below is a set of steps to replicate the solution I came up with. The database is an Sqlite3 database.
I made it pretty with Bootstrap, the core logic is in the HTML file.
After running the Tina4stack do the following
1.) Create a migration with http://localhost:12345/maggy/create,
[php]create table show (
show_id integer primary key,
show_name varchar (200) default ‘’,
show_season varchar (20) default ‘’,
show_episode integer default 1
)[/php]
Run the migration afterwards at http://localhost:12345/maggy
2.) Under the web_root/objects directory, create a file called Show.php, this will map the database.
[php]
class Show extends Olga
{
var $id = 0;
var $showName = “”;
var $season = “”;
var $episode = 1;
var $mapping = ["table" => "show",
"fields" => [
"id" => ["field" => "show_id"],
"showName" => ["field" => "show_name"],
"season" => ["field" => "show_season"],
"episode" => ["field" => "show_episode"]
]
];
}
[/php]
3.) Under the web_root/objects directory create a file called Shows.php, this will give us our list of shows.
[php]
class Shows extends Olga
{
var $mapping = [“table” => “show”, “object” => “Show”]; //maps to the Show object
}
[/php]
4.) Under the web_root/assets/pages directory create a file called shows.html
[php]
My TV Shows Tutorial in Tina4
{{if(!empty($_REQUEST[“showName”]))}}
Success! Added {$_REQUEST[“showName”]}.
{{ShowService:addShow?{$_REQUEST[“showName”]},{$_REQUEST[“showSeason”]},{$_REQUEST[“showEpisode”]}}}
{{endif}}
Show Name
Season
Episode
Add Show
Show Name |
Season |
Episode |
{{ShowService:listShows}}
{showName} |
{season} |
{episode} |
{{/ShowService:listShows}}
[/php]
5.) Finally, under the web_root/project directory add a file called ShowService.php, this lists the shows and has some simple logic to replace a show if the name already exists.
[php]
class ShowService
{
/**
* List all the shows
* @return Array
*/
function listShows() {
$shows = (new Shows());
$shows->load();
return json_decode($shows->toJSON());
}
/**
* Adding a new show
* @param $showName
* @param $season
* @param $episode
*/
function addShow($showName, $season, $episode) {
//see if show exists
$show = (new Show())->getBy(["showName" => $showName]);
//update the values
$show->setShowName($showName);
$show->setSeason($season);
$show->setEpisode($episode);
$show->save();
}
}
[/php]
That’s it, you should have a form with the grid on the side.
See the running sample at http://localhost:12345/shows
Ruth automatically routes to the shows.html file.