diff --git a/data/generator/sfPropelModule/revisitedAdmin15/parts/configuration.php b/data/generator/sfPropelModule/revisitedAdmin15/parts/configuration.php index 70e5323..9e3783f 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/parts/configuration.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/parts/configuration.php @@ -14,8 +14,21 @@ abstract class BasegetModuleName()) ?>GeneratorConfigu - +config['exportation']['enabled']) && $this->config['exportation']['enabled']): ?> + + + + config['exportation']) ?> + + + public function isExportationEnabled() + { $plugins = sfContext::getInstance()->getConfiguration()->getPlugins(); + + return config['exportation']['enabled']) && $this->config['exportation']['enabled']? 'true' : 'false') ?> && in_array('sfPhpExcelPlugin',$plugins); +config['exportation']['enabled']) ?> + } + /** * Gets the form class name. * @@ -85,4 +98,17 @@ public function getCondition($action) return $condition; } + + public function getPeerMethod() + { + return 'config['list']['peer_method']) ? $this->config['list']['peer_method'] : 'doSelect' ?>'; +config['list']['peer_method']) ?> + } + + public function getPeerCountMethod() + { + return 'config['list']['peer_count_method']) ? $this->config['list']['peer_count_method'] : 'doCount' ?>'; +config['list']['peer_count_method']) ?> + } + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterAction.php b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterAction.php new file mode 100644 index 0000000..7df8343 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterAction.php @@ -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('@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('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('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('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('@getModuleName()?>'); + } + } + else + { + $this->getUser()->setFlash('error', 'There was an error while trying to export the desired page.'); + $this->redirect('@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'); + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterConfiguration.php b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterConfiguration.php new file mode 100644 index 0000000..e15ab0e --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterConfiguration.php @@ -0,0 +1,102 @@ + + public function getExportationHelperClass() + { + return 'config['exportation']['helperClass'])? $this->config['exportation']['helperClass'] : $this->getModuleName()."ExporterHelper" ?>'; + } +config['exportation']['helperClass']) ?> + + public function getExportationAjaxIndicatorPath() + { + return 'config['exportation']['ajaxIndicatorPath'])? $this->config['exportation']['ajaxIndicatorPath'] : '/acPropelExtendedGeneratorPlugin/images/ajax-loader.gif' ?>'; + } +config['exportation']['ajaxIndicatorPath']) ?> + + public function getExportationHelperUserClass() + { + return 'config['exportation']['helperUserClass'])? $this->config['exportation']['helperUserClass'] : $this->getModuleName()."ExporterHelperUser" ?>'; + } +config['exportation']['helperUserClass']) ?> + + public function getExportationForm($defaults = array(), $options = array()) + { + $formClass = '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 config['exportation']['allowUserTypeSelection']) && $this->config['exportation']['allowUserTypeSelection'])? 'true' : 'false' ?>; + } +config['exportation']['allowUserTypeSelection']) ?> + + public function getExportationFieldSelection() + { + return asPhp(isset($this->config['exportation']['fieldSelection'])? $this->config['exportation']['fieldSelection'] : array(array('label' => 'Object', 'decorator' => 'pass'))) ?>; + } +config['exportation']['fieldSelection']) ?> + + public function getExportationFieldSelectionDecorators() + { + $fields = array(); + foreach ($this->getExportationFieldSelection() as $id => $f) + { + $fields[$id] = gmExporterFieldDecorator::getInstance($f); + } + return $fields; + } +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 "config['exportation']['title'])? $this->config['exportation']['title'] : 'Report' ?>"; + } +config['exportation']['title']) ?> + + public function getExportationDefaultType() + { + return gmExporterTypes::EXPORT_TYPE_XLS; + } + + public function getExportationType() + { + config['exportation']['type'])): ?> + return "config['exportation']['type'] ?>"; + + return $this->getExportationDefaultType(); + + } +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); + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationAction.php b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationAction.php new file mode 100644 index 0000000..ef71483 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationAction.php @@ -0,0 +1,28 @@ + protected function getExportationPager($type = null, $page = null) + { + $pager = $this->configuration->getExportationPager('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('getModuleName() ?>.exportation_page', $page, 'admin_module'); + } + + protected function getExportationPage() + { + return $this->getUser()->getAttribute('getModuleName() ?>.exportation_page', 1, 'admin_module'); + } + + protected function buildExportationCriteria() + { + return $this->buildQuery(); + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationConfiguration.php b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationConfiguration.php new file mode 100644 index 0000000..8e05b16 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/parts/exporterPaginationConfiguration.php @@ -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 'config['exportation']['pager_class']) ? $this->config['exportation']['pager_class'] : 'sfPropelPager' ?>'; +config['exportation']['pager_class']) ?> + } + + public function getExportationPagerMaxPerPage($type = 'default') + { + config['exportation']['max_per_page']) && is_numeric($this->config['exportation']['max_per_page'])): ?> + $maxPerPageOpts = array('default' => config['exportation']['max_per_page'] ?>); + config['exportation']['max_per_page']) && is_array($this->config['exportation']['max_per_page'])): ?> + $maxPerPageOpts = asPhp(array_merge(array('default' => 1000), $this->config['exportation']['max_per_page'])) ?>; + + $maxPerPageOpts = array('default' => 1000); + + + return isset($maxPerPageOpts[$type])? $maxPerPageOpts[$type] : $maxPerPageOpts['default']; +config['exportation']['max_per_page']) ?> + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/skeleton/lib/exporterCsv.php b/data/generator/sfPropelModule/revisitedAdmin15/skeleton/lib/exporterCsv.php new file mode 100644 index 0000000..18e96a0 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/skeleton/lib/exporterCsv.php @@ -0,0 +1,13 @@ +moduleName) ?>GeneratorConfiguration.class.php'); require_once(dirname(__FILE__).'/../lib/BasemoduleName) ?>GeneratorHelper.class.php'); +require_once(dirname(__FILE__).'/../lib/exporterHelper.php'); +require_once(dirname(__FILE__).'/../lib/exporterHelperUser.php'); +require_once(dirname(__FILE__).'/../lib/exporterXls.php'); +require_once(dirname(__FILE__).'/../lib/exporterCsv.php'); +require_once(dirname(__FILE__).'/../lib/exporterForm.php'); + /** * getModuleName() ?> actions. * @@ -62,4 +68,11 @@ public function preExecute() + + +configuration->isExportationEnabled()): ?> + + + + } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterCsv.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterCsv.php new file mode 100644 index 0000000..045fffa --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterCsv.php @@ -0,0 +1,6 @@ +[?php + +class BasegetModuleName()) ?>ExporterCsv extends gmExporterCsv +{ + +} diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterForm.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterForm.php new file mode 100644 index 0000000..717daf5 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterForm.php @@ -0,0 +1,6 @@ +[?php + +class BasegetModuleName()) ?>ExporterForm extends gmExporterForm +{ + +} diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelper.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelper.php new file mode 100644 index 0000000..5f4fffd --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelper.php @@ -0,0 +1,17 @@ +[?php + +/** + * getModuleName() ?> module exporter. + * + * @package ##PROJECT_NAME## + * @subpackage getModuleName()."\n" ?> + * @author ##AUTHOR_NAME## + * @version SVN: $Id: exporter.php 14891 2009-01-20 06:47:03Z dwhittle $ + */ +class BasegetModuleName()) ?>ExporterHelper extends gmExporterHelper +{ + protected function getExporterSubclassPrefix() + { + return 'getModuleName() ?>'; + } +} diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelperUser.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelperUser.php new file mode 100644 index 0000000..cf9aa59 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterHelperUser.php @@ -0,0 +1,17 @@ +[?php + +/** + * getModuleName() ?> module exporter helper with user selection. + * + * @package ##PROJECT_NAME## + * @subpackage getModuleName()."\n" ?> + * @author ##AUTHOR_NAME## + * @version SVN: $Id: exporter.php 14891 2009-01-20 06:47:03Z dwhittle $ + */ +class BasegetModuleName()) ?>ExporterHelperUser extends gmExporterHelperUser +{ + protected function getExporterSubclassPrefix() + { + return 'getModuleName() ?>'; + } +} diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterXls.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterXls.php new file mode 100644 index 0000000..70407ce --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/exporterXls.php @@ -0,0 +1,6 @@ +[?php + +class BasegetModuleName()) ?>ExporterXls extends gmExporterXls +{ + +} diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/helper.php b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/helper.php index 4e2c9b6..3daebdf 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/lib/helper.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/lib/helper.php @@ -14,59 +14,129 @@ public function getUrlForAction($action) return 'list' == $action ? 'params['route_prefix'] ?>' : 'params['route_prefix'] ?>_'.$action; } - public function linkToMoveUp($object, $params) + public function linkToEdit($object, $params) { - if ($object->isFirst()) + $obj = $object instanceOf sfOutputEscaperObjectDecorator ? $object->getRawValue() : $object; + if (isset($params['show_when'])) { - return '