Okay
that code is from a much, much older version of Mysidia and shouldn't be referenced and use cannot be made of it. Some of those include files don't even
exist anymore.
You should read
this guide on making custom pages and it should cover everything you need. Please do read through it all before continuing down this post, or at least reread this post after you've read everything there.
To be specific, and this is covered, you'll need to add a column to a table in your database. Now, depending on the amount of things like this you want to, I'd suggest making a table just to hold data on this. But if it's only going to be a few things, you can always just add a column to the end of the 'adopts_users' table in your database to hold a time reference.
In the examples in the link I gave, we add a column 'lastday' and use it to check time. (Logically, if you're going to have more than one sort of time-based event, you'll need many more intuitively-named columns because they can't all share one.)
Say your page is "/awesomepage".
You will need to make
awesomepage.php -
PHP Code:
<?php
class AwesomePageController extends AppController{
public function __construct(){
parent::__construct("member");
}
public function index(){
$mysidia = Registry::get("mysidia");
}
}
?>
And then
view/awesomepageview.php (so that's inside the view folder) -
PHP Code:
<?php
class AwesomePage extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Super Awesome Page");
if (strtotime($mysidia->user->lastday) < strtotime("-30 days")) {
$document->add(new Comment("It has been at least 30 days since your last visit!", FALSE));
// Give User Item
$item = "Cupcake";
$qty = 1;
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
// Reset Timestamp
$now = new DateTime();
$today = $now->format('Y-m-d');
$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
} else {
$daysleft = strtotime($mysidia->user->lastday);
$document->add(new Comment("We're sorry, 30 days have not yet passed! Please wait {$daysleft} more days!", FALSE));
}
}
}
?>
So long as you've added the column to the database, this should just automatically work. However, it leaves very little room for testing since it will automatically attempt to give the item "Cupcake" and then any visits for the next 30 days should be prevented. You can "comment out" php code to temporarily disable it by wrapping it in /* These */, starting a line with //, and/or starting a line with #.
I super recommend you obtain a nice text editor with syntax highlighting such as Notepad++ or Sublime Text, as it makes coding much easier on the eyes and you can easily see at a glance where things are breaking because the colors will mess up.