Skip to content

Instantly share code, notes, and snippets.

@sevein
Forked from jraddaoui/boxLabel
Created December 10, 2012 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevein/4252770 to your computer and use it in GitHub Desktop.
Save sevein/4252770 to your computer and use it in GitHub Desktop.
<?php
/*
* This file is part of the AccesstoMemory (AtoM) software.
*
* AccesstoMemory (AtoM) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AccesstoMemory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AccesstoMemory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/
class InformationObjectBoxLabelCsvAction extends sfAction
{
public function execute($request)
{
$this->resource = $this->getRoute()->resource;
if (!isset($this->resource))
{
$this->forward404();
}
foreach ($this->resource->descendants->andSelf()->orderBy('rgt') as $informationObject)
{
$event = $this->resource->getDates(array('type_id','Creation'));
$creation_date = $event[0]->startDate;
// Reference code, container name, title, creation date
foreach ($informationObject->getPhysicalObjects() as $item)
{
$data .= sprintf("%s,%s,%s,%s\n",
$informationObject->referenceCode,
$item->__toString(),
$informationObject->__toString(),
$creation_date);
}
}
// Disable layout
$this->setLayout(false);
// Do we need this?
// http://www.symfony-project.org/api/1_4/sfWebResponse#method_clearhttpheaders
// $this->getResponse()->clearHttpHeaders();
// Set the file name
$this->getResponse()->setHttpHeader('Content-Disposition', "attachment; filename=report.csv");
// Send $data as the response body
$this->getResponse()->setContent($data);
return sfView::NONE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment