예제 #1
0
 public function executeExport($request)
 {
     if ($request->isMethod('POST')) {
         $exportManager = sfExportManager::create('Resource');
         $sheets = array('stuff' => array('have', 'need'), 'info' => array('have', 'need'), 'time' => array('need'));
         foreach ($sheets as $prefix => $types) {
             $class = sfInflector::camelize($prefix . 'Resource');
             $fields = Doctrine::getTable($class)->getColumnNames();
             $fields = array_combine($fields, $fields);
             foreach ($fields as $key => $value) {
                 $fields[$key] = sfInflector::humanize($value);
             }
             foreach ($types as $type) {
                 $results = Doctrine::getTable($class)->createQuery()->where('transaction_type = ?', $type)->execute();
                 $exportManager->exportCollectionSheet($results, $fields, sprintf('%s %s', $type, $prefix));
             }
         }
         $title = $request->getParameter('title', 'Donate_Nashville_Export');
         $title = $request->getParameter('include_timestamp') ? $title . '-' . date('Y-m-d H:i') : $title;
         $exportManager->output($title);
         return sfView::NONE;
     }
 }
예제 #2
0
  public function executeExport(sfWebRequest $request)
  { 
    // sorting
    if ($request->getParameter('sort'))
    {
      $this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_direction')));
    }

    $this->pager = $this->getPager();
     
    if ($request->isMethod('post')) 
    { 
      $manager = new sfExportManager($this->getResponse());
      
      $fields = array_intersect_key($request->getParameter('export'), $request->getParameter('include'));
      
      if(false === $manager->export($this->pager->getQuery()->limit(9999999)->execute(), $fields, 'dsPersonExport'))
      {
        // There was an error when generating the download.  Redirect to the referer and set the error in a flash message
        $this->redirectReferer($manager->getErrorMessage());
      }

      if($route = $manager->getDownloadRoute())
      {
        $this->redirect($route);
      }
      
      return sfView::NONE;
    }
  }
$company2['name'] = 'Company Name 2';
$company2['city'] = 'City 2';
$company2['state'] = 'State 2';
$company2->save();

$companies = Doctrine::getTable('Company')
  ->createQuery()
  ->whereIn('id', array($company1['id'], $company2['id']))
  ->execute();

$manager = new sfExportManager();
$csvArray = $manager->doExport($companies, array('name'));

$t->is(count($csvArray), 3, 'Three rows (including "headers")');
$t->is(count($csvArray[0]), 1, 'One Column: "name"');
$t->is($csvArray[1], $company1['name'], 'First row is Company 1');
$t->is($csvArray[2], $company2['name'], 'Second row is Company 2');

$manager = new sfExportManager();
$csvArray = $manager->doExport($companies, array('name', 'city' => 'Company City', 'state'));

$t->is(count($csvArray), 3, 'Three rows (including "headers")');
$headers = explode(',', $csvArray[0]);

$t->is(count($headers), 3, 'Three Column: "name", "city", "state"');
$t->is($headers[1], 'Company City', 'Label for "city" is "Company City"');

$row1 = explode(',', $csvArray[1]);
$row2 = explode(',', $csvArray[2]);
$t->is($row1[1], $company1['city'], 'First row second column is is Company 1 city');
$t->is($row2[1], $company2['city'], 'Second row second column is is Company 2 city');