Mys 1.3.4 Shop Listing Display

Forum
Last Post
Threads / Messages

Kyttias

Super Moderator
Super Mod
Joined
Jan 26, 2014
Messages
849
Points
18
Mysidian Dollar
58,199
*This may work in versions earlier than v1.3.4, but I wouldn't know.

What we'll be doing:
  • the enter button will now be the shop image
  • closed shops will be the shop image at a lower opacity
  • the description and other details for closed shops will be hidden
  • replacing the shop type with a nicer word, 'itemshop' becomes 'Items' and 'adoptshop' becomes 'Pets'
ss_by_kyttias-d89x60t.png


Inside view/shopview.php, public function index, starting from where $shopList is defined, down to the end of the while($iterator->hasNext()) loop:

PHP:
	    $shopList = $this->getField("shopList"); 
	    $document->addLangvar($this->lang->select);
		$shopTable = new TableBuilder("shoplist");
		$shopTable->setAlign(new Align("center", "middle"));
		$shopTable->buildHeaders("Enter", "Sells", "Description", "Location");	
	    $shopTable->setHelper(new ShopTableHelper);		 
        
		$iterator = $shopList->iterator();
		while($iterator->hasNext()){
            $entry = $iterator->next();
		    $shop = $shopList->createshop($entry->getKey());
			$cells = new LinkedList;
			$cells->add(new TCell($shopTable->getHelper()->getShopStatus($shop)));
			
			if($shop->status == "open") { 
				if ($shop->shoptype == "itemshop"){ $cells->add(new TCell("Items")); }
				if ($shop->shoptype == "adoptshop"){ $cells->add(new TCell("Pets")); }
				$cells->add(new TCell($shop->description));
				$cells->add(new TCell($shop->category));
				# $cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));	
			}	
			if($shop->status == "closed") { 
				$cells->add(new TCell(""));
				$cells->add(new TCell("Not Open."));
				$cells->add(new TCell("")); 
			}	
			$shopTable->buildRow($cells);
		}

Inside classes/class_shoptablehelper.php, replace public function getShopStatus with:
PHP:
public function getShopStatus($shop){	
	    if($shop->status == "open") return new Link("shop/browse/{$shop->shopname}", new Image($shop->imageurl));
        if($shop->status == "closed") return "<img src='{$shop->imageurl}' style='opacity:0.3;'>";
		else return "Closed";		
    }

Notes: I have rearranged what order the columns are in and removed the Sales Tax column, as it is not something my site uses. Also? My category column is called Location, so rename as necessary.

To re-add the Sales Tax column, simply uncomment this line by removing the # at the start of it:
PHP:
# $cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));

And add "Sales Tax" back to the end of the headers, as follows:
PHP:
$shopTable->buildHeaders("Enter", "Sells", "Description", "Location", "Sales Tax");

You can also comment out the above line entirely if you don't want a row with header names. ^^

On an unrelated note, clever users can still find their way into 'Closed' shops if they know the shop's name or have it bookmarked or whatever. Therefore, I recommend inside of classes/class_itemshop.php and classes/class_adoptshop.php to find inside public function display the statement foreach($this->items as $stockitem){ ... } and wrapping it inside if ($this->status == "open"){ ... } (being sure to close it afterward), and then adding in if ($this->status == "closed"){ $document->add(new Comment("Sorry, this shop is closed.")); } so that your shop items will be hidden from view if the shop is closed but the page is still somehow accessed.
 
Last edited:
I can't seem to fix it so that people can't enter the shop if its closed. The extra parts at the end of your post fail.

If I add the if > open thing then, no matter what the status, the items are NOT shown. Just the table itself.

If I add the closed status part, the entire thing breaks.
 
Let me see your file? Something may not be getting closed correctly.
 
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'");
	}  
}
?>
 
Ok, since this was exactly similar to a problem you had on instructions in another thread, let me explain clearly what you didn't do, and therefore why it's not working.

This is the foreach loop:
PHP:
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);			
}

You were supposed to wrap it inside the if statement:
PHP:
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);			
	}
}

This is what you have in what you sent me:
PHP:
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);			
	}

The foreach closes still, but the if statement does not. There is only one curly brace at the end. You must wrap something completely. It's always best to line up code so that the end curly brace is directly below the thing that opened it - so you can visually make sure that it's indeed closed.

Then, the next thing you did was add the second if statement, checking if the shop is closed, outside of the display function, rather than inside of it, as instructed.

This is what you have:
PHP:
    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.")); }

This is what you SHOULD have, if you had followed the instructions:
PHP:
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);
		}
    }
    if ($this->status == "closed"){ $document->add(new Comment("Sorry, this shop is closed.")); }	  
    $document->add($itemList);  
}

And, finally, here is the entire document, just in case:
PHP:
<?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);
			}
		}
		if($this->status == "closed"){
			$document->add(new Comment("Sorry, this shop is closed."));
		}

		$document->add($itemList);
	}

	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'");
	}
}
?>

It's ready to just copy and paste in, but please try to understand where things went wrong.

You might want to take a basic coding course at code Codecademy if you haven't yet - it's totally free and only takes a couple hours.
 
Last edited:
Oh my god! What an idiot! Of course! "double wrapping"
How could I have missed such a simple mistake?

Sorry about that. Wasting your time and all. Dx

It's working now of course.

Is there also a way to disable the dropdown list? So all shops are in the list but each is catergorised a little apart for ease of view?
 
Last edited:
Probably...? I don't have any adopt shops, so it'd be hard for me to test. :desudesudesu:

I might get to something like that eventually... but not for a while.
 
I know you're busy, but, when you have the chance...I'm not sure what I'm messing up and I'm by no means an experienced coder...but I'm getting this error:
Fatal error: Uncaught exception 'Resource\Exception\NosuchElementException' in /hermes/bosoraweb162/b1009/ipg.ferrepetscom/classes/resource/collection/linkedhashmapiterator.php:83 Stack trace: #0 /hermes/bosoraweb162/b1009/ipg.ferrepetscom/classes/resource/collection/entrylinkediterator.php(26): Resource\Collection\LinkedHashMapIterator->nextEntry() #1 /hermes/bosoraweb162/b1009/ipg.ferrepetscom/view/shopview.php(47): Resource\Collection\EntryLinkedIterator->next() #2 /hermes/bosoraweb162/b1009/ipg.ferrepetscom/classes/class_frontcontroller.php(100): ShopView->index() #3 /hermes/bosoraweb162/b1009/ipg.ferrepetscom/index.php(74): FrontController->render() #4 /hermes/bosoraweb162/b1009/ipg.ferrepetscom/index.php(78): IndexController::main() #5 {main} thrown in /hermes/bosoraweb162/b1009/ipg.ferrepetscom/classes/resource/collection/linkedhashmapiterator.php on line 83

Here's my shopview:
PHP:
<?php

use Resource\Collection\LinkedList;

class ShopView extends View{
	
	public function index(){
		$document = $this->document;
	    $document->setTitle($this->lang->access);
		
		$typeForm = new Form("shoptypes", "shop", "post");
		$typeSelection = new DropdownList("shoptype");
		$typeSelection->add(new Option("Itemshop", "itemshop"));
		$typeSelection->add(new Option("Adoptshop", "adoptshop"));
		$typeForm->add($typeSelection);
		$typeForm->add(new Button("Go", "submit", "submit"));
		$document->add($typeForm);
		
        $shopList = $this->getField("shopList"); 
        $document->addLangvar($this->lang->select);
        $shopTable = new TableBuilder("shoplist");
        $shopTable->setAlign(new Align("center", "middle"));
        $shopTable->buildHeaders("Enter", "Sells", "Description", "Location");    
        $shopTable->setHelper(new ShopTableHelper);         
        
        $iterator = $shopList->iterator();
        while($iterator->hasNext()){
            $entry = $iterator->next();
            $shop = $shopList->createshop($entry->getKey());
            $cells = new LinkedList;
            $cells->add(new TCell($shopTable->getHelper()->getShopStatus($shop)));
            
            if($shop->status == "open") { 
                if ($shop->shoptype == "itemshop"){ $cells->add(new TCell("Items")); }
                if ($shop->shoptype == "adoptshop"){ $cells->add(new TCell("Pets")); }
                $cells->add(new TCell($shop->description));
                $cells->add(new TCell($shop->category));
                # $cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));    
            }    
            if($shop->status == "closed") { 
                $cells->add(new TCell(""));
                $cells->add(new TCell("Not Open."));
                $cells->add(new TCell("")); 
            }    
            $shopTable->buildRow($cells);
        } {
            $entry = $iterator->next();
		    $shop = $shopList->createshop($entry->getKey());
			$cells = new LinkedList;
			
			$cells->add(new TCell($shopList->getshopimage($shop->imageurl)));
			$cells->add(new TCell($shop->category));
			$cells->add(new TCell($shop->shoptype));
			$cells->add(new TCell($shop->shopname));
			$cells->add(new TCell($shop->description));
			$cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));
			$cells->add(new TCell($shopTable->getHelper()->getShopStatus($shop)));
			$shopTable->buildRow($cells);
		}
        $document->add($shopTable);  
	}
	
	public function browse(){
		$document = $this->document;			        
		$document->setTitle($this->lang->welcome);
        $shop = $this->getField("shop");
        $shop->display();
	}
	
	public function purchase(){
        $mysidia = Registry::get("mysidia");
		$cost = $this->getField("cost");
		$document = $this->document;		
		
	    if($mysidia->input->post("shoptype") == "itemshop"){
		    $document->setTitle($this->lang->global_transaction_complete);
	        $document->addLangvar("{$this->lang->purchase_item}{$cost->getValue()} {$mysidia->settings->cost}");
		}
		elseif($mysidia->input->post("shoptype") == "adoptshop"){
   			$document->setTitle($this->lang->global_transaction_complete);
	        $document->addLangvar("{$this->lang->purchase_adopt}{$cost->getValue()} {$mysidia->settings->cost}");	  
		}
		else return;
	}
}
?>

And here's my shoptablehelper:
PHP:
<?php

/**
 * The ShopTableHelper Class, extends from the TableHelper class.
 * It is a specific helper for tables that involves operations on shops.
 * @category Resource
 * @package Helper
 * @author Hall of Famer 
 * @copyright Mysidia Adoptables Script
 * @link http://www.mysidiaadoptables.com
 * @since 1.3.3
 * @todo Not much at this point.
 *
 */

class ShopTableHelper extends TableHelper{

    /**
     * Constructor of ShopTableHelper Class, it simply serves as a wrap-up.
     * @access public
     * @return Void
     */
	public function __construct(){
	    parent::__construct();         
	}

	/**
     * The getSalestax method, formats and retrieves the salestax of a shop.
     * @param Int  $salestax
     * @access public
     * @return String
     */
    public function getSalestax($salestax){
		return "{$salestax}%";				
    }
	
	/**
     * The getShopstatus method, returns the shop status with an enter link or a closed message.
     * @param Shop  $shop
     * @access public
     * @return Link|String
     */
	public function getShopStatus($shop){    
        if($shop->status == "open") return new Link("shop/browse/{$shop->shopname}", new Image($shop->imageurl));
        if($shop->status == "closed") return "<img src='{$shop->imageurl}' style='opacity:0.3;'>";
        else return "Closed";        
    } 
	
	/**
     * The getItemPurchaseForm method, constructs a buy form for an itemshop table.
	 * @param Itemshop  $shop
     * @param Item  $item 
     * @access public
     * @return Form
     */
    public function getItemPurchaseForm(Itemshop $shop, Item $item){	
        $mysidia = Registry::get("mysidia");
        $buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
        $buyForm->setLineBreak(FALSE);
        $buyForm->buildComment("<br>")
                ->buildPasswordField("hidden", "action", "purchase")
		        ->buildPasswordField("hidden", "itemname", $item->itemname)
				->buildPasswordField("hidden", "shopname", $shop->shopname)
                ->buildPasswordField("hidden", "shoptype", "itemshop")
				->buildPasswordField("hidden", "salestax", $shop->salestax);
				
        $quantity = new TextField("quantity");
        $quantity->setSize(3);
        $quantity->setMaxLength(3);
        $quantity->setLineBreak(TRUE);

        $buy = new Button("Buy", "buy", "buy");
        $buy->setLineBreak(FALSE);

		$buyForm->add($quantity);
		$buyForm->add($buy);
        return $buyForm;				
    }
	
	/**
     * The getAdoptPurchaseForm method, constructs a purchase form for an adoptshop table.
	 * @param Adoptshop  $shop
     * @param Adoptable  $adopt 
     * @access public
     * @return Form
     */
    public function getAdoptPurchaseForm(Adoptshop $shop, $adopt){	
        $mysidia = Registry::get("mysidia");
        $buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
        $buyForm->setLineBreak(FALSE);
        $buyForm->buildComment("<br>")
                ->buildPasswordField("hidden", "action", "purchase")
		        ->buildPasswordField("hidden", "adopttype", $adopt->type)
				->buildPasswordField("hidden", "shopname", $shop->shopname)
                ->buildPasswordField("hidden", "shoptype", "adoptshop")
				->buildPasswordField("hidden", "salestax", $shop->salestax);
				
        $buy = new Button("Buy", "buy", "buy");
        $buy->setLineBreak(FALSE);
		$buyForm->add($buy);
        return $buyForm;				
    }
	
	/**
     * Magic method __toString for ShopTableHelper class, it reveals that the object is a shop table helper.
     * @access public
     * @return String
     */
    public function __toString(){
	    return new String("This is an instance of Mysidia ShopTableHelper class.");
	}    
} 
?>

Are you able to spot my mistake?
 
I can tell you that the index function is wrong in shopview.php.

This is the original index function:
PHP:
	public function index(){
		$document = $this->document;
	    $document->setTitle($this->lang->access);
		
		$typeForm = new Form("shoptypes", "shop", "post");
		$typeSelection = new DropdownList("shoptype");
		$typeSelection->add(new Option("Itemshop", "itemshop"));
		$typeSelection->add(new Option("Adoptshop", "adoptshop"));
		$typeForm->add($typeSelection);
		$typeForm->add(new Button("Go", "submit", "submit"));
		$document->add($typeForm);
		
		$shopList = $this->getField("shopList"); 
	    $document->addLangvar($this->lang->select);
		$shopTable = new TableBuilder("shoplist");
		$shopTable->setAlign(new Align("center", "middle"));
		$shopTable->buildHeaders("Image", "Category", "Type", "Name", "Description", "Sales Tax", "Enter");	
	    $shopTable->setHelper(new ShopTableHelper);		 
        
		$iterator = $shopList->iterator();
		while($iterator->hasNext()){
            $entry = $iterator->next();
		    $shop = $shopList->createshop($entry->getKey());
			$cells = new LinkedList;
			
			$cells->add(new TCell($shopList->getshopimage($shop->imageurl)));
			$cells->add(new TCell($shop->category));
			$cells->add(new TCell($shop->shoptype));
			$cells->add(new TCell($shop->shopname));
			$cells->add(new TCell($shop->description));
			$cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));
			$cells->add(new TCell($shopTable->getHelper()->getShopStatus($shop)));
			$shopTable->buildRow($cells);
		}
        $document->add($shopTable);  
	}

This is what it needs to be:
PHP:
	public function index(){
		$document = $this->document;
	    $document->setTitle($this->lang->access);
		
		$typeForm = new Form("shoptypes", "shop", "post");
		$typeSelection = new DropdownList("shoptype");
		$typeSelection->add(new Option("Itemshop", "itemshop"));
		$typeSelection->add(new Option("Adoptshop", "adoptshop"));
		$typeForm->add($typeSelection);
		$typeForm->add(new Button("Go", "submit", "submit"));
		$document->add($typeForm);
		
		$shopList = $this->getField("shopList"); 
        $document->addLangvar($this->lang->select);
        $shopTable = new TableBuilder("shoplist");
        $shopTable->setAlign(new Align("center", "middle"));
        $shopTable->buildHeaders("Enter", "Sells", "Description", "Location");    
        $shopTable->setHelper(new ShopTableHelper);         
        
        $iterator = $shopList->iterator();
        while($iterator->hasNext()){
            $entry = $iterator->next();
            $shop = $shopList->createshop($entry->getKey());
            $cells = new LinkedList;
            $cells->add(new TCell($shopTable->getHelper()->getShopStatus($shop)));
            
            if($shop->status == "open") { 
                if ($shop->shoptype == "itemshop"){ $cells->add(new TCell("Items")); }
                if ($shop->shoptype == "adoptshop"){ $cells->add(new TCell("Pets")); }
                $cells->add(new TCell($shop->description));
                $cells->add(new TCell($shop->category));
                # $cells->add(new TCell($shopTable->getHelper()->getSalestax($shop->salestax)));    
            }    
            if($shop->status == "closed") { 
                $cells->add(new TCell(""));
                $cells->add(new TCell("Not Open."));
                $cells->add(new TCell("")); 
            }    
            $shopTable->buildRow($cells);
        }  
        $document->add($shopTable);  
	}

Or, basically, I replaced lines 19 through 40 in the original document with the ones from my first post. From where $shopList is defined to the end of the while loop, leaving everything before $shopList is defined intact, and leaving everything after the end of the while loop intact.
 
Awesome, thank you! I was pretty tired when I was putting it together, so it's no wonder I messed up XD

It's working wondrously now, thank you!
 
Thank you so much for taking the time to offer this. It works perfectly!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top