public static function render(array $parameters) { // Adds script to UI DataCenterUI::addScript('/extensions/DataCenter/Resources/Widgets/Plan/Plan.js'); // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Checks if width was given as an integer if (is_int($parameters['width'])) { // Converts width to CSS pixel definition $parameters['width'] .= 'px'; } // Checks if height was given as an integer if (is_int($parameters['height'])) { // Converts height to CSS pixel definition $parameters['height'] .= 'px'; } // Begins widget $xmlOutput = parent::begin($parameters['class']); // Adds XML element $xmlOutput .= DataCenterXML::div(array('id' => $parameters['id'], 'style' => DataCenterCss::toAttributes(array('width' => $parameters['width'], 'height' => $parameters['height']))), ' '); // Builds script for adding setup job to renderer $jsOutput = DataCenterJs::callFunction('dataCenter.renderer.addJob', array(DataCenterJs::toScalar('scene'), DataCenterJs::toScalar($parameters['id']), self::addPlanJsFunction($parameters))); // Adds script $xmlOutput .= DataCenterXml::script($jsOutput); // Begins widget $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Adds buttons foreach (array('past', 'present', 'future') as $tense) { $radioAttributes = array('type' => 'radio', 'id' => $parameters['id'] . '_' . $tense, 'name' => $parameters['name'], 'value' => $tense, 'class' => 'button'); $labelAttributes = array('for' => $parameters['id'] . '_' . $tense, 'class' => 'label'); if ($parameters['value'] == $tense) { $radioAttributes['checked'] = 'checked'; } if (in_array($tense, $parameters['disable'])) { $radioAttributes['disabled'] = 'true'; $labelAttributes['class'] .= ' disabled'; } $xmlOutput .= DataCenterXml::tag('input', $radioAttributes); $xmlOutput .= DataCenterXml::tag('label', $labelAttributes, DataCenterUI::message('option', $tense)); } // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
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']); // Builds form attributes $formAttributes = array('id' => 'form_search', 'name' => 'form_search', 'method' => 'post', 'action' => DataCenterXml::url(array('page' => 'search'))); // Begins form $xmlOutput .= DataCenterXml::open('form', $formAttributes); // Adds query field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'text', 'class' => 'query', 'name' => 'meta[query]', 'value' => $path['page'] == 'search' ? urldecode($path['parameter']) : '')); // Adds search button $xmlOutput .= DataCenterXml::tag('input', array('type' => 'submit', 'class' => 'search', 'name' => 'meta[search]', 'value' => DataCenterUI::message('label', 'search'))); // Adds do field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => 'search')); // Adds token field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken())); // Ends form $xmlOutput .= DataCenterXml::close('form'); // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); // Checks for... if (is_scalar($parameters['message']) && $parameters['message'] !== null) { // Checks if a subject was given if ($parameters['subject'] !== null) { // Uses subject-based message $message = DataCenterUI::message('heading', $parameters['message'], $parameters['subject']); } elseif ($parameters['type'] !== null) { // Checks if a type was given // Uses type-based message $message = DataCenterUI::message('heading', $parameters['message'], DataCenterUI::message('type', $parameters['type'])); } else { // Uses plain message $message = DataCenterUI::message('heading', $parameters['message']); } // Returns heading with message $xmlOutput .= $message; // Checks if text was given } elseif ($parameters['text'] !== null) { // Adds a heading with text $xmlOutput .= $parameters['text']; } // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); // Begins table $xmlOutput .= DataCenterXml::open('table'); // Checks that an array of fields and valid row was given if (is_array($parameters['fields']) && $parameters['row'] instanceof DataCenterDBRow) { // Loops over each field foreach ($parameters['fields'] as $key => $value) { $values = array(); if (is_int($key)) { $label = $value; $value = $parameters['row']->get($value); } else { $label = $key; if (is_array($value)) { if (isset($value['fields'])) { foreach ($value['fields'] as $fieldName) { $values[] = DataCenterUI::format($parameters['row']->get($fieldName), isset($value['format']) ? $value['format'] : null); } } elseif (isset($value['field'])) { $value = DataCenterUI::format($parameters['row']->get($value['field']), isset($value['format']) ? $value['format'] : null); } else { $value = DataCenterUI::format($parameters['row']->get($key), isset($value['format']) ? $value['format'] : null); } } else { $value = $parameters['row']->get($key); } } if (isset($value['glue'])) { $glue = $value['glue']; } else { $glue = ', '; } // Adds row $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(array('class' => 'label'), DataCenterUI::message('field', $label)), DataCenterXml::cell(array('class' => 'value'), count($values) ? implode($glue, $values) : $value)); } } if ($parameters['meta'] && $parameters['row'] instanceof DataCenterDBComponent) { $values = $parameters['row']->getMetaValues(); foreach ($values as $value) { // Adds row $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(array('class' => 'label'), $value->get('name')), DataCenterXml::cell(array('class' => 'value'), DataCenterUI::format($value->get('value'), $value->get('format')))); } } // Ends table $xmlOutput .= DataCenterXml::close('table'); // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public function history($path) { if ($path['type'] == 'location') { $facility = DataCenterDB::getLocation($path['id']); } elseif ($path['type'] == 'space') { $facility = DataCenterDB::getSpace($path['id']); } else { return null; } return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'history-type', 'subject' => DataCenterUI::message('type', $path['type']))), DataCenterUI::renderWidget('history', array('component' => $facility)))))); }
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 static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Adds button $xmlOutput .= DataCenterXml::tag('input', array('type' => 'button', 'id' => $parameters['id'], 'name' => $parameters['name'], 'class' => 'button', 'value' => DataCenterUI::message('label', $parameters['label']))); // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
private static function markerOptions(array $parameters, $location) { // Begins window $xmlOutput = DataCenterXml::open('div', array('class' => 'window')); // Adds heading $xmlOutput .= DataCenterXml::div(array('class' => 'heading'), DataCenterXml::link($location->get('name'), array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $location->getId()))); // Gets number of spaces in location $numSpaces = DataCenterDB::numSpaces(DataCenterDB::buildCondition('facility', 'space', 'location', $location->getId())); // Adds body $xmlOutput .= DataCenterXml::div(array('class' => 'body'), DataCenterXml::div(array('class' => 'region'), $location->get('region')) . DataCenterXml::div(array('class' => 'spaces'), DataCenterUI::message('label', 'num-spaces', $numSpaces))); // Ends window $xmlOutput .= DataCenterXml::close('div'); // Returns JavaScript object of options return DataCenterJs::toObject(array('content' => $xmlOutput)); }
private static function renderModel($parameters, $structure, $level = 0) { $xmlOutput = ''; foreach ($structure as $model) { $modelLink = DataCenterDB::getModelLink($model->get('link')); if (!DataCenterPage::userCan('change')) { $rowAttributes = array(); } elseif ($level == 0 && count($parameters['link']) > 0) { $rowAttributes = array_merge(array('class' => 'link'), DataCenterXml::buildLink($parameters['link'], $model)); } else { $rowAttributes = array('class' => 'mute'); } $xmlOutput .= DataCenterXml::row($rowAttributes, DataCenterXml::cell(DataCenterXml::div(array('style' => 'padding-left:' . $level * 15 . 'px'), $modelLink->get('name'))) . DataCenterXml::cell(array('align' => 'right'), $modelLink->get('quantity')) . DataCenterXml::cell($model->get('name')) . DataCenterXml::cell(DataCenterUI::message('type', $model->getType()))); $xmlOutput .= self::renderModel($parameters, $model->getStructure(), $level + 1); } return $xmlOutput; }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Checks for permissions if (!DataCenterPage::userCan($parameters['rights'])) { return null; } // Begins widget $xmlOutput = parent::begin($parameters['class']); // Checks if links is an array if (is_array($parameters['links'])) { // Loops over each link foreach ($parameters['links'] as $label => $link) { // Checks if link is not an array if (!is_array($link)) { // Skips the invalid data continue; } // Checks if a label was not given but an action was if (is_int($label) && isset($link['action'])) { // Uses action as label $label = $link['action']; } if (is_array($link[$parameters['subject']])) { $subject = current($link[$parameters['subject']]); } else { $subject = $link[$parameters['subject']]; } // Builds label $label = DataCenterUI::message('action', $label . '-type', DataCenterUI::message('type', $subject)); // Builds link $link = DataCenterXml::link($label, $link); // Adds action link $xmlOutput .= DataCenterXml::div(array('class' => 'action'), $link); } } // Ends widget $xmlOutput .= parent::end(); $xmlOutput .= DataCenterXml::clearFloating(); // Returns results return $xmlOutput; }
public function configure($path) { // Detects mode if (!$path['id']) { // Creates new component $field = DataCenterDBMetaField::newFromValues(); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'settings', 'type' => 'field')); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'adding-type', 'type' => 'field'))); } else { // Gets component from database $field = DataCenterDB::getMetaField($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'settings', 'type' => 'field', 'action' => 'view', 'id' => $path['id'])); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'configuring-type', 'type' => 'field')), DataCenterUI::renderWidget('body', array('message' => 'important-configuring-field', 'style' => 'important'))); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array_merge($rows, array(DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'settings', 'type' => 'field'), 'row' => $field, 'fields' => array('name' => array('type' => 'string'), 'format' => array('type' => 'list', 'enum' => array('category' => 'meta', 'type' => 'field', 'field' => 'format'))))))))), ' ')); }
public function edit($path) { // Checks if... if (!$path['id'] && is_array($path['parameter']) && count($path['parameter'] >= 2) && $path['parameter'][0] == 'location') { // Creates new facility with default parameters $space = DataCenterDBSpace::newFromValues(array('location' => $path['parameter'][1], 'tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'space')))); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'hidden' => array($path['parameter'][0]), 'success' => array('page' => 'facilities', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1]), 'type' => 'add'); $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets facility from database $space = DataCenterDB::getSpace($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('location', 'id'), 'success' => array('page' => 'facilities', 'type' => 'space', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit'); $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Builds JavaScript to access renderable facility $jsTarget = DataCenterJs::chain(array("dataCenter.renderer.getTarget" => DataCenterJs::toScalar('space'), 'getModule'), false); // Complete form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'space'), 'row' => $space, 'fields' => array('tense' => array('type' => 'tense', 'disable' => array('past')), 'name' => array('type' => 'string'), 'width' => array('type' => 'number', 'effect' => $jsTarget . '.setWidth( {this}.value, true );'), 'height' => array('type' => 'number', 'effect' => $jsTarget . '.setHeight( {this}.value, true );'), 'depth' => array('type' => 'number', 'effect' => $jsTarget . '.setDepth( {this}.value, true );'), 'power' => array('type' => 'number', 'min' => 0, 'max' => 100000, 'step' => 100)))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('space', array('space' => $space)))); }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Creates list of buttons $buttons = array('true' => true, 'false' => false); // Adds buttons foreach ($buttons as $button => $value) { $radioAttributes = array('type' => 'radio', 'id' => $parameters['id'] . '_' . $button, 'name' => $parameters['name'], 'value' => $value ? 1 : 0, 'class' => 'button'); $labelAttributes = array('for' => $parameters['id'] . '_' . $button, 'class' => 'label'); if ($parameters['value'] == ($value ? 1 : 0) && $parameters['value'] !== null && $parameters['value'] !== '') { $radioAttributes['checked'] = 'checked'; } $xmlOutput .= DataCenterXml::tag('input', $radioAttributes); $xmlOutput .= DataCenterXml::tag('label', $labelAttributes, DataCenterUI::message('option', $button)); } // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
public function edit($path) { // Detects mode if (!$path['id']) { // Creates a new facility location $location = DataCenterDBLocation::newFromValues(array('tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'location')))); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'facilities', 'type' => 'location'), 'type' => 'add'); $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets facility location from database $location = DataCenterDB::getLocation($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit'); $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Builds JavaScript that hooks the button into the geocoder $jsForm = 'document.form_save'; $jsOut = DataCenterJs::callFunction('addHandler', array("{$jsForm}.field_button_0", DataCenterJs::toScalar('click'), DataCenterJs::buildFunction(null, DataCenterJs::chain(array('dataCenter.renderer.getTarget' => DataCenterJs::toScalar('map'), 'showAddress' => array('document.form_save.field_region.value', DataCenterJs::toObject(array('latField' => "'{$jsForm}.field_latitude'", 'lngField' => "'{$jsForm}.field_longitude'")))))))); // Complete form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'location'), 'row' => $location, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'region' => array('type' => 'string'), array('type' => 'button', 'label' => 'lookup'), 'latitude' => array('type' => 'string'), 'longitude' => array('type' => 'string')))); // Returns 2 columm layout with a form and a map widget return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('map', !$path['id'] ? array() : array('location' => $location)))) . DataCenterXml::script($jsOut); }
public static function render(array $parameters) { global $wgScriptPath; // Checks that... if (isset($parameters['fields']['x'], $parameters['fields']['y']) && is_array($parameters['fields']['x']) && is_array($parameters['fields']['y']) && count($parameters['fields']) == 2) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Builds resource path $resourcePath = $wgScriptPath . '/extensions/DataCenter/Resources/Inputs/Position/'; // Converts mode to upper case to avoid case-sensitivity errors $mode = strtoupper($parameters['mode']); // Builds list of resource paths $resources = array('normal' => $resourcePath . $mode . '-Normal.png', 'n' => $resourcePath . $mode . '-N.png', 'e' => $resourcePath . $mode . '-E.png', 's' => $resourcePath . $mode . '-S.png', 'w' => $resourcePath . $mode . '-W.png'); // Builds lists of image map polygons $polygons = array('2D' => array('n' => '24,2,42,2,42,16,24,16', 'e' => '42,2,58,2,58,32,42,32', 's' => '24,16,42,16,42,32,24,32', 'w' => '8,2,24,2,24,32,8,32'), 'ISO' => array('n' => '30,0,60,17,30,17', 'e' => '60,17,30,34,30,17', 's' => '30,34,0,17,30,17', 'w' => '0,17,30,0,30,17')); // Creates structure of elements to be created $structure = array('x' => array('e' => array('op' => '+', 'func' => 'min', 'limit' => 'max'), 'w' => array('op' => '-', 'func' => 'max', 'limit' => 'min')), 'y' => array('n' => array('op' => '-', 'func' => 'max', 'limit' => 'min'), 's' => array('op' => '+', 'func' => 'min', 'limit' => 'max'))); // Creates shortcut to fields $fields = $parameters['fields']; // Builds effect $effect = DataCenterJs::buildEffect($parameters['effect'], array('this.x' => sprintf("document.getElementById( %s )", DataCenterJs::toScalar($fields['x']['id'])), 'this.y' => sprintf("document.getElementById( %s )", DataCenterJs::toScalar($fields['y']['id'])))); // Loops over each field $jsOutput = ''; foreach ($structure as $field => $directions) { // Adds label $xmlOutput .= DataCenterXml::tag('label', array('for' => $fields[$field]['id'], 'class' => 'label'), DataCenterUI::message('field', 'position-' . $field)); // Adds input $xmlOutput .= DataCenterXml::tag('input', array('type' => 'text', 'name' => $fields[$field]['name'], 'id' => $fields[$field]['id'], 'class' => 'number', 'value' => $fields[$field]['value'])); // Calculates minimum and maximum values $range = array('min' => min($fields[$field]['min'], $fields[$field]['max']), 'max' => max($fields[$field]['min'], $fields[$field]['max'])); foreach ($directions as $direction => $options) { // Builds javascript to connect button to input $jsOutput .= <<<END \t\t\t\t\t\t\$('#{$fields[$field]['id']}_{$direction}).on({ \t\t\t\t\t\t\t'mouseover': \t\t\t\t\t\t\tfunction() { \t\t\t\t\t\t\t\tdocument.getElementById( \t\t\t\t\t\t\t\t\t'{$parameters['id']}' \t\t\t\t\t\t\t\t).src = '{$resources[$direction]}'; \t\t\t\t\t\t\t}, \t\t\t\t\t\t\t'mouseout': \t\t\t\t\t\t\tfunction() { \t\t\t\t\t\t\t\tdocument.getElementById( \t\t\t\t\t\t\t\t\t'{$parameters['id']}' \t\t\t\t\t\t\t\t).src = '{$resources['normal']}'; \t\t\t\t\t\t\t}, \t\t\t\t\t\t\t'click': \t\t\t\t\t\t\tfunction() { \t\t\t\t\t\t\t\tvar input = document.getElementById( \t\t\t\t\t\t\t\t\t'{$fields[$field]['id']}' \t\t\t\t\t\t\t\t); \t\t\t\t\t\t\t\tvar value = parseInt( input.value ); \t\t\t\t\t\t\t\tif ( !isNaN( value ) ) { \t\t\t\t\t\t\t\t\tinput.value = Math.{$options['func']}( \t\t\t\t\t\t\t\t\t\tvalue {$options['op']} 1, \t\t\t\t\t\t\t\t\t\t{$range[$options['limit']]} \t\t\t\t\t\t\t\t\t) \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t{$effect} \t\t\t\t\t\t\t} \t\t\t\t\t\t}); END; } } // Begins map $xmlOutput .= DataCenterXml::open('map', array('name' => "{$parameters['id']}_map")); // Loops over each field foreach ($structure as $field => $directions) { // Loops over each direction foreach ($directions as $direction => $options) { $xmlOutput .= DataCenterXml::tag('area', array('href' => '#', 'shape' => 'poly', 'coords' => $polygons[$mode][$direction], 'id' => $fields[$field]['id'] . '_' . $direction)); } } // Ends map $xmlOutput .= DataCenterXml::close('map'); // Adds image $xmlOutput .= DataCenterXml::tag('img', array('src' => $resources['normal'], 'usemap' => "#{$parameters['id']}_map", 'id' => $parameters['id'], 'class' => 'navigator')); // Adds JavaScript $xmlOutput .= DataCenterXml::script($jsOutput); // Begins preloading $xmlOutput .= DataCenterXml::open('div', array('style' => 'display:none')); // Loops over each resource foreach ($resources as $resource) { // Adds resource $xmlOutput .= DataCenterXml::tag('img', array('src' => $resource)); } // Ends preloading $xmlOutput .= DataCenterXml::close('div'); // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; } }
public function configure($path) { // Detects mode if (!$path['id']) { if (is_array($path['parameter']) && count($path['parameter']) >= 2 && $path['parameter'][0] == 'space') { // Gets space from database $space = DataCenterDB::getSpace($path['parameter'][1]); // Creates new component $plan = DataCenterDBPlan::newFromValues(array('space' => $path['parameter'][1], 'tense' => 'present', 'name' => $space->get('name'))); // Sets 'do' specific parameters $formParameters = array('label' => 'create', 'hidden' => array('space'), 'success' => array('page' => 'plans')); $headingParameters = array('message' => 'adding-type', 'type' => 'plan'); } else { throw new MWException('Invalid parameters. space,# expected.'); } } else { // Gets component from database $plan = DataCenterDB::getPlan($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'plan', 'action' => 'view', 'id' => $path['id'])); $headingParameters = array('message' => 'configuring-type', 'type' => 'plan'); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'plan'), 'row' => $plan, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'note' => array('type' => 'text'))))))), DataCenterUI::renderWidget('plan', array('plan' => $plan)))); }
public function configure($path) { // Checks if... if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 3 && $path['parameter'][0] == 'rack') { $object = DataCenterDB::getAsset('object', $path['parameter'][2]); $model = $object->getModel(); $rackLink = DataCenterDB::getAssetLink($path['parameter'][1]); $rack = $rackLink->getAsset(); $plan = DataCenterDB::getPlan($rackLink->get('plan')); $objectLink = DataCenterDBAssetLink::newFromValues(array('name' => $model->get('kind'), 'plan' => $plan->getId(), 'parent_link' => $rackLink->getId(), 'asset_type' => 'object', 'asset_id' => $object->getId(), 'z' => 1, 'orientation' => 0)); // Sets action specific parameters $formParameters = array('label' => 'attach', 'hidden' => array('plan', 'parent_link', 'asset_type', 'asset_id'), 'success' => array('page' => 'plans', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1])); $headingParameters = array('message' => 'attaching-type', 'type' => 'object'); } else { // Gets asset from database $objectLink = DataCenterDB::getAssetLink($path['id']); // Gets object that object link links to $object = $objectLink->getAsset(); // Gets plan from database $plan = DataCenterDB::getPlan($objectLink->get('plan')); // Gets rack link object is linked to $rackLink = DataCenterDB::getAssetLink($objectLink->get('parent_link')); // Extracts rack from rack link $rack = $rackLink->getAsset(); // Sets action specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'object', 'action' => 'view', 'id' => $path['id'])); $headingParameters = array('message' => 'configuring-type', 'type' => 'object'); } // Builds javascript that references the renderable asset $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule'); $rackId = $rack->getId(); $rackModel = $rack->getModel(); $objectModel = $object->getModel(); $objectId = $object->getId(); $maxZ = $rackModel->get('units') - $objectModel->get('units') + 1; // Builds form parameters $formFields = array('name' => array('type' => 'string'), 'position' => array('type' => 'number', 'field' => 'z', 'min' => 1, 'max' => $maxZ, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectPosition' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false)), 'orientation' => array('type' => 'number', 'min' => 0, 'max' => 1, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectOrientation' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'object'), 'row' => $objectLink, 'fields' => $formFields))))), DataCenterUI::renderWidget('plan', array('plan' => $plan, 'current-rack' => $rack->getId(), 'look-at-rack' => $rack->getId(), 'current-object' => $object->getId(), 'include' => !$path['id'] ? $objectLink : null)))); }
public static function render(array $parameters) { // Increment the number of tabbed layouts in existence self::$sets++; // Gets id for this set $set = self::$sets; // Begins layout $xmlOutput = parent::begin(self::$parameters['class']); $xmlOutput .= DataCenterXml::open('div', array('class' => 'tabs')); // Loops over each content block $state = 'current'; $tab = 0; foreach ($parameters as $name => $content) { if ($content !== null) { // Adds row $xmlOutput .= DataCenterXml::div(array('class' => 'item-' . $state, 'id' => 'tabs_' . $set . '_tab_' . $tab, 'onclick' => DataCenterJs::callFunction('dataCenter.ui.layouts.tabs.select', array(DataCenterJs::toScalar($set), DataCenterJs::toScalar($tab)))), DataCenterUI::message('tab', $name)); $state = 'normal'; $tab++; } else { $xmlOutput .= DataCenterXml::div(array('class' => 'item-disabled'), DataCenterUI::message('tab', $name)); } } $xmlOutput .= DataCenterXml::close('div'); $xmlOutput .= DataCenterXml::clearFloating(); // Loops over each content block $display = 'block'; $tab = 0; foreach ($parameters as $content) { if ($content !== null) { // Adds row $xmlOutput .= DataCenterXml::div(DataCenterXml::div(array('class' => 'page', 'id' => 'tabs_' . $set . '_page_' . $tab, 'style' => 'display:' . $display), $content)); $display = 'none'; $tab++; } } // Ends layout $xmlOutput .= parent::end(); // Builds javascript for layout $jsOutput = <<<END \t\t\tif ( !dataCenter.ui.layouts.tabs ) { \t\t\t\tdataCenter.ui.layouts.tabs = { \t\t\t\t\tsets: {}, \t\t\t\t\tselect: function( \t\t\t\t\t\tsetID, tabID \t\t\t\t\t) { \t\t\t\t\t\tif ( this.sets[setID] ) { \t\t\t\t\t\t\tfor ( var i = 0; i < this.sets[setID].count; i++ ) { \t\t\t\t\t\t\t\tvar page = document.getElementById( \t\t\t\t\t\t\t\t\t'tabs_' + setID + '_page_' + i \t\t\t\t\t\t\t\t); \t\t\t\t\t\t\t\tvar tab = document.getElementById( \t\t\t\t\t\t\t\t\t'tabs_' + setID + '_tab_' + i \t\t\t\t\t\t\t\t); \t\t\t\t\t\t\t\tif ( tab && page ) { \t\t\t\t\t\t\t\t\tif ( i == tabID ) { \t\t\t\t\t\t\t\t\t\tpage.style.display = 'block'; \t\t\t\t\t\t\t\t\t\ttab.className = 'item-current'; \t\t\t\t\t\t\t\t\t} else { \t\t\t\t\t\t\t\t\t\tpage.style.display = 'none'; \t\t\t\t\t\t\t\t\t\ttab.className = 'item-normal'; \t\t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t}, \t\t\t\t\taddSet: function( name, count ) { \t\t\t\t\t\tthis.sets[name] = {}; \t\t\t\t\t\tthis.sets[name].count = count; \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t\t// Add information for this set \t\t\tdataCenter.ui.layouts.tabs.addSet( {$set}, {$tab} ); END; // Adds script $xmlOutput .= DataCenterXml::script($jsOutput); // Returns results return $xmlOutput; }
/** * Builds and stores menus in output cache * @param pages Array of pages for main menu, with keys as page * names * @param controller DataCenterController of the current page's * controller * @param path Array of link parameters of current path */ public static function setDestinations(array $pages, DataCenterController $controller, array $path) { global $wgUser; // Adds main menu self::$output['menu'] .= DataCenterXml::open('div', array('class' => 'menu')); foreach ($pages as $page => $classes) { if ($classes['display']) { $state = $page == $path['page'] ? 'current' : 'normal'; self::$output['menu'] .= DataCenterXml::div(array('class' => 'item-' . $state), DataCenterXml::link(self::message('page', $page), array('page' => $page))); } } self::$output['menu'] .= DataCenterXml::close('div'); // Adds search self::$output['menu'] .= DataCenterUI::renderWidget('search', array()); // Adds sub menu self::$output['menu'] .= DataCenterXml::open('div', array('class' => 'toolbar')); // Type tabs if (count($controller->types) > 0) { self::$output['menu'] .= DataCenterXml::div(array('class' => 'type-label'), self::message('label', 'browse-by')); foreach ($controller->types as $label => $type) { $state = $label == $path['type'] ? 'current' : 'normal'; self::$output['menu'] .= DataCenterXml::div(array('class' => 'type-' . $state), DataCenterXml::link(self::message('type', $label), $type)); } } // Trail steps $count = 1; foreach ($controller->trail as $label => $step) { $end = $count == count($controller->trail) ? '-end' : ''; self::$output['menu'] .= DataCenterXml::div(array('class' => 'breadcrumb' . $end), DataCenterXml::link($label, $step)); $count++; } // Action tabs foreach ($controller->actions as $label => $action) { $state = $label == $path['action'] ? 'current' : 'normal'; self::$output['menu'] .= DataCenterXml::div(array('class' => 'action-' . $state), DataCenterXml::link(self::message('action', $label), $action)); } self::$output['menu'] .= DataCenterXml::close('div'); }
public function main($path) { $plans = DataCenterDB::getPlans(DataCenterDB::buildSort('meta', 'plan', array('space', 'tense DESC'))); $numPlans = DataCenterDB::numPlans(); return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'plans')), DataCenterUI::renderWidget('table', array('rows' => $plans, 'num' => $numPlans, 'fields' => array('name', 'space' => array('field' => 'space_name'), 'tense' => array('format' => 'option')), 'link' => array('page' => 'plans', 'action' => 'view', 'type' => 'plan', 'id' => '#id'))))))); }
public function execute($sub) { global $wgOut, $wgScriptPath, $wgUser, $wgRequest; // Checks if the user is logged in if (!$wgUser->isLoggedIn()) { // Lets them know they need to $wgOut->loginToUse(); // Returns true so MediaWiki can move on return true; } // Gets user rights self::$rights = $wgUser->getRights(); if (!self::userCan('view')) { $wgOut->permissionRequired('datacenter-view'); return true; } // Keeps some state between pages self::loadState(); // Begins output $this->setHeaders(); // Checks if the path is empty if ($sub == '') { // Uses the first page in the array as a default $sub = current(array_keys(self::$pages)); } // Gets path from sub $path = self::subToPath($sub); // Verifies page name and parameters if (isset(self::$pages[$path['page']])) { // Makes shortcut to page classes $pageClasses = self::$pages[$path['page']]; // Makes shortcut to controller class $controllerClass = $pageClasses['controller']; // Verifies existence of page class if (class_exists($controllerClass)) { // Creates instance of page class $controller = new $controllerClass($path); // Checks if the view is empty if ($path['action'] === null) { // Uses default action $path['action'] = 'main'; } // Checks if the type is empty if ($path['type'] === null) { // Checks if default type is available if (isset(self::$pages[$path['page']]['default'])) { // Uses default type $path['type'] = self::$pages[$path['page']]['default']; } } // Verifies instance inherited the correct parent class if ($controller instanceof DataCenterController) { // Verifies the current edit token matches any passed token $token = $wgRequest->getText('token'); if ($wgUser->matchEditToken($token)) { // Gets the action to be performed $do = $wgRequest->getText('do'); // Verifies handler is not the instance's constructor and // that action exists in the instance if ($do !== '__constructor' && is_callable(array($controllerClass, $do))) { if ($wgRequest->getCheck('cancel')) { // Redirects to success URL without acting $wgOut->redirect($wgRequest->getText('cancellation')); } else { // Gets submitted data $data = array('row' => $wgRequest->getArray('row'), 'meta' => $wgRequest->getArray('meta'), 'change' => $wgRequest->getArray('change')); // Delegates handling of form submissions $status = $controller->{$do}($data, $path['type']); // Checks if status is not null if ($status !== null) { // Redirects to success or failure URL $wgOut->redirect($wgRequest->getText($status ? 'success' : 'failure')); } } } } // Sets destinations for menus DataCenterUI::setDestinations(self::$pages, $controller, $path); $viewClass = null; // Checks if specialized view exists if (isset($pageClasses['types'][$path['type']])) { // Uses specialized view $viewClass = $pageClasses['types'][$path['type']]; // Verifies specialized view can handle action $renderFunction = array($viewClass, $path['action']); if (!is_callable($renderFunction)) { $viewClass = null; } } // Checks if a view class has been not selected yet if (!$viewClass) { // Uses generic view $viewClass = $pageClasses['view']; // Verifies generic view can handle action $renderFunction = array($viewClass, $path['action']); if (!is_callable($renderFunction)) { $viewClass = null; } } // Verifies page user interface class exists if ($viewClass && class_exists($viewClass)) { // Creates instance of page user interface class $view = new $viewClass($controller); // Verifies the action is not the instance's constructor if ($path['action'] !== '__constructor') { // Renders view of instance $renderFunction = array($view, $path['action']); DataCenterUI::addContent(call_user_func($renderFunction, $path)); } } } } } DataCenterUI::render(); // Keeps some state between pages self::saveState(); }
public function main($path) { return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'overview')), DataCenterUI::renderWidget('body', array('message' => 'important-welcome', 'style' => 'important')))))); }
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']); // Gets existing links from database $metaFieldLinks = $parameters['field']->getLinks(); $existsTable = array(); foreach ($metaFieldLinks as $metaFieldLink) { $key = implode('_', $metaFieldLink->get(array('component_category', 'component_type'))); $existsTable[$key] = $metaFieldLink; } // Builds form attributes $formAttributes = array('id' => 'form_fieldlinks', 'name' => 'form_fieldlinks', 'method' => 'post', 'action' => DataCenterXml::url($path)); // Begins form $xmlOutput .= DataCenterXml::open('form', $formAttributes); // Begins table $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']); foreach (self::$targets as $category => $types) { $xmlOutput .= DataCenterXml::row(DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('category', $category))); foreach ($types as $type) { $name = $category . '_' . $type; $checkboxAttributes = array('type' => 'checkbox', 'name' => "meta[{$name}]", 'id' => "field_{$name}", 'value' => 1); $count = 0; if (isset($existsTable[$name])) { $checkboxAttributes['checked'] = 'checked'; $count = $existsTable[$name]->numValues(); if ($count > 0) { $checkboxAttributes['disabled'] = 'true'; $checkboxAttributes['name'] = "locked[{$name}]"; $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => "meta[{$name}]", 'value' => 1)); } } if (!DataCenterPage::userCan('change')) { $checkboxAttributes['disabled'] = 'true'; } $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(self::$defaultAttributes['checkbox'], DataCenterXml::tag('input', $checkboxAttributes)), DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterXml::tag('label', array('for' => "field_{$name}"), DataCenterUI::message('type', $type))), DataCenterXml::cell(self::$defaultAttributes['uses'], $count > 0 ? DataCenterUI::message('label', 'num-uses', $count) : '')); } } if (DataCenterPage::userCan('change')) { // Adds reset and submit button $xmlOutput .= DataCenterXML::row(DataCenterXml::cell(self::$defaultAttributes['buttons'], DataCenterXml::tag('input', array('type' => 'reset', 'name' => 'reset', 'class' => 'reset', 'value' => DataCenterUI::message('label', 'reset'))) . DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'submit', 'class' => 'submit', 'value' => DataCenterUI::message('label', 'save'))))); } $xmlOutput .= DataCenterXml::close('table'); // Adds row fields $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'row[id]', 'value' => $parameters['field']->getId())); // Adds do field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => 'saveFieldLinks')); // Adds token field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken())); // Adds success field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'success', 'value' => DataCenterXml::url($path))); // Adds failure field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'failure', 'value' => DataCenterXml::url($path))); // Adds canellation field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'cancellation', 'value' => DataCenterXml::url($path))); $xmlOutput .= DataCenterXml::close('form'); // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public static function export(array $data) { global $wgOut; // Disables MediaWiki output $wgOut->disable(); // Gets current path $path = DataCenterPage::getPath(); // Gets time in a nice format $date = date('Y-m-d'); $fileName = DataCenterUI::message('datacenter') . ' - ' . DataCenterUI::message('label', 'export-type', DataCenterUI::message('type', $data['meta']['type']) . ' ' . DataCenterUI::message('category', $data['meta']['category'])) . ' - ' . $date . '.' . $data['meta']['format']; // Sets headers for downloading CSV file header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"{$fileName}\""); $rows = DataCenterDB::getRows('DataCenterDBRow', $data['meta']['category'], $data['meta']['type']); $useMeta = $data['meta']['include-meta'] == 1 && ($data['meta']['category'] == 'facility' && DataCenterDB::isFacilityType($data['meta']['type']) || $data['meta']['category'] == 'asset' && DataCenterDB::isAssetType($data['meta']['type']) || $data['meta']['category'] == 'model' && DataCenterDB::isModelType($data['meta']['type'])); if ($data['meta']['format'] == 'csv') { $metaFieldsTable = null; $lines = array(); $fieldNames = ''; $first = true; foreach ($rows as $row) { $line = ''; $fields = $row->get(); foreach ($fields as $field => $value) { $line .= self::exportValue($value); } if ($first) { foreach ($fields as $field => $value) { $fieldNames .= self::exportValue(DataCenterUI::message('field', $field)); } } if ($useMeta) { $component = DataCenterDBComponent::newFromClass('DataCenterDBComponent', $data['meta']['category'], $data['meta']['type'], $fields); if (!$metaFieldsTable) { $metaFields = $component->getMetaFields(); $metaFieldsTable = array(); foreach ($metaFields as $metaField) { $metaFieldsTable[] = $metaField->get('field'); } if ($first) { foreach ($metaFields as $metaField) { $fieldNames .= self::exportValue($metaField->get('name')); } } } $metaValues = $component->getMetaValues(); $metaValuesTable = array(); foreach ($metaValues as $metaValue) { $metaValuesTable[$metaValue->get('field')] = $metaValue->get('value'); } foreach ($metaFieldsTable as $metaField) { if (isset($metaValuesTable[$metaField])) { $line .= self::exportValue($metaValuesTable[$metaField]); } else { $line .= ','; } } } $lines[] = rtrim($line, ',') . "\r\n"; $first = false; } echo rtrim($fieldNames, ',') . "\r\n"; echo implode($lines); } }
public function results($path) { return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'search-results')), DataCenterUI::renderWidget('searchresults', array('query' => $path['parameter'])))))); }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Begins select $xmlOutput .= DataCenterXml::open('select', array('name' => $parameters['name'], 'id' => $parameters['id'], 'class' => 'list')); // Checks if rows were given if ($parameters['rows']) { // Loops over each row foreach ($parameters['rows'] as $row) { // Builds attributes for option $optionAttributes = array('value' => $row->getId()); // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, implode($row->get($parameters['labels']), $parameters['glue'])); } // Alternatively check if options were given } elseif ($parameters['options']) { // Loops over each option foreach ($parameters['options'] as $key => $value) { // Checks if option key was not given if (is_int($key)) { // Uses key as value $optionAttributes = array('value' => $key); // Uses value as label $optionLabel = $value; } else { // Uses value as value $optionAttributes = array('value' => $value); // Uses key as label $optionLabel = $key; } // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, DataCenterUI::message('option', $optionLabel)); } // Alternatively check if an enum was given } elseif (isset($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field'])) { // Gets enum values from database $enum = DataCenterDB::getEnum($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field']); // Loops over each name foreach ($enum as $name) { // Uses name as value $optionAttributes = array('value' => $name); // Uses name as label $optionLabel = $name; // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= Xml::element('option', $optionAttributes, DataCenterUI::message('option', $optionLabel)); } } // Ends select $xmlOutput .= DataCenterXml::close('select'); // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
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']); if (isset($path['parameter']) && is_array($path['parameter']) && count($path['parameter']) >= 2) { $changes = array(DataCenterDB::getChange($path['parameter'][0]), DataCenterDB::getChange($path['parameter'][1])); if ($changes[0]->get('timestamp') > $changes[1]->get('timestamp')) { $changes = array_reverse($changes); } // Use blank user name if none is set foreach ($changes as $change) { if ($change->get('user') == 0) { $change->set('username', DataCenterUI::message('label', 'change-blank-user')); } } // Get states from serialized versions $states = array(unserialize($changes[0]->get('state')), unserialize($changes[1]->get('state'))); // Begins table $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']); // Restructures data $data = array(); foreach ($states as $i => $state) { foreach ($state as $group => $fields) { if (!isset($data[$group])) { $data[$group] = array(); } foreach ($fields as $field => $value) { if ($field !== 'id') { if (!isset($data[$group][$field])) { $data[$group][$field] = array(); } $data[$group][$field][$i] = $value; } } } } $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(), DataCenterXml::cell($changes[0]->get('username') . ' - ' . DataCenterUI::format($changes[0]->get('timestamp'), 'date')), DataCenterXml::cell($changes[1]->get('username') . ' - ' . DataCenterUI::format($changes[1]->get('timestamp'), 'date'))); // Loops over each field foreach ($data as $group => $fields) { if (count($fields) == 0) { continue; } $xmlOutput .= DataCenterXml::row(DataCenterXml::headingCell(array_merge(self::$defaultAttributes['heading'], array('colspan' => 3)), DataCenterUI::message('label', 'change-state-' . $group))); $even = true; foreach ($fields as $field => $values) { // Deals with incomplete data if (count($values) == 1) { if (!isset($values[0])) { $values[0] = null; } if (!isset($values[1])) { $values[1] = null; } } // Detects differnce $different = (string) $values[0] !== (string) $values[1]; $spanAttributes = array('class' => $different ? 'different' : 'same'); // Gets label name if ($group == 'row') { $label = DataCenterUI::message('field', strtr($field, '_', '-')); } elseif ($group == 'meta') { $metaField = DataCenterDB::getMetaField($field); $label = $metaField->get('name'); } $state = $even ? 'even' : 'odd'; // Adds row $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(array('class' => 'label'), $label), DataCenterXml::cell(array('class' => 'older-' . $state), DataCenterXml::span($spanAttributes, $values[0])), DataCenterXml::cell(array('class' => 'newer-' . $state), DataCenterXml::span($spanAttributes, $values[1]))); $even = !$even; } } // Ends table $xmlOutput .= DataCenterXml::close('table'); } else { // Gets history of component from database $changes = $parameters['component']->getChanges(array_merge_recursive(DataCenterDB::buildSort('meta', 'change', array('timestamp DESC')), DataCenterDB::buildRange($path))); // Gets number of changes fromd database $numChanges = $parameters['component']->numChanges(); // Use blank user name if none is set foreach ($changes as $change) { if ($change->get('user') == 0) { $change->set('username', DataCenterUI::message('label', 'change-blank-user')); } } // Builds form attributes $formAttributes = array('id' => 'form_history', 'name' => 'form_history', 'method' => 'post', 'action' => DataCenterXml::url($path)); // Begins form $xmlOutput .= DataCenterXml::open('form', $formAttributes); // Begins table $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']); // Adds paging $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(self::$defaultAttributes['paging'], parent::buildPaging($path, $numChanges))); // Adds headings $xmlOutput .= DataCenterXml::row(DataCenterXml::headingCell(), DataCenterXml::headingCell(), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'date')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'username')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'type')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'note'))); foreach ($changes as $i => $change) { // Build row attributes $rowAttributes = array('class' => $i % 2 == 0 ? 'odd' : 'even'); // Build radio attributes $radio1Attributes = array('type' => 'radio', 'name' => 'meta[change1]', 'id' => 'field_change1_' . $change->getId(), 'value' => $change->getId()); if ($i == 0) { $radio1Attributes['checked'] = 'checked'; } $radio2Attributes = array('type' => 'radio', 'name' => 'meta[change2]', 'id' => 'field_change2_' . $change->getId(), 'value' => $change->getId()); if ($i == 1 || count($changes) == 1) { $radio2Attributes['checked'] = 'checked'; } $xmlOutput .= DataCenterXml::row($rowAttributes, DataCenterXml::cell(self::$defaultAttributes['radio'], DataCenterXml::tag('input', $radio1Attributes)), DataCenterXml::cell(self::$defaultAttributes['radio'], DataCenterXml::tag('input', $radio2Attributes)), DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::format($change->get('timestamp'), 'date')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('username')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('type')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('note'))); } // Adds reset and submit button $xmlOutput .= DataCenterXML::row(DataCenterXml::cell(self::$defaultAttributes['buttons'], DataCenterXml::tag('input', array('type' => 'reset', 'name' => 'reset', 'class' => 'reset', 'value' => DataCenterUI::message('label', 'reset'))) . DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'submit', 'class' => 'submit', 'value' => DataCenterUI::message('label', 'compare-changes'))))); // Adds do field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => 'compareChanges')); // Adds token field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken())); $xmlOutput .= DataCenterXml::close('table'); $xmlOutput .= DataCenterXml::close('form'); } // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge_recursive(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); // Processes fields $fields = self::processFields($parameters['fields']); // Check if there was an error processing fields if (!$fields) { // Tells the user return DataCenterUI::message('error', 'no-fields'); } // Begins table $xmlOutput .= DataCenterXml::open('table', array('border' => 0, 'cellspacing' => 0)); // Gets current path $path = DataCenterPage::getPath(); // Check if number of possible records was given if (isset($parameters['num'])) { // Adds paging $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(array('colspan' => count($parameters['fields']), 'align' => 'right'), parent::buildPaging($path, $parameters['num']))); } // Adds headings foreach ($fields as $label => $options) { $xmlOutput .= DataCenterXml::headingCell(array('align' => $options['align']), DataCenterUI::message('field', $label)); } if (count($parameters['rows']) == 0) { $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(DataCenterUI::message('error', 'no-rows'))); } // Loops over each row foreach ($parameters['rows'] as $i => $row) { // Builds row attributes $rowAttributes = array_merge(array('class' => $i % 2 == 0 ? 'odd' : 'even'), DataCenterXml::buildEffects($parameters['effects'], $row), DataCenterXml::buildLink($parameters['link'], $row)); if (count($parameters['link']) > 0) { $rowAttributes['class'] .= ' link'; } // Begins row $xmlOutput .= DataCenterXml::open('tr', $rowAttributes); // Loops over each field foreach ($fields as $label => $options) { // Checks if multiple fields were specified if (count($options['fields']) > 0) { // Builds array of values $values = array(); foreach ($options['fields'] as $field => $fieldOptions) { $values[] = DataCenterUI::format($row->get($field), $fieldOptions['format']); } // Glues values together $value = implode($options['glue'], $values); // Alternatively checks if a field was specified } elseif ($options['field']) { // Uses specified field $value = DataCenterUI::format($row->get($options['field']), $options['format']); } else { // Uses label as field $value = DataCenterUI::format($row->get($label), $options['format']); } // Adds cell $xmlOutput .= DataCenterXml::cell(array('align' => $options['align']), $value); } // Ends row $xmlOutput .= DataCenterXml::close('tr'); } // Ends table $xmlOutput .= DataCenterXml::close('table'); // Clears any floating $xmlOutput .= DataCenterXml::clearFloating(); // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public function manage($path) { // Checks if... if (!$path['id'] && is_scalar($path['parameter'])) { // Creates new asset with default parameters $asset = DataCenterDBAsset::newFromType($path['type'], array('model' => $path['parameter'], 'tense' => 'present')); // Sets action specific parameters $formParameters = array('label' => 'deploy', 'hidden' => array('model'), 'success' => array('page' => 'assets', 'type' => $path['type']), 'type' => 'deploy'); $headingParameters = array('message' => 'deploying-asset-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets asset from database $asset = DataCenterDB::getAsset($path['type'], $path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'assets', 'type' => $path['type'], 'action' => 'view', 'id' => $path['id']), 'type' => 'manage'); $headingParameters = array('message' => 'managing-asset-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Gets model from database $model = $asset->getModel(); // Gets list of locations $locations = DataCenterDB::getLocations(); // Completes form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'assets', 'type' => $path['type']), 'row' => $asset, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'location' => array('type' => 'list', 'rows' => $locations, 'labels' => array('name', 'region'), 'glue' => ' / '), 'serial' => array('type' => 'string'), 'asset' => array('type' => 'string')))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'model-type', 'type' => $path['type'])), DataCenterUI::renderWidget('details', array_merge(self::$options[$path['type']]['details'], array('row' => $model))))))); }