[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/maniphest/export/ -> ManiphestExcelDefaultFormat.php (source)

   1  <?php
   2  
   3  final class ManiphestExcelDefaultFormat extends ManiphestExcelFormat {
   4  
   5    public function getName() {
   6      return pht('Default');
   7    }
   8  
   9    public function getFileName() {
  10      return 'maniphest_tasks_'.date('Ymd');
  11    }
  12  
  13    /**
  14     * @phutil-external-symbol class PHPExcel
  15     * @phutil-external-symbol class PHPExcel_IOFactory
  16     * @phutil-external-symbol class PHPExcel_Style_NumberFormat
  17     * @phutil-external-symbol class PHPExcel_Cell_DataType
  18     */
  19    public function buildWorkbook(
  20      PHPExcel $workbook,
  21      array $tasks,
  22      array $handles,
  23      PhabricatorUser $user) {
  24  
  25      $sheet = $workbook->setActiveSheetIndex(0);
  26      $sheet->setTitle(pht('Tasks'));
  27  
  28      $widths = array(
  29        null,
  30        15,
  31        null,
  32        10,
  33        15,
  34        15,
  35        60,
  36        30,
  37        20,
  38        100,
  39      );
  40  
  41      foreach ($widths as $col => $width) {
  42        if ($width !== null) {
  43          $sheet->getColumnDimension($this->col($col))->setWidth($width);
  44        }
  45      }
  46  
  47      $status_map = ManiphestTaskStatus::getTaskStatusMap();
  48      $pri_map = ManiphestTaskPriority::getTaskPriorityMap();
  49  
  50      $date_format = null;
  51  
  52      $rows = array();
  53      $rows[] = array(
  54        pht('ID'),
  55        pht('Owner'),
  56        pht('Status'),
  57        pht('Priority'),
  58        pht('Date Created'),
  59        pht('Date Updated'),
  60        pht('Title'),
  61        pht('Projects'),
  62        pht('URI'),
  63        pht('Description'),
  64      );
  65  
  66      $is_date = array(
  67        false,
  68        false,
  69        false,
  70        false,
  71        true,
  72        true,
  73        false,
  74        false,
  75        false,
  76        false,
  77      );
  78  
  79      $header_format = array(
  80        'font'  => array(
  81          'bold' => true,
  82        ),
  83      );
  84  
  85      foreach ($tasks as $task) {
  86        $task_owner = null;
  87        if ($task->getOwnerPHID()) {
  88          $task_owner = $handles[$task->getOwnerPHID()]->getName();
  89        }
  90  
  91        $projects = array();
  92        foreach ($task->getProjectPHIDs() as $phid) {
  93          $projects[] = $handles[$phid]->getName();
  94        }
  95        $projects = implode(', ', $projects);
  96  
  97        $rows[] = array(
  98          'T'.$task->getID(),
  99          $task_owner,
 100          idx($status_map, $task->getStatus(), '?'),
 101          idx($pri_map, $task->getPriority(), '?'),
 102          $this->computeExcelDate($task->getDateCreated()),
 103          $this->computeExcelDate($task->getDateModified()),
 104          $task->getTitle(),
 105          $projects,
 106          PhabricatorEnv::getProductionURI('/T'.$task->getID()),
 107          id(new PhutilUTF8StringTruncator())
 108          ->setMaximumBytes(512)
 109          ->truncateString($task->getDescription()),
 110        );
 111      }
 112  
 113      foreach ($rows as $row => $cols) {
 114        foreach ($cols as $col => $spec) {
 115          $cell_name = $this->col($col).($row + 1);
 116          $cell = $sheet
 117            ->setCellValue($cell_name, $spec, $return_cell = true);
 118  
 119          if ($row == 0) {
 120            $sheet->getStyle($cell_name)->applyFromArray($header_format);
 121          }
 122  
 123          if ($is_date[$col]) {
 124            $code = PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2;
 125            $sheet
 126              ->getStyle($cell_name)
 127              ->getNumberFormat()
 128              ->setFormatCode($code);
 129          } else {
 130            $cell->setDataType(PHPExcel_Cell_DataType::TYPE_STRING);
 131          }
 132        }
 133      }
 134    }
 135  
 136    private function col($n) {
 137      return chr(ord('A') + $n);
 138    }
 139  
 140  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1