Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Gets structure of links
  */
 public function getStructure(array $options = array())
 {
     if (!$this->structure) {
         $links = DataCenterDB::getRows('DataCenterDBAssetLink', 'link', 'asset', array_merge_recursive($options, DataCenterDB::buildCondition('link', 'asset', 'plan', $this->getId())));
         $this->structure = array();
         foreach ($links as $link) {
             if ($link->get('parent_link') == null) {
                 $link->buildStructure($links);
                 $this->structure[] = $link;
             }
         }
     }
     return $this->structure;
 }