diff --git a/application/classes/controller/library.php b/application/classes/controller/library.php index 8d81f2e..3090fe3 100644 --- a/application/classes/controller/library.php +++ b/application/classes/controller/library.php @@ -61,12 +61,11 @@ class Controller_LIBRARY extends Controller_TemplateDefault { Request::current()->redirect('library'); } - $slots = DB::query(Database::SHOW,'SHOW SLOTS '.$lo)->execute(); Block::add(array( 'title'=>sprintf(_('Library Information for %s'),$lo->LIBRARY_NAME), 'body'=>View::factory('library/detail') ->set('lo',$lo) - ->set('slots',$slots) + ->set('slots',$lo->slots()) )); } } diff --git a/application/classes/database/tsm/show.php b/application/classes/database/tsm/show.php index 9337cbd..3e6bd80 100644 --- a/application/classes/database/tsm/show.php +++ b/application/classes/database/tsm/show.php @@ -34,7 +34,7 @@ class Database_TSM_Show extends Database_Result { $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); + $slot['element'] = (int)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)) @@ -72,7 +72,6 @@ class Database_TSM_Show extends Database_Result { list($k,$v) = explode(':',$line,2); $this->data[$k] = $v; - } else { } } } diff --git a/application/classes/model/devclasses.php b/application/classes/model/devclasses.php index 3164c32..3f5bff1 100644 --- a/application/classes/model/devclasses.php +++ b/application/classes/model/devclasses.php @@ -3,12 +3,12 @@ /** * * @package PTA - * @subpackage Volume + * @subpackage Device Classes * @category Models * @author Deon George * @copyright (c) 2010 phpTSMadmin Development Team * @license http://phptsmadmin.sf.net/license.html - * @node This is model is using the plural name, as storage pools have an attribute with the singular name + * @note This is model is using the plural name, as storage pools have an attribute with the singular name */ class Model_DEVCLASSES extends ORMTSM { protected $_table_name = 'DEVCLASSES'; @@ -17,5 +17,9 @@ class Model_DEVCLASSES extends ORMTSM { 'DEVTYPE'=>'ASC', 'DEVCLASS_NAME'=>'ASC', ); + + protected $_has_many = array( + 'STGPOOL'=>array('foreign_key'=>'DEVCLASS','far_key'=>'DEVCLASS_NAME'), + ); } ?> diff --git a/application/classes/model/library.php b/application/classes/model/library.php index 1e33815..c679fc7 100644 --- a/application/classes/model/library.php +++ b/application/classes/model/library.php @@ -16,10 +16,119 @@ class Model_LIBRARY extends ORMTSM { 'LIBRARY_NAME'=>'ASC', ); + // Store our show slots data + private $slots; + private $storagepools = array(); + protected $_has_one = array( ); protected $_has_many = array( 'DRIVE'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'), + 'PATH'=>array('foreign_key'=>'DESTINATION_NAME','far_key'=>'LIBRARY_NAME'), + 'DEVCLASSES'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'), ); + + public function slots() { + return $this->slots ? $this->slots : $this->slots = DB::query(Database::SHOW,'SHOW SLOTS '.$this)->execute(); + } + + // Return a list of scratch volumes + public function scratch() { + $return = array(); + + foreach ($this->slots() as $slot) + if ($slot->status == 'Allocated' AND $slot->LIBVOLUME->usage() == 'scratch') + array_push($return,$slot->LIBVOLUME->VOLUME); + + return $return; + } + + // Return a list of volumes that are readonly + public function readonly() { + $return = array(); + + foreach ($this->slots() as $slot) + if ($slot->LIBVOLUME->VOLUME->ACCESS == 'READONLY') + array_push($return,$slot->LIBVOLUME->VOLUME); + + return $return; + } + + // Return the number of slots that are empty. + public function numemptyslot() { + return $this->slots->Slots-$this->slots->Changers-count($this->slots); + } + + // Return the slots that are used, but not checked in. + public function notcheckedin() { + $return = array(); + + foreach ($this->slots() as $slot) + if ($slot->status == 'Full') + array_push($return,$slot); + + return $return; + } + + // Return the device classes that use this library. + public function devclasses() { + return $this->DEVCLASSES->where('LIBRARY_NAME','=',$this)->find_all(); + } + + // Return a list of storage pools that potentially use this library. + public function storagepools() { + if (! $this->storagepools) + foreach ($this->devclasses() as $dco) + foreach ($dco->STGPOOL->find_all() as $spo) + array_push($this->storagepools,$spo); + + return $this->storagepools; + } + + public function storagepoolstype($type) { + $result = array(); + + foreach ($this->storagepools() as $spo) + if ($spo->POOLTYPE == $type) + array_push($result,$spo); + + return $result; + } + + // Return a list of volumes + // $ptype is pool type (PRIMARY,ACTIVE,COPY) + // @param $inout IN|OUT of the library + // @param $status volume status FULL|FILLING|PENDING|EMPTY + // @note This is an intensive method that needs caching. + public function volstype($type,$inout,$status) { + static $CACHE = array(); + $ainout = array('in','out'); + $astatus = array('FULL','FILLING','PENDING','EMPTY'); + + if (! isset($CACHE[__METHOD__][$type])) + foreach ($this->storagepoolstype($type) as $spo) + foreach ($ainout as $cinout) + foreach ($astatus as $cstatus) { + if (! isset($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus])) + $CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] = array(); + + $CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] = + array_merge($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus],$spo->libvolstype($cinout,$cstatus)); + } + + return isset($CACHE[__METHOD__][$type][$inout][$status]) ? $CACHE[__METHOD__][$type][$inout][$status] : array(); + } + + public function volsnotinlib() { + $result = array(); + + foreach ($this->storagepools() as $spo) + foreach ($spo->VOLUME->find_all() as $vo) + if ($vo->MEDIA->STATUS != 'MOUNTABLEINLIB') + array_push($result,$vo); + + Sort::masort($result,'VOLUME_NAME'); + return $result; + } } ?> diff --git a/application/classes/model/libvolume.php b/application/classes/model/libvolume.php index 012331a..624948e 100644 --- a/application/classes/model/libvolume.php +++ b/application/classes/model/libvolume.php @@ -11,7 +11,7 @@ */ class Model_LIBVOLUME extends ORMTSM { protected $_table_name = 'LIBVOLUMES'; - protected $_primary_key = 'VOLUME_NAME'; + protected $_primary_key = 'HOME_ELEMENT'; protected $_sorting = array( 'VOLUME_NAME'=>'ASC', ); @@ -32,16 +32,19 @@ class Model_LIBVOLUME extends ORMTSM { case 'data': return strtolower($this->LAST_USE); - default: return 'unknown'; + default: return ($this->VOLUME->STATUS == 'EMPTY') ? 'empty' : 'unknown'; } + default: return 'notcheckedin'; } } public function volusage() { switch ($this->usage()) { - case 'scratch': return _('Scratch'); + case 'data': + case 'empty': return $this->VOLUME->STGPOOL_NAME; case 'dbbackup': return $this->VOLHISTORY->lastuse()->TYPE; - case 'data': return $this->VOLUME->STGPOOL_NAME; + case 'notcheckedin': return _('Not Checked In'); + case 'scratch': return _('Scratch'); default: return _('Unknown'); } @@ -51,27 +54,26 @@ class Model_LIBVOLUME extends ORMTSM { switch ($this->usage()) { case 'data': return sprintf('%s/%s',$this->VOLUME->display('STATUS'),$this->VOLUME->display('ACCESS')); case 'dbbackup': return $this->VOLHISTORY->lastuse()->backupid(); + case 'empty': return _('Empty'); default: return ''; } } public function access() { - switch ($this->usage()) { - case 'data': - case 'dbbackup': - return sprintf('%s/%s',$this->display('STATUS'),$this->display('OWNER')); - - default: return ''; - } + if ($this->usage() == 'scratch') + return ''; + elseif ($this->STATUS) + return sprintf('%s/%s',$this->display('STATUS'),$this->display('OWNER')); + else + return ''; } public function lastwrite() { switch ($this->usage()) { case 'data': - return $this->VOLUME->display('LAST_WRITE_DATE'); - case 'dbbackup': - return $this->VOLHISTORY->lastuse()->display('DATE_TIME'); + case 'empty': return $this->VOLUME->display('LAST_WRITE_DATE'); + case 'dbbackup': return $this->VOLHISTORY->lastuse()->display('DATE_TIME'); default: return ''; } diff --git a/application/classes/model/media.php b/application/classes/model/media.php new file mode 100644 index 0000000..5a06346 --- /dev/null +++ b/application/classes/model/media.php @@ -0,0 +1,24 @@ +'ASC', + ); + + protected $_has_one = array( + ); + protected $_has_many = array( + ); +} +?> diff --git a/application/classes/model/stgpool.php b/application/classes/model/stgpool.php index e1aed06..c08bb91 100644 --- a/application/classes/model/stgpool.php +++ b/application/classes/model/stgpool.php @@ -22,5 +22,23 @@ class Model_STGPOOL extends ORMTSM { protected $_has_many = array( 'VOLUME'=>array('foreign_key'=>'STGPOOL_NAME','far_key'=>'STGPOOL_NAME'), ); + + // Return a list of volumes + // @param $inout IN|OUT of the library + // @param $status volume status FULL|FILLING|PENDING|EMPTY + public function libvolstype($inout,$status) { + $inout = strtolower($inout); + $status = strtoupper($status); + $result = array(); + + if (! isset($result[$inout])) + foreach ($this->VOLUME->find_all() as $vo) { + $state = ($vo->MEDIA->STATE == 'MOUNTABLEINLIB') ? 'in' : 'out'; + + $result[$state][$vo->STATUS][] = $vo; + } + + return isset($result[$inout][$status]) ? $result[$inout][$status] : array(); + } } ?> diff --git a/application/classes/model/volume.php b/application/classes/model/volume.php index 4c0f3df..b988cbb 100644 --- a/application/classes/model/volume.php +++ b/application/classes/model/volume.php @@ -17,6 +17,9 @@ class Model_VOLUME extends ORMTSM { 'STGPOOL_NAME'=>'ASC', ); + protected $_has_one = array( + 'MEDIA'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'), + ); protected $_has_many = array( 'VOLUMEUSAGE'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'), ); diff --git a/application/classes/orm.php b/application/classes/orm.php index 476eef6..a71c8ad 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -12,6 +12,7 @@ */ class ORM extends Kohana_ORM { protected $_table_names_plural = false; + protected $_model_names_plural = false; private $_object_formated = array(); private $_formated = FALSE; // Our filters used to display values in a friendly format diff --git a/application/classes/slot.php b/application/classes/slot.php index edb2758..278c293 100644 --- a/application/classes/slot.php +++ b/application/classes/slot.php @@ -14,7 +14,7 @@ class Slot { private $data = array(); private $objects = array( 'VOLUME'=>'barcodelabel', - 'LIBVOLUME'=>'barcodelabel', + 'LIBVOLUME'=>'element', ); public function __construct(array $slot) { @@ -36,7 +36,9 @@ class Slot { } public function barcodelabel() { - if ($this->status == 'Allocated' AND $this->barcode == 'not present') + if ($this->LIBVOLUME->VOLUME_NAME) + return $this->LIBVOLUME->VOLUME_NAME; + elseif ($this->status == 'Allocated' AND $this->barcode == 'not present') return _('No Label'); elseif ($this->status == 'Unallocated') return _('Slot Empty'); diff --git a/application/views/library/detail.php b/application/views/library/detail.php index cdee94b..60da2ec 100644 --- a/application/views/library/detail.php +++ b/application/views/library/detail.php @@ -3,7 +3,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -40,8 +40,98 @@ + + + + +
Information for this LibraryInformation for this Library
 
Slots/ChangersSlots,$slots->Changers); ?>Slots-$slots->Changers,$slots->Changers); ?>
SharedAuto Label display('AUTOLABEL'); ?>
Paths + + PATH->find_all() as $po) { ?> + + + + + + +
display('SOURCE_NAME'); ?>display('SOURCE_TYPE'); ?>display('DESTINATION_TYPE'); ?>display('DEVICE'); ?>
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + storagepoolstype($type) as $spo) { ?> + + + + + + + + + + + + + + +
Library Volume Summary
 
Empty Slotsnumemptyslot(); ?>
Not Checked Innotcheckedin()); ?>
Scratchscratch()); ?>
Read Onlyreadonly()); ?>
 
Storage Pool Volumes for this Library
 
Storage TypeIN: FULLIN: FILLINGIN: PENDINGIN: EMPTYOUT: FULLOUT: FILLINGOUT: PENDINGOUT: EMPTY
volstype($type,'in','FULL')); ?>volstype($type,'in','FILLING')); ?>volstype($type,'in','PENDING')); ?>volstype($type,'in','EMPTY')); ?>volstype($type,'out','FULL')); ?>volstype($type,'out','FILLING')); ?>volstype($type,'out','PENDING')); ?>volstype($type,'out','EMPTY')); ?>
 libvolstype('in','FULL')); ?>libvolstype('in','FILLING')); ?>libvolstype('in','PENDING')); ?>libvolstype('in','EMPTY')); ?>libvolstype('out','FULL')); ?>libvolstype('out','FILLING')); ?>libvolstype('out','PENDING')); ?>libvolstype('out','EMPTY')); ?>
+ + + @@ -88,27 +178,61 @@ - - + + - - + + + + +
 
Slot Barcode Usage Status/AccessLibrary Access Utilisation Reclaim Last Read Last WriteSlotLibrary Access
barcodelabel()); ?> LIBVOLUME->volusage(); ?> LIBVOLUME->status()); ?>LIBVOLUME->access()); ?> LIBVOLUME->VOLUME->display('PCT_UTILIZED'); ?> LIBVOLUME->VOLUME->display('PCT_RECLAIM'); ?> LIBVOLUME->VOLUME->display('LAST_READ_DATE'); ?> LIBVOLUME->lastwrite()); ?>LIBVOLUME->access()); ?>
+ + + + + + + + + + + + + + + + + + + + + + volsnotinlib() as $vo) { ?> + + + + + + + + +
Volumes out of this Library
 
VolumeUsageStatus/AccessUtilisationReclaimLast ReadLast WriteLocation
STGPOOL_NAME; ?>display('STATUS'),$vo->display('ACCESS')); ?>display('PCT_UTILIZED'); ?>display('PCT_RECLAIM'); ?>display('LAST_READ_DATE'); ?>display('LAST_WRITE_DATE'); ?>display('LOCATION'); ?>