Skip to content

Instantly share code, notes, and snippets.

@jraddaoui
Created December 10, 2012 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jraddaoui/4252713 to your computer and use it in GitHub Desktop.
Save jraddaoui/4252713 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
{
private $data = "";
public function execute($request)
{
$this->resource = $this->getRoute()->resource;
if (!isset($this->resource))
{
$this->forward404();
}
// Disable layout
$this->setLayout(false);
// All linked physical storage objects for current description and all descendants, containing the listed fields (Reference code, Container name, Title, Creation Dates). A good example to iterate over an inforamtion objects and its ancestors is apps/qubit/modules/digitalobject/actions/imageflowComponent.class.php
global $data;
global $creation_date;
$event = $this->resource->getDates(array('type_id','Creation'));
$creation_date = $event[0]->startDate;
$data .= $creation_date;
foreach ($this->resource->getPhysicalObjects() as $item)
{
$data .= $this->resource->__get("referenceCode").",".$item->__toString().",".$this->resource->__toString().",".$creation_date."\n";
}
$this->writeChildrens($this->resource);
// Radda, we may need this but I am not sure
// http://www.symfony-project.org/api/1_4/sfWebResponse#method_clearhttpheaders
$this->getResponse()->clearHttpHeaders();
$this->getResponse()->setHttpHeader('Content-Disposition', "attachment; filename=report.txt");
// Put the $data contents into the body part of the HTTP response
$this->getResponse()->setContent($data);
return sfView::NONE;
}
private function writeChildrens($informationobject)
{
global $data;
foreach ($informationobject->getChildren() as $children)
{
foreach ($children->getPhysicalObjects() as $physicalobjet)
{
$data .= $children->__get("referenceCode").",".$physicalobjet->__toString().",".$children->__toString().","."\n";
}
$this->writeChildrens($children);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment