示例#1
0
 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_export', 'name' => 'form_export', 'method' => 'post', 'action' => DataCenterXml::url($path));
     // Begins form
     $xmlOutput .= DataCenterXml::open('form', $formAttributes);
     // Begins table
     $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']);
     // Adds ...
     $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', 'format')), DataCenterXml::cell(self::$defaultAttributes['input'], DataCenterUI::renderInput('list', array('name' => 'meta[format]', 'options' => array('csv' => 'csv')))));
     $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', 'include-meta')), DataCenterXml::cell(self::$defaultAttributes['input'], DataCenterUI::renderInput('boolean', array('name' => 'meta[include-meta]', 'value' => true))));
     if (DataCenterPage::userCan('export')) {
         // 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', 'export')))));
     }
     $xmlOutput .= DataCenterXml::close('table');
     // Adds category field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'meta[category]', 'value' => $parameters['category']));
     // Adds type field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'meta[type]', 'value' => $parameters['type']));
     // Adds do field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => 'export'));
     // 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;
 }
示例#2
0
 public static function render(array $parameters)
 {
     global $wgUser;
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins widget
     $xmlOutput = parent::begin($parameters['class']);
     // Builds form attributes
     $formAttributes = array('id' => 'form_' . $parameters['do'], 'name' => 'form_' . $parameters['do'], 'method' => 'post', 'action' => DataCenterXml::url($parameters['action']), 'onsubmit' => DataCenterJs::buildEffect($parameters['effect'], $parameters['row']->get()));
     // Begins form
     $xmlOutput .= DataCenterXml::open('form', $formAttributes);
     // Inserts content before fields
     $xmlOutput .= $parameters['insert'];
     // Begins table
     $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']);
     // Creates array to keep track of the number of each type for auto-naming
     $count = array();
     // Loops over each field
     foreach ($parameters['fields'] as $label => $options) {
         // Begins row
         $xmlOutput .= DataCenterXml::open('tr', self::$defaultAttributes['row']);
         // Checks if the key is a numeric index
         if (is_int($label)) {
             // Adds an empty cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['empty']);
         } else {
             // Adds a label cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', $label));
         }
         // Checks if field is not an array
         if (!is_array($options)) {
             // Uses value as the input type
             $options = array();
         }
         // Checks if no type was set
         if (!isset($options['type'])) {
             // Uses "text" as the default
             $options['type'] = 'text';
         }
         // Verifies the input type is available
         if (DataCenterUI::isInput($options['type'])) {
             // Copies field for use as options for input
             $inputOptions = $options;
             // Removes type from attributes since the input doesn't need it
             unset($inputOptions['type']);
             // Check no field or fields were set
             if (!isset($inputOptions['fields']) && !isset($inputOptions['field'])) {
                 // Uses key as field
                 $inputOptions['field'] = $label;
             }
             // Checks if this is an un-named field
             if (is_int($label)) {
                 // Checks if there has been this type before
                 if (isset($count[$options['type']])) {
                     // Incriments type count
                     $count[$options['type']]++;
                 } else {
                     // Starts counting fields of this type
                     $count[$options['type']] = 0;
                 }
                 // Sets ID from type and count
                 $inputOptions['id'] = "field_{$options['type']}_{$count[$options['type']]}";
                 // Sets name of input for form processing
                 $inputOptions['name'] = "row[{$inputOptions['field']}]";
             } else {
                 // Checks if a specific field was given
                 if (isset($inputOptions['field'])) {
                     // Checks if no value was set
                     if (!isset($inputOptions['value'])) {
                         // Sets value of input from row
                         $inputOptions['value'] = $parameters['row']->get($inputOptions['field']);
                     }
                     // Sets ID from name
                     $inputOptions['id'] = "field_{$inputOptions['field']}";
                     // Sets name of input for form processing
                     $inputOptions['name'] = "row[{$inputOptions['field']}]";
                     // Alternatively checks if a list of fields were given
                 } elseif (isset($inputOptions['fields'])) {
                     // Loops over each sub-field
                     foreach ($inputOptions['fields'] as $key => $field) {
                         // Checks if sub-field is an array
                         if (is_array($inputOptions['fields'][$key])) {
                             // Uses sub-field's specific field name
                             $fieldName = $inputOptions['fields'][$key]['field'];
                         } else {
                             // Uses simple value as field name
                             $fieldName = $field;
                             // Creates arrray for sub-field options
                             $inputOptions['fields'][$key] = array();
                         }
                         // Checks if...
                         if (!isset($inputOptions['fields'][$key]['value'])) {
                             // Set the value of the field from the row
                             $inputOptions['fields'][$key]['value'] = $parameters['row']->get($fieldName);
                         }
                         // Set the ID of the field
                         $inputOptions['fields'][$key]['id'] = "field_{$fieldName}";
                         // Sets the name of the field
                         $inputOptions['fields'][$key]['name'] = "row[{$fieldName}]";
                     }
                 }
             }
             // Renders input
             $widget = DataCenterUI::renderInput($options['type'], $inputOptions);
         } else {
             // Alerts the user that the input did not exist
             $widget = DataCenterUI::message('error', 'no-ui-widget', $label);
         }
         // Adds input cell
         $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['field'], $widget);
         // Ends field row
         $xmlOutput .= DataCenterXml::close('tr');
     }
     // Checks if row is a component
     if ($parameters['meta'] && $parameters['row'] instanceof DataCenterDBComponent) {
         // Adds meta fields
         $metaFields = $parameters['row']->getMetaFields();
         $metaValues = $parameters['row']->getMetaValues();
         $valuesTable = DataCenterDB::buildLookupTable('field', $metaValues);
         foreach ($metaFields as $metaField) {
             $field = $metaField->get('field');
             $value = '';
             if (isset($valuesTable[$field][0]) && $valuesTable[$field][0] instanceof DataCenterDBMetaValue) {
                 $value = $valuesTable[$field][0]->get('value');
             }
             // Begins row
             $xmlOutput .= DataCenterXml::open('tr', self::$defaultAttributes['meta']);
             // Adds label cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['label'], $metaField->get('name'));
             // Adds input cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::renderInput($metaField->get('format'), array('name' => 'meta[' . $field . ']', 'id' => 'meta_' . $field, 'value' => $value)));
             // Ends field row
             $xmlOutput .= DataCenterXml::close('tr');
         }
         // Adds change comment field
         $xmlOutput .= DataCenterXml::row(self::$defaultAttributes['change'], DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', 'change-summary')), DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::renderInput('string', array('name' => 'change[note]', 'id' => 'change_note'))));
         // Adds type of edit field
         $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'change[type]', 'value' => $parameters['type']));
     }
     // Adds cancel and submit button
     $xmlOutput .= DataCenterXML::row(DataCenterXml::cell(self::$defaultAttributes['buttons'], DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'cancel', 'class' => 'cancel', 'value' => DataCenterUI::message('label', 'cancel'))) . DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'submit', 'class' => 'submit', 'value' => DataCenterUI::message('label', $parameters['label'])))));
     // Ends table
     $xmlOutput .= DataCenterXml::close('table');
     // Adds do field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => $parameters['do']));
     // 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($parameters['success'])));
     // Adds failure field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'failure', 'value' => DataCenterXml::url($parameters['failure'])));
     // Adds canellation field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'cancellation', 'value' => DataCenterXml::url(count($parameters['cancellation']) > 0 ? $parameters['cancellation'] : $parameters['success'])));
     // Loops over hidden fields
     foreach ($parameters['hidden'] as $key => $value) {
         // Checks if key is numeric
         if (is_int($key)) {
             // Adds field with value from row
             $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => "row[{$value}]", 'value' => $parameters['row']->get($value)));
         } else {
             // Adds field with specified value
             $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => "row[{$key}]", 'value' => $value));
         }
     }
     // Appends content after fields
     $xmlOutput .= $parameters['append'];
     // Ends form
     $xmlOutput .= DataCenterXml::close('form');
     // Ends widget
     $xmlOutput .= DataCenterXml::close('div');
     // Returns the results
     return $xmlOutput;
 }