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 '
  • '.__($params['label'], array(), 'sf_admin').'
  • '; + $show_when = $params['show_when']; } - if (empty($params['action'])) + if (method_exists($obj, 'canEdit') && !$obj->canEdit()) { - $params['action'] = 'moveUp'; + return '
  • '.__($params['label'], array(), 'sf_admin').'
  • '; } - return '
  • '.link_to(__($params['label'], array(), 'sf_admin'), 'params['moduleName'] ?>/'.$params['action'].'?getPrimaryKeyUrlParams('$object', true); ?>).'
  • '; + if (isset($show_when)) + { + return (call_user_func(array($obj, $show_when))) ? parent::linkToEdit($object, $params) : ''; + } + else + { + return parent::linkToEdit($object, $params); + } } - public function linkToMoveDown($object, $params) + public function linkToDelete($object, $params) { - if ($object->isLast()) + $obj = $object instanceOf sfOutputEscaperObjectDecorator ? $object->getRawValue() : $object; + if (isset($params['show_when'])) { - return '
  • '.__($params['label'], array(), 'sf_admin').'
  • '; + $show_when = $params['show_when']; } - if (empty($params['action'])) + if (method_exists($obj, 'canDelete') && !$obj->canDelete()) { - $params['action'] = 'moveDown'; + return '
  • '.__($params['label'], array(), 'sf_admin').'
  • '; } - return '
  • '.link_to(__($params['label'], array(), 'sf_admin'), 'params['moduleName'] ?>/'.$params['action'].'?getPrimaryKeyUrlParams('$object', true); ?>).'
  • '; + if (isset($show_when)) + { + return (call_user_func(array($obj, $show_when))) ? parent::linkToDelete($object, $params) : ''; + } + else + { + return parent::linkToDelete($object, $params); + } } - public function linkToNew($params) + public function linkToShow($object, $params) { - return '
  • '.link_to(__($params['label'], array(), 'sf_admin'), '@'.$this->getUrlForAction('new')).'
  • '; - } + $obj = $object instanceOf sfOutputEscaperObjectDecorator ? $object->getRawValue() : $object; + if (isset($params['show_when'])) + { + $show_when = $params['show_when']; + } - public function linkToList($params) - { - return '
  • '.link_to(__($params['label'], array(), 'sf_admin'), '@'.$this->getUrlForAction('list')).'
  • '; + if (method_exists($obj, 'canShow') && !$obj->canShow()) + { + return '
  • '.__($params['label'], array(), 'sf_admin').'
  • '; + } + + if (isset($show_when)) + { + return (call_user_func(array($obj, $show_when))) ? '
  • '.link_to(__($params['label'], array(), 'sf_admin'), $this->getUrlForAction('show'), $object).'
  • ' : ''; + } + else + { + return '
  • '.link_to(__($params['label'], array(), 'sf_admin'), $this->getUrlForAction('show'), $object).'
  • '; + } } - public function linkToSave($object, $params) + public function linkToExport($params) { - return '
  • '; + $params['action'] = isset($params['action'])? $params['action'] : 'doExportationPages'; + $params['label'] = 'Export'; + + return '
  • '.link_to_function(__('Export'), +" +jQuery('#sf_admin_exportation').show(); +jQuery('#sf_admin_exportation_ajax_indicator').show(); +jQuery('#sf_admin_exportation_form').hide(); +jQuery('#sf_admin_exportation').centerHorizontally(); + +jQuery('#sf_admin_exportation_form').load('".url_for(sfContext::getInstance()->getModuleName().'/'.$params['action'])."', + + function (response, status, xhr) { + if (status != 'error') + { + jQuery('#sf_admin_exportation').show(); + jQuery('#sf_admin_exportation_ajax_indicator').hide(); + jQuery('#sf_admin_exportation_form').show(); + jQuery('#sf_admin_exportation').centerHorizontally(); + jQuery('#sf_admin_exportation_resizable_area').ensureVisibleHeight(); + jQuery(document).scrollTop(jQuery('#sf_admin_exportation').offset().top); + } + } +)").'
  • '; } - public function linkToSaveAndAdd($object, $params) + public function linkToUserExport($params) { - if (!$object->isNew()) + $params['action'] = isset($params['action'])? $params['action'] : 'newUserExportation'; + $params['label'] = 'Custom export'; + + return '
  • '.link_to_function(__('Custom export'), +" +jQuery('#sf_admin_exportation').show(); +jQuery('#sf_admin_exportation_ajax_indicator').show(); +jQuery('#sf_admin_exportation_form').hide(); +jQuery('#sf_admin_exportation').centerHorizontally(); + +jQuery('#sf_admin_exportation_form').load('".url_for(sfContext::getInstance()->getModuleName().'/'.$params['action'])."', + + function (response, status, xhr) { + if (status != 'error') { - return ''; + jQuery('#sf_admin_exportation').show(); + jQuery('#sf_admin_exportation_ajax_indicator').hide(); + jQuery('#sf_admin_exportation_form').show(); + jQuery('#sf_admin_exportation').centerHorizontally(); + jQuery('#sf_admin_exportation_resizable_area').ensureVisibleHeight(); + jQuery(document).scrollTop(jQuery('#sf_admin_exportation').offset().top); } - - return '
  • '; + } +)").''; } } diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_assets.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_assets.php index 78b785a..0f4b83a 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_assets.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_assets.php @@ -2,4 +2,6 @@ [?php use_stylesheet('params['css'] ?>', 'first') ?] params['css'])): ?> [?php use_stylesheet('', 'first') ?] +[?php use_stylesheet('/acPropelExtendedGeneratorPlugin/css/exportation.css', 'first') ?] +[?php use_javascript('/acPropelExtendedGeneratorPlugin/js/exportation.js', 'last') ?] diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation.php new file mode 100644 index 0000000..0108dc6 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation.php @@ -0,0 +1,7 @@ + diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_form_field.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_form_field.php new file mode 100644 index 0000000..195b415 --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_form_field.php @@ -0,0 +1,17 @@ +
    + [?php $escapedField = $form[$name] instanceOf sfOutputEscaper? $form[$name]->getRawValue() : $form[$name] ?] + [?php if (!$escapedField instanceOf sfFormFieldSchema) echo $form[$name]->renderError() ?] + +
    + [?php echo $form[$name]->renderLabel(null, array('class' => ($form->getValidator($name) && $form->getValidator($name)->getOption('required')) ? 'required' : '')) ?] + +
    + [?php echo $form[$name]->render() ?] +
    + + [?php if ($help || $help = $form[$name]->renderHelp()): ?] +
    [?php echo __($help, array(), 'getI18nCatalogue() ?>') ?]
    + [?php endif; ?] +
    +
    +
    diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_pages.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_pages.php new file mode 100644 index 0000000..e2dc26a --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_exportation_pages.php @@ -0,0 +1,36 @@ +[?php use_helper('I18N', 'Date', 'JavascriptBase') ?] +configuration->isExportationEnabled()): ?> +
    + [?php if ($pager->getNbResults() > 0): ?] +

    [?php echo __('Please, select the group of items you want to export', array(), 'sf_admin') ?]

    +
    + +
    + [?php else: ?] +

    [?php echo __('No results', array(), 'sf_admin') ?]

    +
    + +
    + [?php endif ?] +
    +
    + +
    + diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_form_fieldset.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_form_fieldset.php index e294f52..e0428cc 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_form_fieldset.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_form_fieldset.php @@ -1,3 +1,4 @@ +
    [?php if ('NONE' != $fieldset): ?] [?php echo __($fieldset, array(), 'getI18nCatalogue() ?>') ?] @@ -12,7 +13,7 @@ 'help' => $field->getConfig('help'), 'form' => $form, 'field' => $field, - 'class' => 'field sf_admin_field_'.strtolower($field->getType()).' sf_admin_form_field_'.$name, + 'class' => 'row field sf_admin_field_'.strtolower($field->getType()).' sf_admin_form_field_'.$name, )) ?] [?php endforeach; ?]
    diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list.php index ae2b0c5..acc363d 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list.php @@ -2,7 +2,7 @@ [?php if (!$pager->getNbResults()): ?]

    [?php echo __('No result', array(), 'sf_admin') ?]

    [?php else: ?] - +
    configuration->getValue('list.batch_actions')): ?> diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_actions.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_actions.php index b2a47c8..cf38bcf 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_actions.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_actions.php @@ -3,10 +3,11 @@ [?php if (sfContext::getInstance()->getUser()->()): ?] - -
  • - addCredentialCondition($this->getLinkToAction($name, $params, false), $params) ?> -
  • + +addCredentialCondition('[?php echo $helper->linkToExport('.$this->asPhp($params).') ?]', $params)."\n" ?> + +addCredentialCondition('[?php echo $configuration->isExportationEnabled()?$helper->linkToUserExport('.$this->asPhp($params).'):"" ?]', $params)."\n" ?> + [?php endif; ?] diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_td_actions.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_td_actions.php index 499b19f..7ceec8d 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_td_actions.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/_list_td_actions.php @@ -21,12 +21,10 @@ addCredentialCondition('[?php echo $helper->linkToMoveDown($'.$this->getSingularName().', '.$this->asPhp($params).') ?]', $params) ?> -
  • - addCredentialCondition($this->getLinkToAction($name, $params, true), $params) ?> - -
  • + %s', $params['class_suffix'], $this->getLinkToAction($name, $params, true)); ?> + addCredentialCondition($link, $params); ?> - + [?php endif; ?] diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/createUserExportationSuccess.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/createUserExportationSuccess.php new file mode 100644 index 0000000..7351f1f --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/createUserExportationSuccess.php @@ -0,0 +1,3 @@ +configuration->isExportationEnabled()): ?> +[?php include_partial('getModuleName()?>/exportation_pages', array('pager' => $pager, 'exportUrl' => 'processUserExportation')) ?] + diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/indexSuccess.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/indexSuccess.php index a819e11..e5e979c 100644 --- a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/indexSuccess.php +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/indexSuccess.php @@ -2,6 +2,10 @@ [?php include_partial('getModuleName() ?>/assets') ?]
    + configuration->isExportationEnabled()): ?> + [?php include_partial('exportation', array('configuration' => $configuration)) ?] + +

    [?php echo getI18NString('list.title') ?> ?]

    [?php include_partial('getModuleName() ?>/flashes') ?] @@ -20,15 +24,18 @@ + configuration->getValue('list.batch_actions')): ?>
    diff --git a/data/generator/sfPropelModule/revisitedAdmin15/template/templates/newUserExportationSuccess.php b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/newUserExportationSuccess.php new file mode 100644 index 0000000..27530db --- /dev/null +++ b/data/generator/sfPropelModule/revisitedAdmin15/template/templates/newUserExportationSuccess.php @@ -0,0 +1,52 @@ +configuration->isExportationEnabled()): ?> +[?php use_helper('JavascriptBase') ?] +
    +

    [?php echo __('Exportation Form', array(), 'sf_admin') ?]

    +
    + + getModuleName() ?>/createUserExportation")?]', + beforeSend: function (request) + { + jQuery('#sf_admin_exportation').show(); + jQuery('#sf_admin_exportation_ajax_indicator').show(); + jQuery('#sf_admin_exportation_form').hide(); + jQuery('#sf_admin_exportation').centerHorizontally(); + jQuery('#sf_admin_exportation_resizable_area').ensureVisibleHeight(); + }, + success: function(html){ + jQuery('#sf_admin_exportation').show(); + jQuery('#sf_admin_exportation_ajax_indicator').hide(); + jQuery('#sf_admin_exportation_form').show(); + jQuery('#sf_admin_exportation').centerHorizontally(); + jQuery('#sf_admin_exportation_resizable_area').ensureVisibleHeight(); + jQuery('#sf_admin_exportation_form').html(html); + }, + data: jQuery.param(jQuery(this).serializeArray()), + dataType: 'script' + }); return false;"> + + + [?php echo $form->renderHiddenFields() ?] + [?php if ($form->hasGlobalErrors()): ?] + [?php echo $form->renderGlobalErrors() ?] + [?php endif; ?] + [?php foreach ($form as $name => $field): ?] + [?php if (!$form[$name]->isHidden()): ?] + [?php include_partial('exportation_form_field', array('form' => $form, 'name' => $name, 'help' => null, 'class' => 'sf_admin_form_row sf_admin_exportation_form_row')) ?] + [?php endif ?] + [?php endforeach ?] + + +
    +
    +
      +
    • [?php echo link_to_function(__('Cancel', array(), 'sf_admin'), "jQuery('#sf_admin_exportation').hide()") ?]
    • +
    • + [?php echo button_to_function(__('Export', array(), 'sf_admin'), "jQuery('#sf_admin_exportation_form_submit').click()") ?] +
    • +
    +
    +
    + diff --git a/lib/exporter/decorators/gmExporterDecorator.class.php b/lib/exporter/decorators/gmExporterDecorator.class.php new file mode 100644 index 0000000..963df8f --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecorator.class.php @@ -0,0 +1,102 @@ +options = $this->configure($options); + $this->context = is_null($context)? sfContext::getInstance() : $context; + } + + static public function parseOptions(&$options) + { + $options['decorator'] = isset($options['decorator'])? $options['decorator'] : 'text'; + } + + public function configure($options) + { + $options['method_parameter'] = isset($options['method_parameter'])? $options['method_parameter'] : null; + $options['translate'] = isset($options['translate'])? $options['translate'] : true; + $options['label'] = isset($options['label'])? $options['label'] : ''; + + return $options; + } + + public function getContext() + { + return $this->context; + } + + public function getId() + { + return strtolower(str_replace(array('á', 'é', 'í', 'ó', 'ú', 'ñ'), + array('a', 'e', 'i', 'o', 'u', 'n'), + sfInflector::underscore($this->options['label']))); + } + + public function getLabel() + { + return $this->translate($this->options['label']); + } + + public function render($value) + { + if (is_object($value) && isset($this->options['method'])) + { + $method = $this->options['method']; + if (is_null($this->options['method_parameter'])) + { + return $value->$method(); + } + return $value->$method($this->options['method_parameter']); + } + return $value; + } + + protected function translate($text) + { + if ($this->options['translate']) + { + $this->getContext()->getConfiguration()->loadHelpers('I18N'); + return __($text); + } + return $text; + } +} diff --git a/lib/exporter/decorators/gmExporterDecoratorArray.class.php b/lib/exporter/decorators/gmExporterDecoratorArray.class.php new file mode 100644 index 0000000..e8a6926 --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecoratorArray.class.php @@ -0,0 +1,48 @@ +options['enclosure'])? '' : $this->options['enclosure']; + + $string .= implode($this->options['separator'], $this->decorateWhole($value)); + + $string .= empty($this->options['enclosure'])? '' : $this->options['enclosure']; + + return $string; + } + + protected function getItemDecorator() + { + $options = array_merge($this->options['itemDecoratorOptions'], array('decorator' => $this->options['itemDecorator'])); + + $decorator = gmExporterFieldDecorator::getInstance($options); + + return $decorator; + } + + protected function decorateWhole($value) + { + $dec = $this->getItemDecorator(); + $ret = array(); + if(!is_array($value)) return $ret; + foreach ($value as $v) + { + $ret[] = $dec->render($v); + } + return $ret; + } +} diff --git a/lib/exporter/decorators/gmExporterDecoratorBoolean.class.php b/lib/exporter/decorators/gmExporterDecoratorBoolean.class.php new file mode 100644 index 0000000..ebb34e5 --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecoratorBoolean.class.php @@ -0,0 +1,21 @@ +translate($this->options['trueRepresentation']) : $this->translate($this->options['falseRepresentation']); + } +} diff --git a/lib/exporter/decorators/gmExporterDecoratorDate.class.php b/lib/exporter/decorators/gmExporterDecoratorDate.class.php new file mode 100644 index 0000000..b6427a8 --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecoratorDate.class.php @@ -0,0 +1,21 @@ +options['dateFormat'])) + { + $value = date($this->options['dateFormat'], strtotime($value)); + } + return $value; + } +} diff --git a/lib/exporter/decorators/gmExporterDecoratorFloat.class.php b/lib/exporter/decorators/gmExporterDecoratorFloat.class.php new file mode 100644 index 0000000..a4f39b0 --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecoratorFloat.class.php @@ -0,0 +1,23 @@ +options['decimals']) + { + $value = gmGeneratorRounder::round($value, $this->options['decimals']); + } + return (float) parent::render($value); + } +} diff --git a/lib/exporter/decorators/gmExporterDecoratorInteger.class.php b/lib/exporter/decorators/gmExporterDecoratorInteger.class.php new file mode 100644 index 0000000..d9be8d8 --- /dev/null +++ b/lib/exporter/decorators/gmExporterDecoratorInteger.class.php @@ -0,0 +1,10 @@ +options['truncateTo'] != -1 && strlen($value) > $this->options['truncateTo']) + { + $value = substr($value, 0, $this->options['truncateTo']-3); + $value .= '...'; + } + + if ($this->options['capitalize']) + { + $value = ucfirst(strtolower($value)); + } + + if ($this->options['uppercase']) + { + $value = strtoupper($value); + } + + if ($this->options['lowercase']) + { + $value = strtolower($value); + } + + return $value; + } +} diff --git a/lib/exporter/gmExporter.class.php b/lib/exporter/gmExporter.class.php new file mode 100644 index 0000000..804e6cb --- /dev/null +++ b/lib/exporter/gmExporter.class.php @@ -0,0 +1,166 @@ +myContext = $context; + } + + /** + * Returns an instance of sfContext + */ + public function getContext() + { + return is_null($this->myContext)? sfContext::getInstance() : $this->myContext; + } + + /** + * This function should save the file in the desired location + */ + abstract public function saveFile($whereTo); + + /** + * This function should do the exportation + */ + abstract public function build(); + + /** + * Should return the file extension to be used + */ + static public function getFileExtension() + { + return self::FILE_EXTENSION; + } + + /** + * Should return the mime type to be used + */ + static public function getMimeType() + { + return self::MIME_TYPE; + } + + /** + * Returns the number of columns that the header row will have. + * + * @return integer + */ + public function getHeaderCount() + { + return count($this->getHeaders()); + } + + /** + * Sets the headers that will be rendered. + * + * @param $headers array of gmExporterHeader + */ + public function setHeaders($headers) + { + $this->headers = $headers; + } + + /** + * Returns the headers that will be rendered. + * + * @return array of gmExporterHeader + */ + public function getHeaders() + { + return $this->headers; + } + + /** + * Sets the fields that will be rendered. + * + * @param $fields array of gmExporterFields + */ + public function setFields($fields) + { + $this->fields = $fields; + } + + /** + * Returns the fields that will be rendered. + * + * @return array of gmExporterFields + */ + public function getFields() + { + return $fields; + } + + public function setTitle($title) + { + $this->title = $title; + } + + /** + * Returns the title of the document. + * + * @param $default a default value to be used is the title has not been set + */ + public function getTitle($default = null) + { + return is_null($this->title)? $default : $this->title; + } + + /** + * Returns the common title for all documents + * (located above the title and is the same for + * all exported documents( + * + * @return String or false + */ + public function getCommonTitle() + { + return gmGeneratorConfiguration::getExportationCommonTitle(); + } + + /** + * If enabled, gets date to all documents + */ + public function getCommonDate() + { + if (gmGeneratorConfiguration::getExportationAppendCommonDate()) + { + return date(gmGeneratorConfiguration::getExportationDateFormat()); + } + return false; + } + + /** + * Returns the content of the created file + * + * @param $fileName full path to the generated file + * + * @return String + */ + public function getFileContent($fileName) + { + return file_get_contents($fileName, $this->fileContentFlags); + } + + + /** + * Translates an string + * + * @param String $text String to be translated + * + * @return String + */ + protected function translate($text) + { + $this->getContext()->getConfiguration()->loadHelpers('I18N'); + return __($text); + } +} diff --git a/lib/exporter/gmExporterCsv.class.php b/lib/exporter/gmExporterCsv.class.php new file mode 100644 index 0000000..9aa14e3 --- /dev/null +++ b/lib/exporter/gmExporterCsv.class.php @@ -0,0 +1,105 @@ +rowInformation = $rows; + } + + static public function getFileExtension() + { + return self::FILE_EXTENSION; + } + + static public function getMimeType() + { + return self::MIME_TYPE; + } + + public function getRowInformation() + { + return $this->rowInformation; + } + + public function build() + { + ini_set("max_execution_time",0); + $this->buildCsvObject(); + $this->buildTitle(); + $this->buildHeaders($this->getHeaders()); + $this->buildRows($this->getRowInformation()); + } + + public function saveFile($whereTo) + { + ini_set("max_execution_time",0); + $handle = fopen($whereTo, "w"); + if ($handle !== false) + { + fwrite($handle, $this->textInRam); + fclose($handle); + } + } + + protected function buildCsvObject() + { + $this->textInRam = ''; + } + + protected function buildTitle() + { + } + + protected function buildHeaders($headers) + { + $column = 0; + $headerStr = ""; + foreach ($this->getHeaders() as $field) + { + $this->appendColumn($field, $column); + $column++; + } + $this->appendLineBreak(); + } + + protected function appendColumn($txt, $column) + { + $str = $column == 0? '' : ';'; + $str .= '"'.addcslashes($txt, '"').'"'; + $this->textInRam .= $str; + } + + protected function appendLineBreak() + { + $this->textInRam .= "\n"; + } + + protected function buildRows($rows) + { + foreach ($rows as $line) + { + $this->buildRow($line); + $this->appendLineBreak(); + } + } + + protected function buildRow($row) + { + $column = 0; + foreach ($row as $key => $field) + { + $this->appendColumn($field, $column); + $column++; + } + } +} diff --git a/lib/exporter/gmExporterForm.class.php b/lib/exporter/gmExporterForm.class.php new file mode 100644 index 0000000..66db1f7 --- /dev/null +++ b/lib/exporter/gmExporterForm.class.php @@ -0,0 +1,129 @@ +configuration = $options['configuration']; + $this->pager = $options['pager']; + + parent::__construct($defaults, $options, $CSRFSecret); + } + + public function bind(array $taintedValues = null, array $taintedFiles = null) + { + parent::bind($taintedValues,$taintedFiles); + + if ($this->isValid()) + { + $this->pager->setMaxPerPage($this->configuration->getExportationPagerMaxPerPage($this->getExportationType())); + } + } + + public function getExportationCriteria() + { + return $this->pager->getCriteria(); + } + + public function getExportationType() + { + if ($this->isBound()) + { + return $this->getValue('type'); + } + else + { + return $this->getDefault('type'); + } + } + + public function getExportationResults() + { + return $this->pager->getResults(); + } + + public function getExportationPager() + { + return $this->pager; + } + + protected function getContext() + { + return is_null($this->getOption('context'))? sfContext::getInstance() : $this->getOption('context'); + } + + protected function getFields() + { + return $this->getOption('fields', array()); + } + + public function configure() + { + parent::configure(); + + + if ($this->getOption('allowUserTypeSelection')) + { + $this->setWidget('type', new sfWidgetFormChoice(array('choices' => gmExporterTypes::getChoices(true, $this->getContext())))); + $this->setValidator('type', new sfValidatorChoice(array('choices' => gmExporterTypes::getTypes(), 'required' => true))); + } + else + { + $this->setWidget('type', new sfWidgetFormInputHidden()); + $this->setValidator('type', new sfValidatorString(array('required' => true))); + } + + $this->setWidget('title', new sfWidgetFormInput()); + $this->setValidator('title', new sfValidatorString(array('required' => true))); + + foreach ($this->getFields() as $fieldDecorator) + { + $this->setWidget($fieldDecorator->getId(), new sfWidgetFormInputCheckbox()); + $this->setValidator($fieldDecorator->getId(), new sfValidatorBoolean()); + $this->getWidgetSchema()->setLabel($fieldDecorator->getId(), $fieldDecorator->getLabel()); + $this->setDefault($fieldDecorator->getId(), true); + } + + $this->getWidgetSchema()->setNameFormat('exportation[%s]'); + + $this->setDefault('title', $this->translate($this->getOption('title'))); + $this->setDefault('type', $this->getOption('type')); + } + + protected function translate($text) + { + $this->getContext()->getConfiguration()->loadHelpers('I18N'); + + return __($text); + } + + public function getExportationFieldSelectionDecorators() + { + if ($this->isBound()) + { + $selectedFields = array(); + foreach ($this->getFields() as $fieldDecorator) + { + if (isset($this->values[$fieldDecorator->getId()]) && $this->values[$fieldDecorator->getId()]) + { + $selectedFields[] = $fieldDecorator; + } + } + return $selectedFields; + } + else + { + throw new Exception('The form is not bounded'); + } + } + + public function getExportationTitle() + { + return $this->values['title']; + } +} diff --git a/lib/exporter/gmExporterHelper.class.php b/lib/exporter/gmExporterHelper.class.php new file mode 100644 index 0000000..83640c2 --- /dev/null +++ b/lib/exporter/gmExporterHelper.class.php @@ -0,0 +1,277 @@ +rowObjects = $objects; + $this->myConfiguration = $configuration; + + $this->parseOptions($options); + } + + /* + * parseOptions + * + * Parses the options of the exporter helper. + * + * @param array $options + */ + protected function parseOptions($options) + { + $this->type = isset($options['type'])? $options['type'] : gmExporterTypes::EXPORT_TYPE_XLS; + $this->myContext = isset($options['context'])? $options['context'] : sfContext::getInstance(); + $this->useSheets = isset($options['use_sheets'])? $options['use_sheets'] : false; + $this->sheetTitles = isset($options['sheet_titles'])? $options['sheet_titles'] : array(); + } + + protected function getExporterSubclassPrefix() + { + return 'gm'; + } + + /** + * Returns the exporter subclass name + * + * @return string exporter subclass name + */ + protected function getExporterSubclassName() + { + return gmExporterTypes::getClassForType($this->type, $this->getExporterSubclassPrefix()); + } + + /** + * Returns the exporter subclass instance + * + * @return gmExporter subclass + */ + protected function getExporterSubclass() + { + $klass = $this->getExporterSubclassName(); + return new $klass(); + } + + /** + * Returns a sfContext instance + * + * @return sfContext + */ + protected function getContext() + { + return $this->myContext; + } + + /** + * Returns the generator's configuration instance + * + * @return The generator's configuration object (do not recall the class name and I shall not look it up!) + */ + protected function getConfiguration() + { + return $this->myConfiguration; + } + + /** + * Return the objects that should be used to fetch data from + * + * @return array Object + */ + protected function getRowObjects($sheet = null) + { + return $this->useSheets && !is_null($sheet)? $this->rowObjects[$sheet] : $this->rowObjects; + } + + /** + * Return an array of strings that will be used to render headers + * + * @return array An array of strings + */ + protected function getHeaders() + { + return $this->getConfiguration()->getExportationHeaders(); + } + + protected function getTitle($pageNumber=null) + { + return $this->getConfiguration()->getExportationTitle(); + } + + /** + * Use this to get an abstraction of the user's field configuration + * + * @return an array of gmExporterFieldDecorators + */ + protected function getFieldSelection() + { + $fields = array(); + foreach ($this->getConfiguration()->getExportationFieldSelection() as $field) + { + $fields[] = gmExporterFieldDecorator::getInstance($field, $this->getContext()); + } + return $fields; + } + + /** + * Formats a row + * + * @param Object $object + * + * @return array an array with the corresponding object's row information + */ + protected function decorateRowInformation($object) + { + $row = array(); + if (!empty($object)) + { + foreach ($this->getFieldSelection() as $fieldDecorator) + { + $row[] = $fieldDecorator->render($object); + } + } + return $row; + } + + + /** + * Returns the row information ready to be passed to the exporter subclass + * + * @return array + */ + public function getRowInformation($sheet = null) + { + if (!$this->useSheets) + { + $rowInformation = array(); + foreach ($this->getRowObjects() as $object) + { + $rowInformation[] = $this->decorateRowInformation($object); + } + } + else + { + $rowInformation = array(); + foreach ($this->getRowObjects($sheet) as $object) + { + $rowInformation[] = $this->decorateRowInformation($object); + } + } + return $rowInformation; + } + + public function getSheetCount() + { + return $this->useSheets? count($this->rowObjects) : 1; + } + + /** + * This method builds the exporting object with all the data in it! + */ + public function build($title = null, $headers = null, $rowInformation = null) + { + for ($i=0;$i<$this->getSheetCount();$i++) + { + $this->buildSheet($title, $headers, $rowInformation, $i); + } + $this->exporterInstance->setActiveSheetIndex(0); + } + + public function getActiveSheet() + { + return is_null($this->exporterInstance)? 0 : $this->exporterInstance->getActiveSheet(); + } + + public function buildSheet($title = null, $headers = null, $rowInformation = null, $pageNumber = 0) + { + $title = is_null($title)? $this->getTitle($pageNumber) : $title; + $headers = is_null($headers)? $this->getHeaders() : $headers; + $rowInformation = is_null($rowInformation)? $this->getRowInformation($pageNumber) : $rowInformation; + + $this->exporterInstance = is_null($this->exporterInstance)? $this->getExporterSubclass() : $this->exporterInstance; + + $this->exporterInstance->createSheet($pageNumber); + $this->exporterInstance->setActiveSheetIndex($pageNumber); + $this->setSheetTitle($pageNumber); + $this->exporterInstance->setTitle($title); + $this->exporterInstance->setHeaders($headers); + $this->exporterInstance->setRowInformation($rowInformation); + + $this->exporterInstance->resetRowCount(); + $this->exporterInstance->build(); + } + + public function setSheetTitle($number) + { + if (!is_null($title = $this->getSheetTitle($number))) + { + $this->exporterInstance->setSheetTitle($number, $title); + } + } + + public function getSheetTitle($number) + { + return isset($this->sheetTitles[$number])? $this->sheetTitles[$number] : null; + } + + /** + * This method saves the file in some location to be rendered afterwards + * + * @param $whereTo self explicatory path + */ + public function saveFile($whereTo) + { + $this->exporterInstance->saveFile($whereTo); + $this->savedFilePath = $whereTo; + } + + /** + * + */ + public function deleteFile($path = null) + { + $path= is_null($path)? $this->savedFilePath : $path; + unlink($path); + $this->savedFilePath=null; + } + + /** + * + */ + public function getFileContents($fromWhere = null) + { + $fromWhere = is_null($fromWhere)? $this->savedFilePath : $fromWhere; + return file_get_contents($fromWhere); + } + + /** + * + */ + public function freeMem() + { + foreach ($this->getRowObjects() as $o) + { + if (method_exists($o, 'clearAllReferences')) $o->clearAllReferences(); + unset($o); + } + $this->rowObjects = array(); + } +} diff --git a/lib/exporter/gmExporterHelperCustom.class.php b/lib/exporter/gmExporterHelperCustom.class.php new file mode 100644 index 0000000..3ab46b6 --- /dev/null +++ b/lib/exporter/gmExporterHelperCustom.class.php @@ -0,0 +1,131 @@ +rowObjects = $objects; + $this->parseOptions($options); + } + + /* + * parseOptions + * + * Parses the options of the exporter helper. + * + * @param array $options + */ + protected function parseOptions($options) + { + parent::parseOptions($options); + $this->fieldSelection = isset($options['decorators'])? $options['decorators'] : array(); + $this->headers = isset($options['headers'])? $options['headers'] : array(); + $this->title = isset($options['title'])? $options['title'] : array(); + $this->mime_type = isset($options['mime_type'])? $options['mime_type'] : null; + } + + protected function getExporterSubclassPrefix() + { + return 'gm'; + } + + /** + * Returns the exporter subclass name + * + * @return string exporter subclass name + */ + protected function getExporterSubclassName() + { + return gmExporterTypes::getClassForType($this->type, $this->getExporterSubclassPrefix()); + } + + /** + * Returns the exporter subclass instance + * + * @return gmExporter subclass + */ + protected function getExporterSubclass() + { + $klass = $this->getExporterSubclassName(); + return new $klass(); + } + + /** + * Returns the generator's configuration instance + * + * @return The generator's configuration object (do not recall the class name and I shall not look it up!) + */ + protected function getConfiguration() + { + return null; + } + + /** + * Return an array of strings that will be used to render headers + * + * @return array An array of strings + */ + protected function getHeaders() + { + return $this->headers; + } + + protected function getTitle($pageNumber = null) + { + return $this->title; + } + + /** + * Use this to get an abstraction of the user's field configuration + * + * @return an array of gmExporterFieldDecorators + */ + protected function getFieldSelection() + { + return $this->fieldSelection; + } + + public function getMimeType() + { + return $this->mime_type; + } + + public function prepareResponseForExportation($response, $filename) + { + sfConfig::set('sf_web_debug', false); + $mimeType = $this->getMimeType(); + $response->setHttpHeader('Content-type', "$mimeType; charset=UTF-8"); + $response->setHttpHeader('Content-Disposition', ' attachment; filename="'.$filename.'"'); + $response->setHttpHeader('Cache-Control', ' maxage=3600'); + $response->setHttpHeader('Pragma', 'public'); + } + + public function prepareActionForExportation($action, $filename) + { + $action->setLayout(false); + $this->prepareResponseForExportation($action->getResponse(), $filename); + } +} diff --git a/lib/exporter/gmExporterHelperUser.class.php b/lib/exporter/gmExporterHelperUser.class.php new file mode 100644 index 0000000..6f17954 --- /dev/null +++ b/lib/exporter/gmExporterHelperUser.class.php @@ -0,0 +1,53 @@ +exportationForm = $exportationForm; + } + + protected function getHeaders() + { + $headers = array(); + foreach ($this->exportationForm->getExportationFieldSelectionDecorators() as $fieldDecorator) + { + $headers[] = $fieldDecorator->getLabel(); + } + return $headers; + } + + protected function getTitle($pageNumber=null) + { + $title = $this->exportationForm->getExportationTitle(); + return empty($title)? parent::getTitle() : $title; + } + + /** + * Use this to get an abstraction of the user's field configuration + * + * @return an array of gmExporterFieldDecorators + */ + protected function getFieldSelection() + { + return $this->exportationForm->getExportationFieldSelectionDecorators(); + } +} diff --git a/lib/exporter/gmExporterTypes.class.php b/lib/exporter/gmExporterTypes.class.php new file mode 100644 index 0000000..b889047 --- /dev/null +++ b/lib/exporter/gmExporterTypes.class.php @@ -0,0 +1,87 @@ + 'Excel', + self::EXPORT_TYPE_CSV => 'CSV', + ); + + static protected + $classes = array( + self::EXPORT_TYPE_XLS => 'ExporterXls', + self::EXPORT_TYPE_CSV => 'ExporterCsv', + ); + + static public function getFileExtension($type) + { + $class = self::getClassForType($type); + + return call_user_func(array($class, 'getFileExtension')); + } + + static public function getMimeType($type) + { + $class = self::getClassForType($type); + + return call_user_func(array($class, 'getMimeType')); + } + + static public function getClassPreffix($preffix = null) + { + return is_null($preffix)? self::EXPORTER_SUBCLASS_PREFFIX : $preffix; + } + + static public function getClassForType($type, $preffix = null) + { + if (isset(self::$classes[$type])) + { + return self::getClassPreffix($preffix).self::getClassSuffixForType($type); + } + return $type; + } + + static public function getClassSuffixForType($type) + { + return isset(self::$classes[$type])? self::$classes[$type] : $type; + } + + static public function getTypes() + { + return array_keys(self::$types); + } + + static public function getChoices($addEmpty = false, $context = null) + { + $choices = $addEmpty? array(null => null) : array(); + + foreach (self::$types as $id => $lbl) + { + $choices[$id] = self::translate($lbl, $context); + } + + return $choices; + } + + static public function translate($val, $context = null) + { + if (is_null($context)) + { + return $val; + } + + self::loadHelpers($context); + + return __($val); + } + + static public function loadHelpers($context) + { + $context->getConfiguration()->loadHelpers('I18N'); + } +} diff --git a/lib/exporter/gmExporterXls.class.php b/lib/exporter/gmExporterXls.class.php new file mode 100644 index 0000000..8be5ad0 --- /dev/null +++ b/lib/exporter/gmExporterXls.class.php @@ -0,0 +1,272 @@ +buildExcelObject(); + } + + public function resetRowCount() + { + $this->headerRow = 1; + } + + public function getTitleRowNumber() + { + } + + public function getHeaderRowNumber() + { + } + + public function getCommonTitleRowNumber() + { + } + + public function getCommonDateRowNumber() + { + } + + public function setRowInformation($rows) + { + $this->rowInformation = $rows; + } + + static public function getFileExtension() + { + return self::FILE_EXTENSION; + } + + static public function getMimeType() + { + return self::MIME_TYPE; + } + + public function getRowInformation() + { + return $this->rowInformation; + } + + public function build() + { + ini_set("max_execution_time",0); + + $this->buildTitle(); + $this->buildHeaders($this->getHeaders()); + $this->buildRows($this->getRowInformation()); + $this->setAutosizeColumnDimensions(); + } + + public function getTitleLastRowNumber() + { + return $this->headerRow - 1; + } + + public function getActiveSheet() + { + return $this->excelObject->getActiveSheetIndex(); + } + + public function setAutosizeColumnDimensions() + { + if (sfConfig::get('app_xls_autosize_columns', true)) + { + if ($this->getTitleLastRowNumber() > 0) + { + foreach (range(1, $this->getTitleLastRowNumber()) as $row) + { + $this->excelObject->getActiveSheet()->getRowDimension($row)->setRowHeight(20); + } + } + + for ($i=0;$i<$this->getHeaderCount();$i++) + { + $column = chr(ord('A') + $i); + $this->excelObject->getActiveSheet()->getColumnDimension($column)->setAutoSize(true); + } + } + } + + public function saveFile($whereTo) + { + ini_set("max_execution_time",0); + $this->excelWriter = new PHPExcel_Writer_Excel5($this->getExcelObject()); + $this->excelWriter->save($whereTo); + } + + public function createSheet($i) + { + return $this->applyDefaultSheetStyle($this->excelObject->createSheet($i)); + } + + public function setSheetTitle($number, $title) + { + if (!is_null($sheet = $this->excelObject->getSheet($number))) + { + $sheet->setTitle($title); + } + } + + public function getSheetCount() + { + return $this->excelObject->getSheetCount(); + } + + public function setActiveSheetIndex($i) + { + $this->excelObject->setActiveSheetIndex($i); + } + + protected function applyDefaultSheetStyle($sheet) + { + $sheet->getDefaultStyle()->getFont()->setSize(sfConfig::get('app_xls_font_size', 9)); + $sheet->getDefaultStyle()->getFont()->setName(sfConfig::get('app_xls_font_name', 'Arial')); + $sheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER); + $sheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER); + $sheet->getPageSetup()->setOrientation(sfConfig::get('app_xls_orientation_landscape')? PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE : PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); + $sheet->getPageSetup()->setFitToPage(true); + $sheet->getPageMargins()->setTop(sfConfig::get('app_xls_top_margin')); + $sheet->getPageMargins()->setRight(sfConfig::get('app_xls_right_margin')); + $sheet->getPageMargins()->setBottom(sfConfig::get('app_xls_bottom_margin')); + $sheet->getPageMargins()->setLeft(sfConfig::get('app_xls_left_margin')); + + return $sheet; + } + + protected function buildExcelObject() + { + $this->excelObject = new sfPhpExcel(); + $this->applyDefaultSheetStyle($this->excelObject->getActiveSheet()); + $this->excelObject->setActiveSheetIndex(0); + } + + public function setExcelObject($excelObject) + { + $this->excelObject = $object; + } + + public function getExcelObject() + { + return $this->excelObject; + } + + protected function buildTitleFormat($order = 1) + { + $ret = array( + 'font' => array( + 'bold' => $order == 1, + 'size' => $order < 4? 15 - $order : 11, + ), + 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, + 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, + 'wrap' => true), + 'borders' => array( + 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => 'ffffff')), + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => 'ffffff')), + 'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => 'ffffff')), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => 'ffffff')), + ), + ); + return $ret; + } + + protected function buildGeneralFormat() + { + $ret = array( + 'borders' => array( + 'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + ), + 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT), + ); + return $ret; + } + + protected function buildHeaderFormat() + { + $ret = array( + 'font' => array( + 'bold' => true, + ), + 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER), + 'borders' => array( + 'top' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), + 'left' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), + ), + ); + return array_merge($ret, $this->buildGeneralFormat()); + } + + protected function getTitles() + { + return is_array($this->getTitle())? $this->getTitle() : array($this->getTitle()); + } + + protected function buildTitle() + { + $titles = $this->getTitles(); + $row = $this->headerRow; + $order = 1; + + foreach ($titles as $title) + { + $this->excelObject->getActiveSheet()->setCellValueByColumnAndRow(0, $row, $this->translate($title)); + $this->excelObject->getActiveSheet()->mergeCellsByColumnAndRow(0, $row, $this->getHeaderCount()-1, $row); + $this->excelObject->getActiveSheet()->getStyleByColumnAndRow(0, $row)->applyFromArray($this->buildTitleFormat($order)); + $row++; + $order++; + } + + $this->headerRow = $row; + } + + protected function buildHeaders($headers) + { + $column = 0; + foreach ($this->getHeaders() as $field) + { + $this->excelObject->getActiveSheet()->setCellValueByColumnAndRow($column, $this->headerRow, $this->translate($field)); + $this->excelObject->getActiveSheet()->getStyleByColumnAndRow($column, $this->headerRow)->applyFromArray($this->buildHeaderFormat()); + $column++; + } + } + + protected function buildRows($rows) + { + $rowNumber = $this->headerRow + 1; + + foreach ($rows as $line) + { + $this->buildRow($line, $rowNumber); + $rowNumber++; + } + } + + protected function buildRow($row, $rowNumber) + { + $column = 0; + foreach ($row as $key => $field) + { + $this->excelObject->getActiveSheet()->setCellValueByColumnAndRow($column, $rowNumber, $field); + $this->excelObject->getActiveSheet()->getStyleByColumnAndRow($column, $rowNumber)->applyFromArray($this->buildGeneralFormat()); + $column++; + } + } +} diff --git a/lib/exporter/gmGeneratorConfiguration.class.php b/lib/exporter/gmGeneratorConfiguration.class.php new file mode 100644 index 0000000..aeafaa9 --- /dev/null +++ b/lib/exporter/gmGeneratorConfiguration.class.php @@ -0,0 +1,51 @@ + diff --git a/lib/generator/pmModelGeneratorConfiguration.class.php b/lib/generator/pmModelGeneratorConfiguration.class.php new file mode 100644 index 0000000..d391e6d --- /dev/null +++ b/lib/generator/pmModelGeneratorConfiguration.class.php @@ -0,0 +1,95 @@ +areFiltersDynamic()) + { + return array('form' => $this->getStaticFilterForm(), 'url' => $this->getDynamicFormFilterUrl()); + } + + return array(); + } + + public function getStaticFilterForm($filters = array()) + { + $class = $this->getStaticFilterFormClass(); + + return new $class($filters, $this->getStaticFilterFormOptions()); + } + + public function getStaticFilterFormOptions() + { + return array(); + } + + public function compile() + { + parent::compile(); + + $this->configuration['show'] = array( + 'fields' => array(), + 'title' => $this->getShowTitle(), + 'actions' => $this->getShowActions() ? $this->getShowActions() : array('_delete' => null, '_list' => null), + ); + + + foreach ($this->configuration['show']['actions'] as $action => $parameters) + { + $this->configuration['show']['actions'][$action] = $this->fixActionParameters($action, $parameters); + } + + $this->parseVariables('show', 'title'); + + $this->configuration['credentials']['show'] = array(); + foreach ($this->configuration['list']['fields'] as $f_name => $field) + { + $this->configuration['list']['fields'][$f_name]= new pmModelGeneratorConfigurationField($field); + } + foreach ($this->configuration['list']['display'] as $f_name => $field) + { + $this->configuration['list']['display'][$f_name]= new pmModelGeneratorConfigurationField($field); + } + } +} diff --git a/lib/generator/pmModelGeneratorConfigurationField.class.php b/lib/generator/pmModelGeneratorConfigurationField.class.php new file mode 100644 index 0000000..5af6d2c --- /dev/null +++ b/lib/generator/pmModelGeneratorConfigurationField.class.php @@ -0,0 +1,17 @@ + + */ +class pmModelGeneratorConfigurationField extends sfModelGeneratorConfigurationField{ + public function __construct(sfModelGeneratorConfigurationField $configurationField) { + parent::__construct($configurationField->name, $configurationField->config); + } + + public function isReal() { + return isset($this->config['column_name'])?true: parent::isReal(); + } +} +?> diff --git a/lib/generator/pmPropelGenerator.php b/lib/generator/pmPropelGenerator.php new file mode 100644 index 0000000..ef3efcb --- /dev/null +++ b/lib/generator/pmPropelGenerator.php @@ -0,0 +1,5 @@ + this.getUnscrolledHeight() + topOffset) + { + this.css("height", this.getUnscrolledHeight() + "px"); + this.css("overflow-y", "hidden"); + } + } +} + +jQuery.fn.getUnscrolledHeight = function() { + var scrollProperty = this.css("overflow-y"); + var heightProperty = this.height(); + + this.css("overflow-y", "hidden"); + this.css("height", "auto"); + + var height = this.height(); + + this.css("overflow-y", scrollProperty); + this.css("height", heightProperty); + + return height; +} diff --git a/web/js/pm_propel_generator.js b/web/js/pm_propel_generator.js new file mode 100644 index 0000000..81fce7f --- /dev/null +++ b/web/js/pm_propel_generator.js @@ -0,0 +1,45 @@ +function selectTab(tab) +{ + var div = document.getElementById('tab_'+tab); + var span = document.getElementById('tab_'+tab+'_link'); + + var divs = document.getElementsByTagName('div'); + var spans = document.getElementsByTagName('span'); + + for (d in divs) + { + if (divs[d].className == 'selected') + { + divs[d].className = 'not-selected'; + + divs[d].parentNode.style.display = "none"; + } + } + + div.className = 'selected'; + div.parentNode.style.display = "block"; + + for (s in spans) + { + if (spans[s].className == 'tab_link_selected') + { + spans[s].className = 'tab_link_not_selected'; + } + } + + span.className = 'tab_link_selected'; +} + +function toggleFold(fieldset) +{ + var div = document.getElementById('fold_'+fieldset); + + if (div.style.display == 'none') + { + div.style.display = 'block'; + } + else + { + div.style.display = 'none'; + } +} \ No newline at end of file