Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 04-24-2015, 03:23 PM
AndromedaKerova's Avatar
AndromedaKerova AndromedaKerova is offline
ChibiFur Queen
 
Join Date: Nov 2014
Location: England
Posts: 83
Gender: Female
Credits: 4,997
AndromedaKerova is on a distinguished road
Default

Well I couldn't even understand what I'm really supposed to have done without the example.

I think I managed to get the open status right though.

I didn't even bother altering the adopts shop one since I don't have one yet but would like it altered for when I'm ready to add shop only adopts.

Code:
<?php

use Resource\Collection\LinkedList;

class Itemshop extends Model{

    public $sid;
    public $category;
    public $shopname;
    public $shoptype;
    public $description;
    public $imageurl;
    public $status;
    public $restriction;
    public $salestax;
    public $items;
    protected $total = 0;
  
    public function __construct($shopname){
        // Fetch the database info into object property	  
	    $mysidia = Registry::get("mysidia");
	    $row = $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
	    if(!is_object($row)) throw new Exception("Invalid Shopname specified");
	  
	    // loop through the anonymous object created to assign properties
        foreach($row as $key => $val){
            $this->$key = $val;		 
        }
        $this->items = $this->getitemnames();
	    $this->total = (is_array($this->items))?count($this->items):0;
    }

    public function getcategory(){
	    $mysidia = Registry::get("mysidia");
	    $stmt = $mysidia->db->select("shops", array(), "category ='{$this->category}'");
        $cate_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;     
	    return $cate_exist;
    }
  
    public function getshop(){  
	    $mysidia = Registry::get("mysidia");
	    if(empty($this->shopname)) $shop_exist = FALSE;
	    else{
	        $stmt = $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
		    $shop_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;    
	    }
	    return $shop_exist;
    }
  
    public function getitemnames(){
  	    if(!$this->items){
		    $mysidia = Registry::get("mysidia");		
		    $stmt = $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
		    $items = array();
		
		    while($item = $stmt->fetchColumn()){
		        $items[] = $item;
		    }
		    return $items;
	    }
	    else return $this->items;
    }
  
    public function gettotal(){  
	    return $this->total;
    }
  
    public function display(){
	    $mysidia = Registry::get("mysidia");
	    $document = $mysidia->frame->getDocument();			  
	    $document->addLangvar($mysidia->lang->select_item);
	  
        if($this->gettotal() == 0){
            $document->addLangvar($mysidia->lang->empty);
		    return FALSE;
        }	 
	  
	    $itemList = new TableBuilder("shop");
	    $itemList->setAlign(new Align("center", "middle"));
        $itemList->buildHeaders("Image", "Category", "Name", "Description", "Price", "Buy");	
	    $itemList->setHelper(new ShopTableHelper);
	  
	  if ($this->status == "open"){
	    foreach($this->items as $stockitem){
	  	    $item = $this->getitem($stockitem);
		    $cells = new LinkedList;		 
	        $cells->add(new TCell(new Image($item->imageurl)));
		    $cells->add(new TCell($item->category));
		    $cells->add(new TCell($item->itemname));
		    $cells->add(new TCell($item->description));
		    $cells->add(new TCell($item->price));
		    $cells->add(new TCell($itemList->getHelper()->getItemPurchaseForm($this, $item)));
		    $itemList->buildRow($cells);
			
        }	  
	    $document->add($itemList);  
    }
  
  if ($this->status == "closed"){ $document->add(new Comment("Sorry, this shop is closed.")); }
  
    public function getitem($itemname){
	  return new StockItem($itemname);
    }
  
    public function purchase(Item $item){
        $mysidia = Registry::get("mysidia");
	    if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
	    else{
            $item->quantity = $mysidia->input->post("quantity");
	        $cost = $item->getcost($this->salestax, $item->quantity);
		    $moneyleft = $mysidia->user->money - $cost;
		    if($moneyleft >= 0 and $item->quantity > 0){	
                $purchase = $item->append($item->quantity, $item->owner);
                $mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");			
                $status = TRUE;
            }			
	        else throw new InvalidActionException($mysidia->lang->money);
	    }
	    return $status;
    }
  
    public function rent($item, $period){

    }
  
    public function execute($action){
	
    }
  
  	protected function save($field, $value){
		$mysidia = Registry::get("mysidia");
		$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
	}  
}
?>
__________________
Failing at being normal since 1990.
Reply With Quote
 

Tags
shop image, shops


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
Mys v1.3.4 Item Shop Mod(s): NPC + Item Display + Tooltips Kyttias Mys v1.3.x Mods 55 06-19-2020 11:21 AM
Display on Phone? Glow Questions and Supports 1 01-05-2015 08:56 AM
Changing Shop and Item Display? Abronsyth Questions and Supports 2 12-16-2014 03:25 PM
Display AdoptSpotlight anywhere? c: pachoofoosh Questions and Supports 11 07-07-2013 02:53 PM
Display codes for all of your adoptables kisazeky Questions and Supports 9 09-03-2010 03:32 PM


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

Currently Active Users: 1755 (0 members and 1755 guests)
Threads: 4,081, Posts: 32,032, 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 - 2025, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636