This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/application/classes/model/library.php

135 lines
3.8 KiB
PHP
Raw Normal View History

2011-06-24 01:27:21 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Library
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_LIBRARY extends ORMTSM {
protected $_table_name = 'LIBRARIES';
protected $_primary_key = 'LIBRARY_NAME';
protected $_sorting = array(
'LIBRARY_NAME'=>'ASC',
);
2011-06-26 12:20:12 +00:00
// Store our show slots data
private $slots;
private $storagepools = array();
2011-06-24 01:27:21 +00:00
protected $_has_one = array(
);
protected $_has_many = array(
2011-06-24 23:46:26 +00:00
'DRIVE'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
2011-06-26 12:20:12 +00:00
'PATH'=>array('foreign_key'=>'DESTINATION_NAME','far_key'=>'LIBRARY_NAME'),
'DEVCLASSES'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
2011-06-24 01:27:21 +00:00
);
2011-06-26 12:20:12 +00:00
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;
}
2011-06-24 01:27:21 +00:00
}
?>