Example #1
0
 public function select($path)
 {
     // Checks if...
     if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 2 && $path['parameter'][0] == 'plan') {
         $plan = DataCenterDB::getPlan($path['parameter'][1]);
         $space = $plan->getSpace();
         // Gets rack links which are linked to this plan
         $rackLinks = DataCenterDB::getAssetLinks(array_merge_recursive(DataCenterDB::buildCondition('link', 'asset', 'plan', $plan->getId()), DataCenterDB::buildCondition('link', 'asset', 'asset_type', 'rack')));
         $existsTable = array();
         foreach ($rackLinks as $rackLink) {
             $existsTable[$rackLink->get('asset_id')] = true;
         }
         // Gets rack from database in two varieties, local and remote
         $racks = array('local' => DataCenterDB::getAssets('rack', array_merge_recursive(DataCenterDB::buildCondition('asset', 'rack', 'location', $space->get('location')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', 'rack', 'location', array('name' => 'location_name', 'region' => 'location_region')))), 'remote' => DataCenterDB::getAssets('rack', array_merge_recursive(DataCenterDB::buildCondition('asset', 'rack', 'location', $space->get('location'), '!='), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', 'rack', 'location', array('name' => 'location_name', 'region' => 'location_region')))));
         $tables = array();
         foreach ($racks as $groupName => $rackGroup) {
             foreach ($rackGroup as $key => $rack) {
                 if ($rack->get('tense') == 'past' || isset($existsTable[$rack->getId()])) {
                     unset($rackGroup[$key]);
                 } else {
                     $rackModel = $rack->getModel();
                     $rack->set($rackModel->get(array('name', 'manufacturer')));
                 }
             }
             if (count($rackGroup) > 0) {
                 $tabs[$groupName] = DataCenterUI::renderWidget('table', array('rows' => $rackGroup, 'fields' => array('manufacturer', 'model' => array('field' => 'name'), 'serial', 'asset', 'location' => array('fields' => array('location_name', 'location_region'), 'glue' => ' / ')), 'link' => array('page' => 'plans', 'type' => 'rack', 'id' => $path['id'], 'action' => 'attach', 'parameter' => array('plan', $path['parameter'][1], '#id'))));
             } else {
                 $tabs[$groupName] = null;
             }
         }
         // Returns 2 columm layout with a form and a scene
         return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'select-attach-type', 'type' => 'rack')), DataCenterUI::renderLayout('tabs', $tabs)))));
     }
 }
Example #2
0
 public function select($path)
 {
     // Checks if...
     if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 2 && $path['parameter'][0] == 'rack') {
         $rackLink = DataCenterDB::getAssetLink($path['parameter'][1]);
         $plan = DataCenterDB::getPlan($rackLink->get('plan'));
         $space = $plan->getSpace();
         // Gets object links which are linked to this rack
         $objectLinks = DataCenterDB::getAssetLinks(array_merge_recursive(DataCenterDB::buildCondition('link', 'asset', 'plan', $plan->getId()), DataCenterDB::buildCondition('link', 'asset', 'parent_link', $rackLink->getId()), DataCenterDB::buildCondition('link', 'asset', 'asset_type', 'object')));
         $existsTable = array();
         foreach ($objectLinks as $objectLink) {
             $existsTable[$objectLink->get('asset_id')] = true;
         }
         // Additional filters for racking objects
         $conditions = array();
         if ($path['parameter'][0] == 'rack') {
             $conditions = DataCenterDB::buildCondition('model', 'object', 'form_factor', 'rackunit');
         }
         // Gets objects from database in two varieties, local and remote
         $objects = array('local' => DataCenterDB::getAssets('object', array_merge_recursive($conditions, DataCenterDB::buildCondition('asset', 'object', 'location', $space->get('location')), DataCenterDB::buildJoin('model', 'object', 'id', 'asset', 'object', 'model', array('name', 'manufacturer')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', 'object', 'location', array('name' => 'location_name', 'region' => 'location_region')))), 'remote' => DataCenterDB::getAssets('object', array_merge_recursive($conditions, DataCenterDB::buildCondition('asset', 'object', 'location', $space->get('location'), '!='), DataCenterDB::buildJoin('model', 'object', 'id', 'asset', 'object', 'model', array('name', 'manufacturer')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', 'object', 'location', array('name' => 'location_name', 'region' => 'location_region')))));
         $tabs = array();
         foreach ($objects as $groupName => $objectGroup) {
             // Removes objects which are already in use
             foreach ($objectGroup as $key => $object) {
                 if (isset($existsTable[$object->getId()])) {
                     unset($objectGroup[$key]);
                 }
             }
             // Checks if there are any objects to display
             if (count($objectGroup) > 0) {
                 // Builds table
                 $tabs[$groupName] = DataCenterUI::renderWidget('table', array('rows' => $objectGroup, 'fields' => array('manufacturer', 'model' => array('field' => 'name'), 'serial', 'asset', 'location' => array('fields' => array('location_name', 'location_region'), 'glue' => ' / ')), 'link' => array('page' => 'plans', 'type' => 'object', 'id' => $path['id'], 'action' => 'attach', 'parameter' => array($path['parameter'][0], $path['parameter'][1], '#id'))));
             } else {
                 $tabs[$groupName] = null;
             }
         }
         // Returns 2 columm layout with a form and a scene
         return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'select-attach-type', 'type' => 'object')), DataCenterUI::renderLayout('tabs', $tabs)))));
     }
 }
 /**
  * Gets flat list of links
  */
 public function getLinks(array $options = array())
 {
     if (!$this->links) {
         $this->links = DataCenterDB::getAssetLinks(DataCenterDB::buildCondition('link', 'asset', 'plan', $this->getId()));
     }
     return $this->links;
 }