Added Library Info

This commit is contained in:
Deon George
2011-06-24 11:27:21 +10:00
parent 529d70d2bb
commit 279eacd4ab
17 changed files with 520 additions and 65 deletions

View File

@@ -0,0 +1,63 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database show result. See [Results](/database/results) for usage and examples.
*
* @package PTA
* @subpackage TSM
* @category Query/Show
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
abstract class Database_Result extends Kohana_Database_Result {
protected $_internal_row = 0;
protected $_rows;
// Required Abstract Classes
public function __destruct() {}
public function seek($offset) {
if ($this->offsetExists($offset)) {
// Set the current row to the offset
$this->_current_row = $this->_internal_row = $offset;
return TRUE;
} else {
return FALSE;
}
}
public function current() {
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
return FALSE;
// Return an stdClass
if ($this->_as_object === TRUE) {
return $this;
} elseif (is_string($this->_as_object)) {
// Return an object of given class name
$o = new $this->_as_object;
return $o->load_object($this->_rows[$this->_current_row]);
// Return an array of the row
} else {
return $this->_rows[$this->_current_row];
}
}
/**
* Get a row value from the query
*
* TSM returns all columns in upper case
*/
public function get($name, $default = NULL) {
$name = strtoupper($name);
return parent::get($name,$default);
}
}
?>

View File

@@ -187,6 +187,8 @@ class Database_TSM extends Database {
return new Database_TSM_Result($result, $sql, $as_object, $params);
elseif ($type === Database::INSERT)
throw new Kohana_Exception('Database INSERTS are not supported');
elseif ($type === Database::SHOW)
return new Database_TSM_Show($result, $sql, $as_object, $params);
}
public function list_tables($like = NULL) {

View File

@@ -11,12 +11,7 @@
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_Result extends Database_Result {
protected $_internal_row = 0;
private $_rows;
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
{
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
parent::__construct($result, $sql, $as_object, $params);
$start = FALSE;
@@ -37,60 +32,5 @@ class Database_TSM_Result extends Database_Result {
$this->_total_rows = $this->_internal_row;
$this->_internal_row = 0;
}
public function __destruct()
{
return;
}
public function seek($offset)
{
if ($this->offsetExists($offset))
{
// Set the current row to the offset
$this->_current_row = $this->_internal_row = $offset;
return TRUE;
}
else
{
return FALSE;
}
}
public function current()
{
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
return FALSE;
if ($this->_as_object === TRUE)
{
// Return an stdClass
return $this;
}
elseif (is_string($this->_as_object))
{
// Return an object of given class name
$o = new $this->_as_object;
return $o->load_object($this->_rows[$this->_current_row]);
}
else
{
// Return an array of the row
return $this->_rows[$this->_current_row];
}
}
/**
* Get a row value from the query
*
* TSM returns all columns in upper case
*/
public function get($name, $default = NULL) {
$name = strtoupper($name);
return parent::get($name,$default);
}
} // End Database_TSM_Result
}
?>

View File

@@ -0,0 +1,61 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database show result. See [Results](/database/results) for usage and examples.
*
* @package PTA
* @subpackage TSM
* @category Query/Show
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_Show extends Database_Result {
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
parent::__construct($result, $sql, $as_object, $params);
$sql = strtolower($sql);
$start = FALSE;
foreach ($result as $line) {
if (! trim($line))
continue;
if (preg_match('/^show slots /',$sql))
if (preg_match('/^Slot /',$line)) {
if ($start)
$this->_internal_row++;
$slot = array();
foreach ((preg_split('/,\s*/',$line,-1)) as $slotkey => $val)
if (preg_match('/^element number\s+/',$val))
$slot['element'] = preg_replace('/^element number\s+/','',$val);
elseif (preg_match('/^Slot\s+/',$val))
$slot['slot'] = preg_replace('/^Slot\s+/','',$val);
elseif (preg_match('/^status\s+/',$val))
$slot['status'] = preg_replace('/^status\s+/','',$val);
elseif (preg_match('/^barcode value </',$val))
$slot['barcodelabel'] = preg_replace('/^barcode value <(.*)>/',"$1",$val);
elseif (preg_match('/^barcode\s+/',$val))
$slot['barcode'] = preg_replace('/^barcode /','',$val);
$slot['library'] = preg_replace('/^show slots /','',$sql);
$this->_rows[$this->_internal_row] = new Slot($slot);
$start = TRUE;
} elseif (preg_match('/busy.$/',$line)) {
SystemMessage::add(array(
'title'=>_('Library is Busy'),
'type'=>'info',
'body'=>_('The library appears busy at the moment.'),
));
return;
}
}
$this->_total_rows = $this->_internal_row;
$this->_internal_row = 0;
}
}
?>