Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2015, 03:46 PM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,519
cailynmae is on a distinguished road
Lightbulb Explore Help?

Kyttias helped me get this working, I give her my deepest gratitude. I don't need help anymore.

Last edited by cailynmae; 04-11-2015 at 01:53 PM. Reason: I got help, explore system working. Thanks Kyttias!
Reply With Quote
  #2  
Old 04-09-2015, 05:31 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 109,718
Kyttias is on a distinguished road
Default

Ok, I'll begin with more of a general how-to guide to making your own pages before moving on to your specific questions at the end. It's good to have all this sort of in one place -- it'll help you do other stuff in the future, yeah?

Pages can be found in the root directory - or, well, their hard-coded side is there, anywhere. The view side is found in the view folder. It is necessary, to make a page, to make a file in each, following the same naming conventions as the others. I'd observe donate and donateview as an example, since they're pretty simple files. Usually I've been keeping my own 'page' files nearly empty, save for what needs to be there for it to operate, and only putting code into their 'pageview' file counterparts. Both exist in cases where you'd need to handle things like form submission.

Basics
As an example, for myself, I'll be creating a new page for pet missions. It will be accessible at "mysite.com/missions":

/missions.php
PHP Code:
<?php
class MissionsController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
    }
    
}
?>
/view/missionsview.php
PHP Code:
<?php
class MissionsView extends View{

    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        
$document->setTitle("Mission List");    
        
$document->add(new Comment("This page will contain missions you can send your pets on."FALSE));
    }
    
}
?>
PHP is case-sensitive language. This means "Catfish" is different than "catfish" and most definitely different than "cAtFiSh". Name variables and documents the same everywhere - best just to use all lowercase all the time if you're a novice so you can't go wrong.

Pretty basic thus far. You can see that a document in view needs its title set. Then you can see I'm adding text to the page by adding a new Comment to the $document. The comment is in double quotes, and can contain HTML. Any HTML inside it that may need double quotes needs them replaced instead with single quotes. When you absolutely need to use double quotes, escape them by placing a backslash before them:

PHP Code:
$document->add(new Comment("<div class='example'>This div a class of \".example\" associated with it.</div>"FALSE)); 
The real syntax here is just:

PHP Code:
$document->add(new Comment("")); 
And by default, all new Comments will have a linebreak after them unless you add a comma and the parameter FALSE. See above? It is my personal preference to always use the FALSE parameter because I want control of when there are linebreaks. If I want to write solid blocks of HTML, well, darn right I'm going to.

Preventing Users Not Logged In
In missions.php, this is one of the functions I included:
PHP Code:
public function __construct(){
    
parent::__construct("member");

This function will prevent anyone not logged in from accessing the page. It will display only a generic error. If you want specific information to display, then remove the above function, and over in missionsview.php, add this (for clarity's sake, I recommend right after $document = $this->document;), it's an if statement reading "if the mysidia user is NOT logged in", the NOT bit coming from the !:

PHP Code:
if (!$mysidia->user->isloggedin) {
    
$document->setTitle("Feature: Mission List");    
    
$document->add(new Comment("Logged in users can send their pets on missions!"FALSE));

User Variables
Alright, let's talk about what sort of stuff you have access to. Well, anything, actually, so long as you know how! This framework is 'object oriented'. Object oriented PHP differs from standard, procedural PHP only in that it adds some new features. To a beginner, it's a lot of overwhelming, confusing new syntax. I'm new at this myself, but I'll try my best to explain.

Let's start with this magical, important line (you'll see I've already included it in the files above):
PHP Code:
$mysidia Registry::get("mysidia"); 
We need this so we can have the variable '$mysidia' contain a dynamic, yet static, link to the parent class called "mysidia", so we can invoke methods and properties from it.You only need to define $mysidia once inside of a function, so best to do it very early on.

Let's keep our view/missionsview.php file open (or whatever you chose to name yours), but also go open up our database. (On your hosting look for phpMyAdmin, it'll probably prompt you to log in.) Our first stop will be the table adopts_users.

For ease of access, all of the columns in this particular table are accessible with the keyword 'user'. The framework already knows which user is logged in, and will pull data from the current user in the form of a variable. If you want to insert a variable into your page, you can wrap it in curly braces:

PHP Code:
$document->add(new Comment("
    User ID#: 
{$mysidia->user->uid} <br/>
    Username: 
{$mysidia->user->username} <br/>
    Birthday: 
{$mysidia->user->birthday} <br/>
    Member Since: 
{$mysidia->user->membersince} <br/>
"
FALSE)); 
Accessing The Database
You'll notice not all of a user's data was stored in adopts_users. There's some more stored in adopts_users_profile. But how to get at it? Well, we can fetch the whole row relating to a current user like this:

PHP Code:
$row $mysidia->db->select("users_profile", array(), "uid ='{$mysidia->user->uid}'")->fetchObject();
foreach(
$row as $key => $val){
    
$this->$key $val;
}
$document->add(new Comment("
    Gender: 
{$this->gender} <br/>
    Nickname: 
{$this->nickname} <br/>
"
FALSE)); 
We're storing the row as an object attached to the variable $row. We then need to iterate through each of the columns in that row, so we're attaching them to key value pairs and making them global to this file. Meaning, accessible with the keyword 'this'.

What if we wanted to do something crazier, like count the total number of pets this user owns? Or find out what pet type they own the most of, and just how many of that pet they own?

PHP Code:
$totalpets $mysidia->db->select("owned_adoptables", array(), "owner = '{$mysidia->user->username}'")->rowCount();    
$most_owned $mysidia->db->query("SELECT type, COUNT(type) AS favpet FROM adopts_owned_adoptables WHERE owner = '{$mysidia->user->username}' GROUP BY type ORDER BY COUNT(*) DESC LIMIT 1")->fetchObject();
$document->add(new Comment("            
    Total Pets Owned: 
{$totalpets} <br/>
    Most Owned Pet: 
{$most_owned->type} ({$most_owned->favpet})<br/>
"
FALSE)); 
I'd like to bring special attention to $most_owned above, because the query string it uses is a normal, raw SQL string. If all else fails after you've read up on SQL queries, try using $mysidia->db->query() like above. Usually select() will do for pulling information, but if you need complicated selectors like that last example, you still can do it in a semi-standard fashion!

For more information on database-related stuff, I'm going to direct you to this other post I made, and some more examples of queries I made to add to my stats page.

Classes
In object oriented programming, classes exist. Classes hold functions as 'methods' that can be reused again and again, to prevent writing redundant code. There's actually some pre-constructed functions you can use with $mysidia->user as before - thanks to the Member class! (Jeez, why didn't you say so, Kyt?)

It's not immediately obvious - if you open up classes/class_user.php, you don't actually see much going on. But go open up classes/class_member.php - whaaaat, class Member extends User? Let's test one out

PHP Code:
$document->add(new Comment("
    Total Pets Owned: 
{$mysidia->user->getalladopts()}
"
FALSE)); 
(But we already did that! You're telling me we didn't even have to?!) Nope, you didn't. Notice that it's getalladopts(). It's a function, not a variable, so it needs those parentheses.

Ok, but what if we're not dealing with an user, but a pet? Well, we can instantiate a pet by it's id number, if we know it, as being a 'new OwnedAdoptable' - and then we'll have access to all the properties and functions available from classes/class_ownedadoptable.php. The OwnedAdoptable class takes the pet's adoptable id, it's aid, as a parameter.

So, let's pick a random pet owned by the user:
PHP Code:
$random_pet $mysidia->db->select("owned_adoptables", array(), "owner='{$mysidia->user->username}' ORDER BY RAND() LIMIT 1")->fetchObject();
$chosen_pet = new OwnedAdoptable($random_pet->aid);
$document->add(new Comment("            
    Pet Name: 
{$chosen_pet->getName()} <br/>
    Pet Level: 
{$chosen_pet->getCurrentLevel()}<br/>
"
FALSE)); 
What Now?
You want to build an explore page, right? Well, now you know how to insert HTML into a page. I assume you've read up on plenty of tutorials on imagemaps, so you have a pretty good idea of what you're doing, so I'll jump right to your specific questions.
  • Give a user some currency:
    PHP Code:
    $amount 1000;
    $mysidia->user->changecash($amount); 
  • Give a user a pet:
    PHP Code:
    $species "Dezh";
    $newadopt = new StockAdopt($species);
    $newadopt->append($mysidia->user->username); 
  • Give a user an item:
    PHP Code:
    $item "Beta Cupcake";
    $qty 1;
    $newitem = new StockItem($item);
    $newitem->append($qty$mysidia->user->username); 
  • Retrieve New Database Properties:
    The good news is, the Member class automatically iterates all the columns inside adopts_users, so since your plan was to add columns there, you can literally access your new properties as variables with $mysidia->user->lastday and $mysidia->user->exploretimes - neat, huh?
  • Check Time Difference:
    PHP Code:
    if (strtotime($mysidia->user->lastday) < strtotime("-1 day")) {
        
    $document->add(new Comment("You explored last over a day ago."));

  • Update The Database:
    PHP Code:
    $now = new DateTime();
    $today $now->format('Y-m-d');
    $mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
    $mysidia->db->update("users", array("exploretimes" => ($mysidia->user->exploretimes 1)), "username = '{$mysidia->user->username}'"); 
  • Premium Only Content:
    In your database, go ahead and change the structure of adopts_users_status to add a column to contain a VARCHAR 3 with Default 'As defined:' No. Then you can perform this check with ease:
    PHP Code:
    if($mysidia->user->status->premium != "yes"){
        
    $document->add(new Comment("No, you're not a premium member!"));
    } else {
        
    $document->add(new Comment("Welcome to this premium area!"));

  • Checking if user has an item:
    PHP Code:
    $item "Beta Cupcake";
    $hasitem $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner='{$mysidia->user->username}'")->fetchColumn();
    if(
    $hasitem){
        
    $document->add(new Comment("You have a {$item}!"));
    } else {
        
    $document->add(new Comment("Sorry, you do not have a {$item}!"));

  • Check the season:
    PHP Code:
    $currentMonth date("m");
    if (
    $currentMonth >= "03" && $currentMonth <= "05"){$season "spring";}
    elseif (
    $currentMonth >= "06" && $currentMonth <= "08"){$season "summer";}
    elseif (
    $currentMonth >= "09" && $currentMonth <= "11"){$season "fall";}
    else {
    $season "winter";}
    $document->add(new Comment("It is {$season}!")); 

Whew, that was fun. Let me know if there's anything else!
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-17-2016 at 01:06 PM.
Reply With Quote
  #3  
Old 04-10-2015, 07:59 AM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,519
cailynmae is on a distinguished road
Default

Wow, thanks. That's pretty much all I need to know. I'll try it out a little later today, since I have some stuff to do. Thank you so much! This was very helpful.
Reply With Quote
  #4  
Old 04-11-2015, 05:56 AM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,519
cailynmae is on a distinguished road
Default

It's working! I just have to make the map, and the items and pets.
Reply With Quote
  #5  
Old 04-11-2015, 07:01 AM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,519
cailynmae is on a distinguished road
Default

Hmm, I take that back. Yesterday it was working just fine, today it is acting as though the explore pages(not the main one, though) don't exist. Hmm, odd...
EDIT: Okay, I got that fixed, but now it's not resetting exploretimes to 0 when it's supposed to...
EDIT AGAIN: And I fixed that! Yay!

Last edited by cailynmae; 04-11-2015 at 12:24 PM. Reason: found a solution
Reply With Quote
  #6  
Old 04-12-2015, 10:18 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 109,718
Kyttias is on a distinguished road
Default

I'm glad things are working out! I actually learned a little bit while making my post, even. Mind if I repost some of this information a little later and ask for it to be stickied as a guide? I want to investigate form submission a little more first, like how to fill a drop down list with a list of pets, and run a few input validation tests so I can discuss security when I teach how to make forms, too. Is there anything else you'd like covered in a guide?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #7  
Old 04-14-2015, 06:39 PM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,519
cailynmae is on a distinguished road
Default

Sure, I actually was thinking this would be very helpful to someone looking to create an explore system. Maybe I'll make a proper mod to make things easier for people when I have some time(with your permission, of course). Thanks for your help, you can totally use your advice elsewhere if you want to.
Reply With Quote
  #8  
Old 03-29-2017, 11:37 PM
ewe ewe is offline
Member
 
Join Date: Mar 2017
Posts: 8
Gender: Female
Credits: 2,014
ewe is on a distinguished road
Default

Kyttias' posts have helped me immensely but it seems I hate to leave well enough alone.

Here's code for more specific seasons:

PHP Code:
    if(new DateTime() < new DateTime($dateTime->format('Y').'-3-20 00:00:00')) $season 'winter';
    else if (new 
DateTime() < new DateTime($dateTime->format('Y').'-6-21 00:00:00')) $season 'spring';
    else if (new 
DateTime() < new DateTime($dateTime->format('Y').'-9-22 00:00:00')) $season 'summer';
    else if (new 
DateTime() < new DateTime($dateTime->format('Y').'-12-20 00:00:00')) $season 'fall';
    else 
$season 'winter';
$document->add(new Comment("It is {$season}!")); 

Last edited by ewe; 03-29-2017 at 11:51 PM.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quest- Explore System (Open Source) squiggler Tutorials and Tips 4 07-23-2020 12:07 PM
How To Create an Explore System in Mys. 1.3.4 cailynmae Tutorials and Tips 42 07-17-2017 01:25 PM


All times are GMT -5. The time now is 02:45 PM.

Currently Active Users: 796 (0 members and 796 guests)
Threads: 4,081, Posts: 32,029, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636