From 9f108dd1a969473375341d92a7b1252fa2cedc9a Mon Sep 17 00:00:00 2001 From: mszulecki Date: Thu, 14 Jun 2007 17:09:01 +0000 Subject: Initial import. git-svn-id: http://svn.sukimashita.com/repos/mailadmin/trunk@2 4281df72-ff29-0410-8fee-2d9ac0c5f5a7 --- .../mailadmin/template/actions/actions.class.php | 435 +++++++++++++++++++++ 1 file changed, 435 insertions(+) create mode 100644 data/generator/sfPropelAdmin/mailadmin/template/actions/actions.class.php (limited to 'data/generator/sfPropelAdmin/mailadmin/template/actions/actions.class.php') diff --git a/data/generator/sfPropelAdmin/mailadmin/template/actions/actions.class.php b/data/generator/sfPropelAdmin/mailadmin/template/actions/actions.class.php new file mode 100644 index 0000000..70f94f0 --- /dev/null +++ b/data/generator/sfPropelAdmin/mailadmin/template/actions/actions.class.php @@ -0,0 +1,435 @@ +[?php + +/** + * getGeneratedModuleName() ?> actions. + * + * @package ##PROJECT_NAME## + * @subpackage getGeneratedModuleName() ?> + + * @author Fabien Potencier + * @version SVN: $Id: actions.class.php 3501 2007-02-18 10:28:17Z fabien $ + */ +class getGeneratedModuleName() ?>Actions extends sfActions +{ + public function executeIndex() + { + return $this->forward('getModuleName() ?>', 'list'); + } + + public function executeList() + { + $this->processSort(); + + $this->processFilters(); + +getParameterValue('list.filters')): ?> + $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/getSingularName() ?>/filters'); + + + // pager + $this->pager = new sfPropelPager('getClassName() ?>', getParameterValue('list.max_per_page', 20) ?>); + $c = new Criteria(); + $this->addSortCriteria($c); + $this->addFiltersCriteria($c); + $this->pager->setCriteria($c); + $this->pager->setPage($this->getRequestParameter('page', 1)); +getParameterValue('list.peer_method')): ?> + $this->pager->setPeerMethod('getParameterValue('list.peer_method') ?>'); + +getParameterValue('list.peer_count_method')): ?> + $this->pager->setPeerCountMethod('getParameterValue('list.peer_count_method') ?>'); + + $this->pager->init(); + } + + public function executeCreate() + { + return $this->forward('getModuleName() ?>', 'edit'); + } + + public function executeSave() + { + return $this->forward('getModuleName() ?>', 'edit'); + } + + public function executeEdit() + { + $this->getSingularName() ?> = $this->getgetClassName() ?>OrCreate(); + + if ($this->getRequest()->getMethod() == sfRequest::POST) + { + $this->updategetClassName() ?>FromRequest(); + + $this->savegetClassName() ?>($this->getSingularName() ?>); + + $this->setFlash('notice', 'Your modifications have been saved'); + + if ($this->getRequestParameter('save_and_add')) + { + return $this->redirect('getModuleName() ?>/create'); + } + else if ($this->getRequestParameter('save_and_list')) + { + return $this->redirect('getModuleName() ?>/list'); + } + else + { + return $this->redirect('getModuleName() ?>/edit?getPrimaryKeyUrlParams('this->') ?>); + } + } + else + { + $this->labels = $this->getLabels(); + } + } + + public function executeDelete() + { + $this->getSingularName() ?> = getClassName() ?>Peer::retrieveByPk(getRetrieveByPkParamsForAction(40) ?>); + $this->forward404Unless($this->getSingularName() ?>); + + try + { + $this->deletegetClassName() ?>($this->getSingularName() ?>); + } + catch (PropelException $e) + { + $this->getRequest()->setError('delete', 'Could not delete the selected getSingularName()) ?>. Make sure it does not have any associated items.'); + return $this->forward('getModuleName() ?>', 'list'); + } + +getColumnCategories('edit.display') as $category): ?> +getColumns('edit.display', $category) as $name => $column): ?> +getParameterValue('edit.fields.'.$column->getName().'.type') ?> + +replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> + $currentFile = sfConfig::get('sf_upload_dir')."//".$this->getSingularName() ?>->getgetPhpName() ?>(); + if (is_file($currentFile)) + { + unlink($currentFile); + } + + + + + return $this->redirect('getModuleName() ?>/list'); + } + + public function handleErrorEdit() + { + $this->preExecute(); + $this->getSingularName() ?> = $this->getgetClassName() ?>OrCreate(); + $this->updategetClassName() ?>FromRequest(); + + $this->labels = $this->getLabels(); + + return sfView::SUCCESS; + } + + protected function savegetClassName() ?>($getSingularName() ?>) + { + $getSingularName() ?>->save(); + +getColumnCategories('edit.display') as $category): ?> +getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> +getName() ?> +isPrimaryKey()) continue ?> +getParameterValue('edit.fields.'.$column->getName().'.credentials') ?> +getParameterValue('edit.fields.'.$column->getName().'.type') ?> +getParameterValue('edit.fields.'.$column->getName().'.params'); +$user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); +$through_class = isset($user_params['through_class']) ? $user_params['through_class'] : ''; + +?> + +getClassName(); +$related_class = sfPropelManyToMany::getRelatedClass($class, $through_class); +$related_table = constant($related_class.'Peer::TABLE_NAME'); +$middle_table = constant($through_class.'Peer::TABLE_NAME'); +$this_table = constant($class.'Peer::TABLE_NAME'); + +$related_column = sfPropelManyToMany::getRelatedColumn($class, $through_class); +$column = sfPropelManyToMany::getColumn($class, $through_class); + +?> + + + if ($this->getUser()->hasCredential()) + { + + // Update many-to-many for "" + $c = new Criteria(); + $c->add(Peer::getColumnName()) ?>, $getSingularName() ?>->getPrimaryKey()); + Peer::doDelete($c); + + $ids = $this->getRequestParameter('associated_'); + if (is_array($ids)) + { + foreach ($ids as $id) + { + $ = new (); + $->setgetPhpName() ?>($getSingularName() ?>->getPrimaryKey()); + $->setgetPhpName() ?>($id); + $->save(); + } + } + + + } + + + + + + } + + protected function deletegetClassName() ?>($getSingularName() ?>) + { + $getSingularName() ?>->delete(); + } + + protected function updategetClassName() ?>FromRequest() + { + $getSingularName() ?> = $this->getRequestParameter('getSingularName() ?>'); + +getColumnCategories('edit.display') as $category): ?> +getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> +getName() ?> +isPrimaryKey()) continue ?> +getParameterValue('edit.fields.'.$column->getName().'.credentials') ?> +getParameterValue('edit.fields.'.$column->getName().'.type') ?> + + if ($this->getUser()->hasCredential()) + { + + +replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> + $currentFile = sfConfig::get('sf_upload_dir')."//".$this->getSingularName() ?>->getgetPhpName() ?>(); + if (!$this->getRequest()->hasErrors() && isset($getSingularName() ?>['_remove'])) + { + $this->getSingularName() ?>->setgetPhpName() ?>(''); + if (is_file($currentFile)) + { + unlink($currentFile); + } + } + + if (!$this->getRequest()->hasErrors() && $this->getRequest()->getFileSize('getSingularName() ?>[]')) + { + + if (isset($getSingularName() ?>[''])) + { + + +getParameterValue('edit.fields.'.$column->getName().'.filename')): ?> + $fileName = "replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.filename'))) ?>"; + + $fileName = md5($this->getRequest()->getFileName('getSingularName() ?>[]').time().rand(0, 99999)); + + $ext = $this->getRequest()->getFileExtension('getSingularName() ?>[]'); + if (is_file($currentFile)) + { + unlink($currentFile); + } + $this->getRequest()->moveFile('getSingularName() ?>[]', sfConfig::get('sf_upload_dir')."//".$fileName.$ext); + $this->getSingularName() ?>->setgetPhpName() ?>($fileName.$ext); + + if ($getSingularName() ?>['']) + { + try + { + $dateFormat = new sfDateFormat($this->getUser()->getCulture()); + + + if (!is_array($getSingularName() ?>[''])) + { + $value = $dateFormat->format($getSingularName() ?>[''], '', $dateFormat->getInputPattern('')); + } + else + { + $value_array = $getSingularName() ?>['']; + $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : ''); + } + $this->getSingularName() ?>->setgetPhpName() ?>($value); + } + catch (sfException $e) + { + // not a date + } + } + else + { + $this->getSingularName() ?>->setgetPhpName() ?>(null); + } + + $this->getSingularName() ?>->setgetPhpName() ?>(isset($getSingularName() ?>['']) ? $getSingularName() ?>[''] : 0); +isForeignKey()): ?> + $this->getSingularName() ?>->setgetPhpName() ?>($getSingularName() ?>[''] ? $getSingularName() ?>[''] : null); + + $this->getSingularName() ?>->setgetPhpName() ?>($getSingularName() ?>['']); + + + } + + + } + + + + } + + protected function getgetClassName() ?>OrCreate(getMethodParamsForGetOrCreate() ?>) + { + if (getTestPksForGetOrCreate() ?>) + { + $getSingularName() ?> = new getClassName() ?>(); + } + else + { + $getSingularName() ?> = getClassName() ?>Peer::retrieveByPk(getRetrieveByPkParamsForGetOrCreate() ?>); + + $this->forward404Unless($getSingularName() ?>); + } + + return $getSingularName() ?>; + } + + protected function processFilters() + { +getParameterValue('list.filters')): ?> + if ($this->getRequest()->hasParameter('filter')) + { + $filters = $this->getRequestParameter('filters'); +getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> + + if (isset($filters['getName() ?>']['from']) && $filters['getName() ?>']['from'] !== '') + { + $filters['getName() ?>']['from'] = sfI18N::getTimestampForCulture($filters['getName() ?>']['from'], $this->getUser()->getCulture()); + } + if (isset($filters['getName() ?>']['to']) && $filters['getName() ?>']['to'] !== '') + { + $filters['getName() ?>']['to'] = sfI18N::getTimestampForCulture($filters['getName() ?>']['to'], $this->getUser()->getCulture()); + } + + + + $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/getSingularName() ?>/filters'); + $this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/getSingularName() ?>/filters'); + } + + } + + protected function processSort() + { + if ($this->getRequestParameter('sort')) + { + $this->getUser()->setAttribute('sort', $this->getRequestParameter('sort'), 'sf_admin/getSingularName() ?>/sort'); + $this->getUser()->setAttribute('type', $this->getRequestParameter('type', 'asc'), 'sf_admin/getSingularName() ?>/sort'); + } + + if (!$this->getUser()->getAttribute('sort', null, 'sf_admin/getSingularName() ?>/sort')) + { +getParameterValue('list.sort')): ?> + + $this->getUser()->setAttribute('sort', '', 'sf_admin/getSingularName() ?>/sort'); + $this->getUser()->setAttribute('type', '', 'sf_admin/getSingularName() ?>/sort'); + + $this->getUser()->setAttribute('sort', '', 'sf_admin/getSingularName() ?>/sort'); + $this->getUser()->setAttribute('type', 'asc', 'sf_admin/getSingularName() ?>/sort'); + + + } + } + + protected function addFiltersCriteria($c) + { +getParameterValue('list.filters')): ?> +getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> +isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue ?> + if (isset($this->filters['getName() ?>_is_empty'])) + { + $criterion = $c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, ''); + $criterion->addOr($c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, null, Criteria::ISNULL)); + $c->add($criterion); + } + + else if (isset($this->filters['getName() ?>'])) + { + if (isset($this->filters['getName() ?>']['from']) && $this->filters['getName() ?>']['from'] !== '') + { + + $criterion = $c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, date('Y-m-d', $this->filters['getName() ?>']['from']), Criteria::GREATER_EQUAL); + + $criterion = $c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, $this->filters['getName() ?>']['from'], Criteria::GREATER_EQUAL); + + } + if (isset($this->filters['getName() ?>']['to']) && $this->filters['getName() ?>']['to'] !== '') + { + if (isset($criterion)) + { + + $criterion->addAnd($c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, date('Y-m-d', $this->filters['getName() ?>']['to']), Criteria::LESS_EQUAL)); + + $criterion->addAnd($c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, $this->filters['getName() ?>']['to'], Criteria::LESS_EQUAL)); + + } + else + { + + $criterion = $c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, date('Y-m-d', $this->filters['getName() ?>']['to']), Criteria::LESS_EQUAL); + + $criterion = $c->getNewCriterion(getPeerClassName() ?>::getName()) ?>, $this->filters['getName() ?>']['to'], Criteria::LESS_EQUAL); + + } + } + + if (isset($criterion)) + { + $c->add($criterion); + } + } + + else if (isset($this->filters['getName() ?>']) && $this->filters['getName() ?>'] !== '') + { + + $c->add(getPeerClassName() ?>::getName()) ?>, strtr($this->filters['getName() ?>'], '*', '%'), Criteria::LIKE); + + $c->add(getPeerClassName() ?>::getName()) ?>, $this->filters['getName() ?>']); + + } + + + + } + + protected function addSortCriteria($c) + { + if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/getSingularName() ?>/sort')) + { + $sort_column = getClassName() ?>Peer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); + if ($this->getUser()->getAttribute('type', null, 'sf_admin/getSingularName() ?>/sort') == 'asc') + { + $c->addAscendingOrderByColumn($sort_column); + } + else + { + $c->addDescendingOrderByColumn($sort_column); + } + } + } + + protected function getLabels() + { + return array( +getColumnCategories('edit.display') as $category): ?> +getColumns('edit.display', $category) as $name => $column): ?> + 'getSingularName() ?>{getName() ?>}' => 'getParameterValue('edit.fields.'.$column->getName().'.name')); echo $label_name ?>:', + + + ); + } +} -- cgit v1.1-32-gdbae