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))))); } }
public function main($path) { if (!isset(self::$options[$path['type']])) { return DataCenterUI::renderWidget('body', array('message' => 'invalid-request', 'type' => 'error')); } // Gets all assets from database $assets = DataCenterDB::getAssets($path['type'], array_merge_recursive(DataCenterDB::buildJoin('model', $path['type'], 'id', 'asset', $path['type'], 'model', array('name', 'manufacturer')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', $path['type'], 'location', array('name' => 'location_name')), DataCenterDB::buildRange($path))); $numAssets = DataCenterDB::numAssets($path['type']); // Returns single columm layout with a table return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'assets-type', 'subject' => DataCenterUI::message('type', $path['type']))), DataCenterUI::renderWidget('table', array('rows' => $assets, 'num' => $numAssets, 'fields' => array('manufacturer', 'model' => array('field' => 'name'), 'serial', 'asset', 'tense' => array('format' => 'option'), 'location' => array('field' => 'location_name')), 'link' => array('page' => 'assets', 'type' => $path['type'], 'id' => '#id', 'action' => 'view'))), DataCenterUI::renderWidget('actions', array('links' => array(array('page' => 'assets', 'type' => $path['type'], 'action' => 'design')), 'rights' => array('change'))))))); }
public static function render(array $parameters) { global $wgUser; // Gets current path $path = DataCenterPage::getPath(); // Sets Defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); // Adds result type menu $currentTarget = null; $currentNum = null; $menuItems = array(); foreach (self::$targets as $target) { $numMatches = DataCenterDB::numMatches($target['category'], $target['type'], $target['fields'], $parameters['query']); if ($numMatches == 0) { continue; } $fusedType = $target['category'] . '.' . $target['type']; if (!$path['type']) { $path['type'] = $fusedType; } if ($path['type'] == $fusedType) { $currentTarget = $target; $currentNum = $numMatches; $state = 'current'; } else { $state = 'normal'; } $typePath = array_merge($path, array('type' => $target['category'] . '.' . $target['type'])); $menuItems[] = DataCenterXml::div(array('class' => 'type-' . $state), DataCenterXml::link(DataCenterUI::message('results', $target['category'] . '-' . $target['type'], $numMatches), $typePath)); } $resultItems = array(); if (!$currentTarget) { $xmlOutput .= DataCenterUI::renderWidget('body', array('message' => 'notice-no-results', 'style' => 'notice')); } else { $joins = array(); if ($currentTarget['class'] == 'DataCenterDBAsset') { $joins = array_merge_recursive(DataCenterDB::buildJoin('model', $currentTarget['type'], 'id', 'asset', $currentTarget['type'], 'model', array('name', 'manufacturer')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', $currentTarget['type'], 'location', array('name' => 'location_name'))); } // Gets search results $results = DataCenterDB::getMatches($currentTarget['class'], $currentTarget['category'], $currentTarget['type'], $currentTarget['fields'], $parameters['query'], array_merge_recursive($joins, DataCenterDB::buildRange($path))); // Adds types $xmlOutput .= DataCenterXml::div(array('class' => 'types'), implode($menuItems)); // Adds results $xmlOutput .= DataCenterXml::div(array('class' => 'results'), DataCenterUI::renderWidget('table', array_merge($currentTarget['table'], array('rows' => $results, 'num' => $currentNum)))); } // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public function main($path) { // Gets all components from database $spaces = DataCenterDB::getSpaces(array_merge_recursive(DataCenterDB::buildJoin('facility', 'location', 'id', 'facility', 'space', 'location', array('name' => 'location_name')), DataCenterDB::buildSort('facility', 'space', array('location_name', 'name')))); $spacesTable = DataCenterDB::buildLookupTable('tense', $spaces); $tables = array(); foreach (array('present', 'future', 'past') as $tense) { if (isset($spacesTable[$tense])) { $tables[$tense] = DataCenterUI::renderWidget('table', array('rows' => $spacesTable[$tense], 'fields' => array('name', 'location' => array('field' => 'location_name'), 'size' => array('fields' => array('width', 'height', 'depth'), 'glue' => 'x'), 'power'), 'link' => array('page' => 'facilities', 'type' => 'space', 'id' => '#id', 'action' => 'view'))); } else { $tables[$tense] = null; } } // Returns 2 columm layout with a table and a map widget return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'spaces')), DataCenterUI::renderLayout('tabs', $tables))))); }
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 meta values associated to this component */ public function getMetaValues() { return DataCenterDB::getRows('DataCenterDBMetaValue', 'meta', 'value', array_merge_recursive(DataCenterDB::buildCondition('meta', 'value', 'component_category', $this->category), DataCenterDB::buildCondition('meta', 'value', 'component_type', $this->type), DataCenterDB::buildCondition('meta', 'value', 'component_id', $this->getId()), DataCenterDB::buildJoin('meta', 'field', 'id', 'meta', 'value', 'field', array('name', 'format')))); }