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-14-2017, 06:19 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 67,622
Dinocanid is on a distinguished road
Default Creating user shops

I have a grasp of what I need to do, but I'm having trouble figuring out how adopt shops are created without their own separate php files, like how you do it through the adminCP. I managed to make a way for users to create/edit/remove shops by making a table in the database similar to how other shops are stored:

PHP Code:
<?php

use Resource\Native\String;
use 
Resource\Collection\LinkedHashMap;

class 
ShopcpController extends AppController{

    const 
PARAM "usid";
    
    public function 
__construct(){
        
parent::__construct();
        
$mysidia Registry::get("mysidia");
        if(
$mysidia->usergroup->getpermission("groupname") != "rootadmins"){
            throw new 
NoPermissionException("Sorry! Only admins can test user shops at this time!");
        }        
    }
    
    public function 
index(){
        
parent::index();
        
$mysidia Registry::get("mysidia");
        
$stmt $mysidia->db->select("user_shops");
        
$num $stmt->rowCount();
        if(
$num == 0) throw new InvalidIDException("You don't have a shop!");            
        
$this->setField("stmt", new DatabaseStatement($stmt));
    }
    
    public function 
add(){
        
$mysidia Registry::get("mysidia");    
        if(
$mysidia->input->post("submit")){
            
$this->dataValidate();
            
$npc_url = (!$mysidia->input->post("npc_url"))?$mysidia->input->post("existingnpc_url"):$mysidia->input->post("npc_url");
            
$tax = (!$mysidia->input->post("tax"))?0:$mysidia->input->post("tax");
            
$mysidia->db->insert("user_shops", array("us_name" => $mysidia->input->post("us_name"), "npc_url" => $npc_url
                                                
"description" => $mysidia->input->post("description"), "tax" => $tax"manager_id" => $mysidia->user->uid));    
        }    
    }
    
    public function 
edit(){
        
$mysidia Registry::get("mysidia");
        if(!
$mysidia->input->get("usid")){
            
$this->index();
            throw new 
NoPermissionException("You do not own this shop!");
            return;
        }
        elseif(
$mysidia->input->post("submit")){
            
$this->dataValidate();
            
$npc_url = (!$mysidia->input->post("npc_url"))?$mysidia->input->post("existingnpc_url"):$mysidia->input->post("npc_url");
            
$tax = (!$mysidia->input->post("tax"))?0:$mysidia->input->post("tax");
            
$mysidia->db->update("user_shops", array("us_name" => $mysidia->input->post("us_name"), "description" => $mysidia->input->post("description"), "npc_url" => $npc_url,
                                                
"status" => $mysidia->input->post("status"), "tax" => $tax), "usid='{$mysidia->input->get("usid")}'");        
            return;
        }
        else{
            
$shop $mysidia->db->select("user_shops", array(), "usid='{$mysidia->input->get("usid")}'")->fetchObject();        
            if(!
is_object($shop)) throw new InvalidIDException("nonexist");
            
$this->setField("user_shop", new DataObject($shop));    
        }
    }

    public function 
delete(){
           
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();
        if(
$mysidia->user->uid !== $mysidia->input->get("manager_id")){
            
$this->index();
            throw new 
NoPermissionException("You do not own this shop!");
            return;
        }
        
$mysidia->db->delete("user_shops""usid='{$mysidia->input->get("usid")}'");
    }

     private function 
dataValidate(){
        
$mysidia Registry::get("mysidia");
        if(!
$mysidia->input->post("us_name")) throw new BlankFieldException("us_name");    
        if(!
$mysidia->input->post("npc_url") and $mysidia->input->post("existingnpc_url") == "none") throw new BlankFieldException("images"); 
        if(!
$mysidia->input->post("status")) throw new BlankFieldException("status");
        if(
$mysidia->input->post("tax") < 0) throw new InvalidActionException("tax");
        
        
$shop $mysidia->db->select("user_shops", array(), "us_name = '{$mysidia->input->post("us_name")}'")->fetchObject();
        if(
$this->action == "add" and is_object($shop)) throw new DuplicateIDException("duplicate");
        return 
TRUE;
    }
}
?>
(shopcp.php)

PHP Code:
<?php

use Resource\Native\String;
use 
Resource\Collection\LinkedHashMap;

class 
ShopcpView extends View{
    
    public function 
index(){
        
parent::index();
        
$stmt $this->getField("stmt")->get();            
        
$document $this->document;
        
        
$fields = new LinkedHashMap;
        
$fields->put(new String("npc_url"), new String("getImage"));
        
$fields->put(new String("us_name"), NULL);
        
$fields->put(new String("description"), NULL);
        
$fields->put(new String("status"), NULL);            
        
$fields->put(new String("usid::edit"), new String("getEditLink"));
        
$fields->put(new String("usid::delete"), new String("getDeleteLink"));
        
        
$shopTable = new TableBuilder("shop");
        
$shopTable->setAlign(new Align("center""middle"));
        
$shopTable->buildHeaders("NPC Image""Shop""Description""Status""Edit""Delete");
        
$shopTable->setHelper(new ShopTableHelper);
        
$shopTable->buildTable($stmt$fields);
        
$document->add($shopTable);        
    }
    
    public function 
add(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        if(
$mysidia->input->post("submit")){
            
$document->setTitle($this->lang->added_title);
            
$document->addLangvar($this->lang->added);
            return;
        }
        
        
$document->setTitle($this->lang->add_title);
        
$document->addLangvar($this->lang->add);
        
$shopForm = new FormBuilder("addform""add""post");
        
$shopForm->add(new Comment("<br><u><h2>Create A New Shop:</u></h2>"TRUE"b"));
        
$shopForm->add(new Comment("<hr>-Basic Settings-"TRUE"b"));
        
$shopForm->add(new Comment("Shop Name: "FALSE));
        
$shopForm->add(new TextField("us_name"));
        
$shopForm->add(new Comment($this->lang->us_name_explain));
        
$shopForm->add(new Comment("<br></br>"));
        
        
$shopForm->add(new Comment("Shop Description:"));
        
$shopForm->add(new TextArea("description""Here you can enter a description for your shop"450));
        
$shopForm->add(new Comment("Shop NPC Image: "FALSE));
        
$shopForm->add(new TextField("npc_url"));
        
$shopForm->add(new Comment($this->lang->npc_url_explain));
        
        
$shopForm->add(new Comment("<hr>-Miscellaneous Settings-"TRUE"b"));
        
$shopForm->add(new Comment("Shop Status: "FALSE));
        
$shopStatus = new RadioList("status");
        
$shopStatus->add(new RadioButton("Open""status""open"));
        
$shopStatus->add(new RadioButton("Closed""status""closed"));
        
//$shopStatus->add(new RadioButton("Hidden", "status", "invisible"));
        
$shopStatus->check("closed");
        
$shopForm->add($shopStatus);
        
$shopForm->add(new Comment("Non-Resident Tax: "FALSE));
        
$shopForm->add(new TextField("NRtax"));
        
$shopForm->add(new Comment($this->lang->nrtax_explain));
        
$shopForm->add(new Comment("<br></br>"));
        
$shopForm->add(new Button("Create Shop""submit""submit"));
        
$document->add($shopForm);        
    }
    
    public function 
edit(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;    
        if(!
$mysidia->input->get("usid")){
            
$this->index();
            return;
        }
        elseif(
$mysidia->input->post("submit")){
            
$document->setTitle($this->lang->edited_title);
            
$document->addLangvar($this->lang->edited);
            return;
        }
        else{
            
$shop $this->getField("user_shop")->get();
            
$document->setTitle($this->lang->edit_title);
            
$document->addLangvar($this->lang->edit);            
            
$shopForm = new FormBuilder("editform"$mysidia->input->get("usid"), "post");
            
$shopForm->add(new Comment("<br><u>Edit an existing Shop:</u>"TRUE"b"));
            
$shopForm->add(new Comment("Basic Settings"TRUE"b"));
            
$shopForm->add(new Comment("Shop Name: "FALSE));
            
$shopForm->add(new TextField("us_name"$shop->us_name));
            
$shopForm->add(new Comment($this->lang->us_name_explain));
            
$shopForm->add(new Comment("Shop Description:"));
            
$shopForm->add(new TextArea("description"$shop->description450));
            
$shopForm->add(new Comment("Shop NPC Image: "FALSE));
            
$shopForm->add(new TextField("npc_url"$shop->npc_url));
            
$shopForm->add(new Comment($this->lang->npc_url_explain));
        
            
$shopForm->add(new Comment("<hr>Miscellaneous Settings:"TRUE"b"));
            
$shopForm->add(new Comment("Shop Status: "FALSE));
            
$shopStatus = new RadioList("status");
            
$shopStatus->add(new RadioButton("Open""status""open"));
            
$shopStatus->add(new RadioButton("Closed""status""closed"));
            
//$shopStatus->add(new RadioButton("Hidden", "status", "invisible"));
            
$shopStatus->check($shop->status);
            
$shopForm->add($shopStatus);
            
$shopForm->add(new Comment("Non-Resident Tax: "FALSE));
            
$shopForm->add(new TextField("NRtax"$shop->tax));
            
$shopForm->add(new Comment($this->lang->nrtax_explain));
            
$shopForm->add(new Button("Edit Shop""submit""submit"));
            
$document->add($shopForm);        
        }
    }

    public function 
delete(){
           
$mysidia Registry::get("mysidia");
        
$document $this->document;
        if(!
$mysidia->input->get("usid")){
            
$this->index();
            return;
        }
        
$document->setTitle($this->lang->delete_title);
        
$document->addLangvar($this->lang->delete);
        
header("Refresh:3; URL='../../shopcp'");
    }
}
?>
(shopcpview.php)

The shop is made, but it somehow needs to be able to be accessed like an actual shop. I planned to have it set up like other sites where the pet in question is still owned by the user selling it until another user buys it, which wouldn't be too difficult. You would just have to add another column to owned adoptables for the usid (user shop ID) and whether or not it is for sale, then a table could just fetch them for the display and from there it would work somewhat similar to the trade code already on the site. There is also the problem of users being able to edit and delete shops that don't belong to them by changing the ID in the url. I tried to remedy this with:
PHP Code:
 if($mysidia->user->uid !== $mysidia->input->get("manager_id")){
 
code for the error goes here 

But it just throws an error saying that the shop does not belong to the user, even if the manager_id and uid match.
__________________
Reply With Quote
  #2  
Old 04-21-2017, 10:09 AM
kristhasirah's Avatar
kristhasirah kristhasirah is offline
Member
 
Join Date: Jan 2010
Location: In middle of the nothingness
Posts: 196
Gender: Female
Credits: 28,968
kristhasirah
Default

dont know if you already fixed this but here is something that works for me as im using the shops as base to create groups for my page and this stops the users from editing others shops
so try changing this:
PHP Code:
            $shop $mysidia->db->select("user_shops", array(), "usid='{$mysidia->input->get("usid")}'")->fetchObject(); 
for this:
PHP Code:
            $shop $mysidia->db->select("user_shops", array(), "usid='{$mysidia->input->get("usid")}' and manager_id = '{$mysidia->user->uid}'")->fetchObject(); 
and for showing only the shops for each user you can try this:
PHP Code:
        $stmt $mysidia->db->select("user_shops", array(), "manager_id = '{$mysidia->user->uid}'"); 
please note that im assuming that manager_id is where you have stored the owner of the shop... as im using owner as the name for the row where the username is stored when a group is created by that user ^^ so if the code above don't work
then try changing the manager_id = '{$mysidia->user->uid}'
for manager_id = '{$mysidia->user->username}' or owner = '{$mysidia->user->username}'

hope this works for you =)
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


All times are GMT -5. The time now is 10:20 AM.

Currently Active Users: 852 (0 members and 852 guests)
Threads: 4,080, Posts: 32,024, 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