Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ abstract class Base<?php echo ucfirst($this->getModuleName()) ?>GeneratorConfigu

<?php include dirname(__FILE__).'/fieldsConfiguration.php' ?>

<?php include dirname(__FILE__).'/slotActionsConfiguration.php' ?>
<?php if (isset($this->config['exportation']['enabled']) && $this->config['exportation']['enabled']): ?>
<?php include dirname(__FILE__).'/exporterConfiguration.php' ?>
<?php include dirname(__FILE__).'/exporterPaginationConfiguration.php' ?>
<?php else: ?>
<?php unset($this->config['exportation']) ?>
<?php endif ?>

public function isExportationEnabled()
{ $plugins = sfContext::getInstance()->getConfiguration()->getPlugins();

return <?php echo (isset($this->config['exportation']['enabled']) && $this->config['exportation']['enabled']? 'true' : 'false') ?> && in_array('sfPhpExcelPlugin',$plugins);
<?php unset($this->config['exportation']['enabled']) ?>
}

<?php include dirname(__FILE__).'/slotActionsConfiguration.php' ?>
/**
* Gets the form class name.
*
Expand Down Expand Up @@ -85,4 +98,17 @@ public function getCondition($action)

return $condition;
}

public function getPeerMethod()
{
return '<?php echo isset($this->config['list']['peer_method']) ? $this->config['list']['peer_method'] : 'doSelect' ?>';
<?php unset($this->config['list']['peer_method']) ?>
}

public function getPeerCountMethod()
{
return '<?php echo isset($this->config['list']['peer_count_method']) ? $this->config['list']['peer_count_method'] : 'doCount' ?>';
<?php unset($this->config['list']['peer_count_method']) ?>
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
public function executeDoExportation(sfWebRequest $request)
{
$this->pageNumber = $request->getParameter('page');

if (empty($this->pageNumber))
{
$this->getUser()->setFlash('error', 'There was an error while trying to export the desired page.');
$this->redirect('@<?php echo $this->getModuleName()?>');
}
else
{
$this->exportationPager = $this->getExportationPager($this->configuration->getExportationType(), $this->pageNumber);

$helperKlass = $this->configuration->getExportationHelperClass();
$exporterType = $this->configuration->getExportationType();
$this->exportationHelper = new $helperKlass($this->configuration, $this->getExportationResults($this->exportationPager), array('type' => $exporterType, 'context' => $this->getContext(), 'title' => $this->configuration->getExportationTitle(), 'headers' => $this->configuration->getExportationHeaders()));

$this->exportationHelper->build();
$this->exportationHelper->saveFile($this->configuration->getExportationSavePath().time().rand(1,1000).'.'.$this->configuration->getExportationFileExtension());
$this->exportationHelper->freeMem();
$this->content = $this->exportationHelper->getFileContents();
$this->exportationHelper->deleteFile();
$this->prepareResponseForExportation($this->configuration->getExportationFileExtension());

return $this->renderText($this->content);
}
}

public function executeDoExportationPages(sfWebRequest $request)
{
$this->exportationPager = $this->getExportationPager($this->configuration->getExportationType());
return $this->renderPartial('<?php echo $this->getModuleName() ?>/exportation_pages', array('pager' => $this->exportationPager, 'exportUrl' => 'doExportation'));
}

public function executeNewUserExportation(sfWebRequest $request)
{
$this->form = $this->configuration->getExportationForm(array(), array('pager' => $this->getExportationPager(), 'configuration' => $this->configuration));
}

public function executeCreateUserExportation(sfWebRequest $request)
{
$this->pager = $this->getExportationPager();
$this->form = $this->configuration->getExportationForm(array(), array('pager' => $this->pager, 'configuration' => $this->configuration));

$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
if ($this->form->isValid())
{
$values = $this->form->getValues();
if ( $this->form->isCSRFProtected() )
{
$values = array_merge($values,array($this->form->getCSRFFieldName() => $this->form->getCSRFToken() ));
}
$this->getUser()->setAttribute('<?php echo $this->getModuleName() ?>.exportation_form_values', $values);
$this->setTemplate('createUserExportation');
}
else
{
$this->setTemplate('newUserExportation');
}
}

public function getExportationFileExtension($form)
{
return $this->configuration->getExportationFileExtension($form->getExportationType());
}

public function executeProcessUserExportation(sfWebRequest $request)
{
$this->pageNumber = $request->getParameter('page');
$this->exportationFormValues = $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.exportation_form_values', array());

if (!empty($this->pageNumber) && !empty($this->exportationFormValues))
{
$this->form = $this->configuration->getExportationForm(array(), array('pager' => $this->getExportationPager(null, $this->pageNumber), 'configuration' => $this->configuration));
$this->form->bind($this->exportationFormValues);
if ($this->form->isValid())
{
$helperKlass = $this->configuration->getExportationHelperUserClass();
$exporterType = $this->form->getExportationType();

$this->exportationPager = $this->form->getExportationPager();

$this->exportationHelper = new $helperKlass($this->configuration, $this->form->getExportationResults(), array('type' => $this->form->getExportationType(), 'context' => $this->getContext(), 'title' => $this->configuration->getExportationTitle(), 'headers' => $this->configuration->getExportationHeaders()), $this->form);

$this->exportationHelper->build();
$this->exportationHelper->saveFile($this->configuration->getExportationSavePath().time().rand(1,1000).'.'.$this->getExportationFileExtension($this->form));
$this->exportationHelper->freeMem();
$this->content = $this->exportationHelper->getFileContents();
$this->exportationHelper->deleteFile();
$this->prepareResponseForExportation($this->getExportationFileExtension($this->form));

return $this->renderText($this->content);
}
else
{
$this->getUser()->setFlash('error', 'There was an error while trying to export the desired page.');
$this->redirect('@<?php echo $this->getModuleName()?>');
}
}
else
{
$this->getUser()->setFlash('error', 'There was an error while trying to export the desired page.');
$this->redirect('@<?php echo $this->getModuleName()?>');
}
}

public function getExportationResults($pager)
{
return $pager->getResults();
}

public function prepareResponseForExportation($extension)
{
sfConfig::set('sf_web_debug', false);
$this->setLayout(false);

$mimeType = $this->configuration->getExportationMimeType($extension);
$this->getResponse()->setHttpHeader('Content-type', "$mimeType; charset=UTF-8");
$this->getResponse()->setHttpHeader('Content-Disposition', ' attachment; filename="'.$this->configuration->getExportationFileName($extension).'"');
$this->getResponse()->setHttpHeader('Cache-Control', ' maxage=3600');
$this->getResponse()->setHttpHeader('Pragma', 'public');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

public function getExportationHelperClass()
{
return '<?php echo isset($this->config['exportation']['helperClass'])? $this->config['exportation']['helperClass'] : $this->getModuleName()."ExporterHelper" ?>';
}
<?php unset($this->config['exportation']['helperClass']) ?>

public function getExportationAjaxIndicatorPath()
{
return '<?php echo isset($this->config['exportation']['ajaxIndicatorPath'])? $this->config['exportation']['ajaxIndicatorPath'] : '/acPropelExtendedGeneratorPlugin/images/ajax-loader.gif' ?>';
}
<?php unset($this->config['exportation']['ajaxIndicatorPath']) ?>

public function getExportationHelperUserClass()
{
return '<?php echo isset($this->config['exportation']['helperUserClass'])? $this->config['exportation']['helperUserClass'] : $this->getModuleName()."ExporterHelperUser" ?>';
}
<?php unset($this->config['exportation']['helperUserClass']) ?>

public function getExportationForm($defaults = array(), $options = array())
{
$formClass = '<?php echo isset($this->config['exportation']['userExportationForm'])? $this->config['exportation']['userExportationForm'] : $this->getModuleName().'ExporterForm' ?>';
return new $formClass(array(), array_merge(array('fields' => $this->getExportationFieldSelectionDecorators(), 'title' => $this->getExportationTitle(), 'type' => $this->getExportationType(), 'allowUserTypeSelection' => $this->getExportationAllowUserTypeSelection()), $options));
}

public function getExportationAllowUserTypeSelection()
{
return <?php echo (isset($this->config['exportation']['allowUserTypeSelection']) && $this->config['exportation']['allowUserTypeSelection'])? 'true' : 'false' ?>;
}
<?php unset($this->config['exportation']['allowUserTypeSelection']) ?>

public function getExportationFieldSelection()
{
return <?php echo $this->asPhp(isset($this->config['exportation']['fieldSelection'])? $this->config['exportation']['fieldSelection'] : array(array('label' => 'Object', 'decorator' => 'pass'))) ?>;
}
<?php unset($this->config['exportation']['fieldSelection']) ?>

public function getExportationFieldSelectionDecorators()
{
$fields = array();
foreach ($this->getExportationFieldSelection() as $id => $f)
{
$fields[$id] = gmExporterFieldDecorator::getInstance($f);
}
return $fields;
}
<?php unset($this->config['exportation']['fieldSelection']) ?>

public function getExportationHeaders()
{
$headers = array();
foreach ($this->getExportationFieldSelection() as $f)
{
$f = gmExporterFieldDecorator::getInstance($f);
$headers[] = $f->getLabel();
}
return $headers;
}

public function getExportationTitle()
{
return "<?php echo isset($this->config['exportation']['title'])? $this->config['exportation']['title'] : 'Report' ?>";
}
<?php unset($this->config['exportation']['title']) ?>

public function getExportationDefaultType()
{
return gmExporterTypes::EXPORT_TYPE_XLS;
}

public function getExportationType()
{
<?php if (isset($this->config['exportation']['type'])): ?>
return "<?php echo $this->config['exportation']['type'] ?>";
<?php else: ?>
return $this->getExportationDefaultType();
<?php endif ?>
}
<?php unset($this->config['exportation']['type']) ?>

public function getExportationSavePath()
{
return "/tmp/";
}

public function getExportationFileExtension($type = null)
{
$type = is_null($type)? $this->getExportationType() : $type;
return gmExporterTypes::getFileExtension($type);
}

public function getExportationFileName($extension = null)
{
$extension = is_null($extension)? $this->getExportationFileExtension() : $extension;
return 'report.'.$extension;
}

public function getExportationMimeType($type = null)
{
$type = is_null($type)? $this->getExportationType() : $type;
return gmExporterTypes::getMimeType($type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
protected function getExportationPager($type = null, $page = null)
{
$pager = $this->configuration->getExportationPager('<?php echo $this->getModelClass() ?>', $type);
$pager->setCriteria($this->buildExportationCriteria());
$pager->setPage($this->getExportationPage());
$pager->setPeerMethod($this->configuration->getPeerMethod());
$pager->setPeerCountMethod($this->configuration->getPeerCountMethod());

if (!is_null($page)) $pager->setPage($page);
$pager->init();

return $pager;
}

protected function setExportationPage($page)
{
$this->getUser()->setAttribute('<?php echo $this->getModuleName() ?>.exportation_page', $page, 'admin_module');
}

protected function getExportationPage()
{
return $this->getUser()->getAttribute('<?php echo $this->getModuleName() ?>.exportation_page', 1, 'admin_module');
}

protected function buildExportationCriteria()
{
return $this->buildQuery();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public function getExportationPager($model = null, $type = null)
{
$class = $this->getExportationPagerClass();

return new $class($model, $this->getExportationPagerMaxPerPage($type));
}

public function getExportationPagerClass()
{
return '<?php echo isset($this->config['exportation']['pager_class']) ? $this->config['exportation']['pager_class'] : 'sfPropelPager' ?>';
<?php unset($this->config['exportation']['pager_class']) ?>
}

public function getExportationPagerMaxPerPage($type = 'default')
{
<?php if (isset($this->config['exportation']['max_per_page']) && is_numeric($this->config['exportation']['max_per_page'])): ?>
$maxPerPageOpts = array('default' => <?php echo $this->config['exportation']['max_per_page'] ?>);
<?php elseif (isset($this->config['exportation']['max_per_page']) && is_array($this->config['exportation']['max_per_page'])): ?>
$maxPerPageOpts = <?php echo $this->asPhp(array_merge(array('default' => 1000), $this->config['exportation']['max_per_page'])) ?>;
<?php else: ?>
$maxPerPageOpts = array('default' => 1000);
<?php endif ?>

return isset($maxPerPageOpts[$type])? $maxPerPageOpts[$type] : $maxPerPageOpts['default'];
<?php unset($this->config['exportation']['max_per_page']) ?>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* ##MODULE_NAME## exporter csv.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: exporterCsv.php 12474 2008-10-31 10:41:27Z mtorres $
*/
class ##MODULE_NAME##ExporterCsv extends Base##UC_MODULE_NAME##ExporterCsv
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* ##MODULE_NAME## exporter form.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: exporterForm.php 12474 2008-10-31 10:41:27Z mtorres $
*/
class ##MODULE_NAME##ExporterForm extends Base##UC_MODULE_NAME##ExporterForm
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* ##MODULE_NAME## exporter helper.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: exporterHelper.php 12474 2008-10-31 10:41:27Z fabien $
*/
class ##MODULE_NAME##ExporterHelper extends Base##UC_MODULE_NAME##ExporterHelper
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* ##MODULE_NAME## exporter helper user.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: exporterHelperUser.php 12474 2008-10-31 10:41:27Z fabien $
*/
class ##MODULE_NAME##ExporterHelperUser extends Base##UC_MODULE_NAME##ExporterHelperUser
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* ##MODULE_NAME## exporter xls.
*
* @package ##PROJECT_NAME##
* @subpackage ##MODULE_NAME##
* @author ##AUTHOR_NAME##
* @version SVN: $Id: exporterXls.php 12474 2008-10-31 10:41:27Z fabien $
*/
class ##MODULE_NAME##ExporterXls extends Base##UC_MODULE_NAME##ExporterXls
{
}
Loading