Loading basket.php +20 −7 Original line number Diff line number Diff line Loading @@ -72,23 +72,36 @@ class Basket { } /** * Return item that matches key/value pair * @return object|FALSE * Return items that match key/value pair * @return array|FALSE * @param $key string * @param $val mixed **/ function find($key,$val) { if (isset($_SESSION[$this->key])) if (isset($_SESSION[$this->key])) { $out=array(); foreach ($_SESSION[$this->key] as $id=>$item) if (array_key_exists($key,$item) && $item[$key]==$val) { $obj=clone($this); $obj->id=$id; $obj->item=$item; return $obj; $out[]=$obj; } return $out; } return FALSE; } /** * Return first item that matches key/value pair * @return object|FALSE * @param $key string * @param $val mixed **/ function findone($key,$val) { return ($data=$this->find($key,$val))?$data[0]:FALSE; } /** * Map current item to matching key/value pair * @return array Loading @@ -97,8 +110,8 @@ class Basket { **/ function load($key,$val) { if ($found=$this->find($key,$val)) { $this->id=$found->id; return $this->item=$found->item; $this->id=$found[0]->id; return $this->item=$found[0]->item; } $this->reset(); return array(); Loading Loading @@ -140,7 +153,7 @@ class Basket { **/ function erase($key,$val) { $found=$this->find($key,$val); if ($found && $id=$found->id) { if ($found && $id=$found[0]->id) { unset($_SESSION[$this->key][$id]); session_commit(); if ($id==$this->id) Loading Loading
basket.php +20 −7 Original line number Diff line number Diff line Loading @@ -72,23 +72,36 @@ class Basket { } /** * Return item that matches key/value pair * @return object|FALSE * Return items that match key/value pair * @return array|FALSE * @param $key string * @param $val mixed **/ function find($key,$val) { if (isset($_SESSION[$this->key])) if (isset($_SESSION[$this->key])) { $out=array(); foreach ($_SESSION[$this->key] as $id=>$item) if (array_key_exists($key,$item) && $item[$key]==$val) { $obj=clone($this); $obj->id=$id; $obj->item=$item; return $obj; $out[]=$obj; } return $out; } return FALSE; } /** * Return first item that matches key/value pair * @return object|FALSE * @param $key string * @param $val mixed **/ function findone($key,$val) { return ($data=$this->find($key,$val))?$data[0]:FALSE; } /** * Map current item to matching key/value pair * @return array Loading @@ -97,8 +110,8 @@ class Basket { **/ function load($key,$val) { if ($found=$this->find($key,$val)) { $this->id=$found->id; return $this->item=$found->item; $this->id=$found[0]->id; return $this->item=$found[0]->item; } $this->reset(); return array(); Loading Loading @@ -140,7 +153,7 @@ class Basket { **/ function erase($key,$val) { $found=$this->find($key,$val); if ($found && $id=$found->id) { if ($found && $id=$found[0]->id) { unset($_SESSION[$this->key][$id]); session_commit(); if ($id==$this->id) Loading