File: D:/HostingSpaces/SBogers10/komma-mediadesign.nl/wwwroot/beheer/app/models/images/m_imageSession.php
<?php
/*
Handles all tasks regarding images in the session
*/
class ImageSession
{
private $_data;
private $_name;
public function __construct($name = 'images_to_store')
{
$this->_name = $name;
$this->_data[$this->_name] = array();
}
/*
GET / SET
*/
/**
*
*
* @access public
* @param int (optional)
* @return array
*/
public function get($key=NULL, $val=NULL)
{
if( ! empty($key))
{
// get data in session by 'key'
switch($key)
{
case 'shortcode':
if(is_string($val))
{
foreach($this->_data[$this->_name] as $session)
{
if( $session['shortcode'] == $val )
{
return $session;
}
}
}
break;
case 'id':
if(is_numeric($val))
{
foreach($this->_data[$this->_name] as $session)
{
if( $session['id'] == $val )
{
return $session;
}
}
}
break;
case 'key':
if(isset($this->_data[$this->_name][$val]))
{
return $this->_data[$this->_name][$val];
}
break;
}
}
else
{
if(isset($this->_data[$this->_name]))
{
return $this->_data[$this->_name];
}
}
return FALSE;
}
/**
* Sets the session
*
* @access public
* @param array, int(optional)
* @return null
*/
public function set($value,$key=NULL)
{
if( ! empty($key))
{
if(isset($this->_data[$this->_name][$key]))
{
$this->_data[$this->_name][$key] = $value;
}
}
else
{
$this->_data[$this->_name] = $value;
}
}
/**
* Adds a new set of data to the session
*
* @access public
* @param array
* @return bool
*/
public function add($data)
{
if(is_array($data))
{
$key = count($this->_data[$this->_name]);
$this->_data[$this->_name][$key] = $data;
return true;
}
return false;
}
/**
* Removes an image from the session
*
* @access public
* @param int
* @return null
*/
public function remove($key)
{
if(isset($this->_data[$this->_name][$key]))
{
unset($this->_data[$this->_name][$key]);
}
}
/**
* Counts the number of images in the session
*
* @access public
* @param int
* @return null
*/
public function count($key)
{
if(isset($this->_data[$this->_name]))
{
return count($this->_data[$this->_name]);
}
}
}