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;
 }
示例#2
0
 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));
 }
示例#3
0
 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;
 }
 /**
  * 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');
 }