Thread: Mys 1.3.4 Riddle Mod
View Single Post
  #3  
Old 02-03-2017, 11:09 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,569
Abronsyth is on a distinguished road
Default

[lots of babbling about what and where and how]

So what we need to do:
Add a new column to adopts_riddle called "fromdate";
Code:
ALTER TABLE  `adopts_riddle` ADD  `fromdate` VARCHAR( 20 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL AFTER  `solve` ;
Then we go into riddleview.php for the fun stuff!

Replace your riddleview.php with this;
PHP Code:
<?php 

use Resource\Native\String
use 
Resource\Collection\LinkedList

class 
RiddleView extends View
     
    public function 
index(){ 
        
$mysidia Registry::get("mysidia"); 
        
$document $this->document;         
        
$document->setTitle("Riddle"); 
        
        
$active $mysidia->db->select("active_riddle", array("name"))->fetchColumn();
    
$ridname $mysidia->db->select("riddle", array("name"), "name = '{$active}'")->fetchColumn();
    
$ridclue $mysidia->db->select("riddle", array("clue"), "name = '{$active}'")->fetchColumn();
    
$ridsolve $mysidia->db->select("riddle", array("solve"), "name = '{$active}'")->fetchColumn();
    
$reward $mysidia->db->select("riddle", array("reward"), "name = '{$active}'")->fetchColumn();
    
    
date_default_timezone_set('EST');
    
$today date('m/d/Y');
                    
            if(
$mysidia->input->post("answer")){
            if(
$mysidia->input->post("solved") == $ridsolve){
            
$document->add(new Comment"Congratulations, you have solved the riddle. You have recieved one {$reward} as a reward!")); 
            
$mysidia->db->insert("solved_riddles", array("name" => $active"uid" => $mysidia->user->uid));
                
$newadopt = new StockAdopt($reward);
                
$newadopt->append($mysidia->user->username);
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }
            else{
            
$document->add(new Comment"Sorry, that is not the correct answer. Feel free to try again!"));
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }        
        }
        
    if(
$mysidia->input->post("add")){
        
$mysidia->db->insert("riddle", array("id" => NULL"name" => $mysidia->input->post("name"), "clue" => $mysidia->input->post("clue"), "fromdate" => $mysidia->input->post("fromdate"), "solve" => $mysidia->input->post("solve"), "reward" => $mysidia->input->post("reward")));                
        
$document->add(new Comment"You have created a new riddle called {$mysidia->input->post("name")}.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;        
    }
    

        
$checkdate $mysidia->db->select("riddle", array("fromdate"), "fromdate ='{$today}'")->fetchColumn();
        
$name $mysidia->db->select("riddle", array("name"), "fromdate ='{$today}'")->fetchColumn();

    if(
$checkdate){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $name));
    }

    
    if(
$mysidia->input->post("activate")){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $mysidia->input->post("currname")));
        
$document->add(new Comment"You have activated a new riddle.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;                
    }
            
            if(
$mysidia->user instanceof Admin){ 
        
$document->add(new Comment"<h2>Manage Riddles</h2>")); 
             
$document->add(new Comment"You can add a new riddle below. Creating a new riddle will not make it the new shown riddle, you do that below. 
                 Riddle answers and names must be the exact name of the pet reward, and they are case sensitive."
));
                 
                 
        
$currForm = new Form("currform""""post");
        
$currForm->add(new Comment("<br><u>Set the Active Riddle:</u><br>"TRUE"b"));
        
$currForm->add(new Comment("<br><b>Current Active Riddle:</b> {$ridname}<br>"TRUE""));
        
$currForm->add(new Comment("Name:"));
        
$currForm->add(new TextField("currname"));
        
$currForm->add(new Button("Activate""activate""submit"));
        
$document->add($currForm);  
         
        
$ridForm = new Form("addform""""post");
        
$ridForm->add(new Comment("<br><u>Create A New Riddle:</u><br>"TRUE"b"));
        
$ridForm->add(new Comment("Name:"));
        
$ridForm->add(new TextField("name"));
        
$ridForm->add(new Comment("Clue:"));
        
$ridForm->add(new TextArea("clue"));
        
$ridForm->add(new Comment("Solve: (answer to the riddle)"));
        
$ridForm->add(new TextField("solve"));
        
$ridForm->add(new Comment("Start Date:(MM/DD/YYYY) or leave blank")); 
            
$ridForm->add(new TextField("fromdate"));
        
$ridForm->add(new Comment("Reward:(the adoptable your member can obtain by solving this riddle.)"));
        
$ridForm->add(new TextField("reward"));
        
$ridForm->add(new Button("Create Riddle""add""submit"));
        
$document->add($ridForm);    
                     
                     
$document->add(new Comment"<hr>"));
        }
                else{ 
$document->add(new Comment"")); 
}
    
$done $mysidia->db->select("solved_riddles", array("name""uid"), "name = '{$active}' and uid = '{$mysidia->user->uid}'")->fetchObject();
    if(
$done){
      
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
           
                
$doneForm = new Form("doneform""""post");
        
$doneForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$doneForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$doneForm->add(new Comment("{$ridclue}"));
        
$doneForm->add(new Comment("<br><h3>You have completed this riddle, good job!</h3>"TRUE"b"));
        
$document->add($doneForm);
        
    }
    
    else{    
        
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
                
$solveForm = new Form("solveform""""post");
        
$solveForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$solveForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$solveForm->add(new Comment("{$ridclue}<br><br>"));
        
$solveForm->add(new Comment("Answer:""""b"));
        
$solveForm->add(new TextField("solved"));
        
$solveForm->add(new Button("Submit Answer""answer""submit"));
        
$document->add($solveForm); 
        
        
    }            
        
            
            
     }
     
}
?>
As far as I can tell this is working. So you can set a current active riddle with no date manually, then as soon as the date matches a date of a riddle in the database, that riddle becomes active until you manually set a new one or a new date/riddle association occurs.
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 02-03-2017 at 11:40 AM.
Reply With Quote