From 5ce47c288d9005c957e9fd885c7d625c670a0051 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Mon, 20 May 2019 14:22:45 +0200 Subject: [PATCH] Created basic backend for club view --- src/admin/abstract/controller.php | 6 ++- src/admin/abstract/model.php | 50 ++++++++++++---------- src/admin/controllers/club.php | 39 +++++++++++++++++ src/admin/mymodels/club.php | 6 +-- src/admin/views/club/tmpl/default.php | 60 +++++++++++++++++++++++++-- src/admin/views/club/view.html.php | 48 +++++++-------------- 6 files changed, 148 insertions(+), 61 deletions(-) create mode 100644 src/admin/controllers/club.php diff --git a/src/admin/abstract/controller.php b/src/admin/abstract/controller.php index 388ecac..efa3631 100644 --- a/src/admin/abstract/controller.php +++ b/src/admin/abstract/controller.php @@ -173,7 +173,11 @@ abstract class AbstractClubsController extends BaseController continue; } - $value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null; + if(isset($v['skip_null_check'])) + $value = $values[$m]; + else + $value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null; + $obj->$functionName($value); } } diff --git a/src/admin/abstract/model.php b/src/admin/abstract/model.php index 4ab1708..5ef288f 100644 --- a/src/admin/abstract/model.php +++ b/src/admin/abstract/model.php @@ -107,16 +107,7 @@ abstract class AbstractClubsModel $q = $dbo->getQuery(true); $mappings = $this->getDataMappings(); - $values = array(); - foreach($mappings as $m) - $values[$m] = $this->$m; - - $this->filter($values); - - foreach($mappings as $m) - $values[$m] = $q->q($values[$m]); - - $this->postQuoteFilter($values); + $values = $this->getDataValues($mappings, $q); $q->insert($this->getTableName()) ->columns(array_map(array($q, 'qn'), $mappings)) @@ -139,16 +130,7 @@ abstract class AbstractClubsModel $q = $dbo->getQuery(true); $mapping = $this->getDataMappings(); - $values = array(); - foreach($mapping as $m) - $values[$m] = $this->$m; - - $this->filter($values); - - foreach($mapping as $m) - $values[$m] = $q->q($values[$m]); - - $this->postQuoteFilter($values); + $values = $this->getDataValues($mapping, $q); $q->update($this->getTableName()); foreach($mapping as $m) @@ -159,6 +141,32 @@ abstract class AbstractClubsModel $dbo->execute(); } + private function getDataValues($mapping, $q) + { + $rawValues = array(); + + foreach($mapping as $m) + $rawValues[$m] = $this->$m; + + $this->filter($rawValues); + + $quotedValues = array(); + + foreach($mapping as $m) + { + if(is_bool($rawValues[$m])) + $quotedValues[$m] = $rawValues[$m] ? 'TRUE' : 'FALSE'; + else if(is_numeric($rawValues[$m])) + $quotedValues[$m] = $rawValues[$m]; + else + $quotedValues[$m] = $q->q($rawValues[$m]); + } + + $this->postQuoteFilter($quotedValues); + + return $quotedValues; + } + protected function prepareDelete($dbo){} public function delete() @@ -186,7 +194,7 @@ abstract class AbstractClubsModel { foreach($this->getRequiredDataMappings() as $m) { - if(!isset($this->$m) || empty($this->$m) || $this->$m === null) + if(!isset($this->$m) || is_null($this->$m) || $this->$m === null) return false; } return true; diff --git a/src/admin/controllers/club.php b/src/admin/controllers/club.php new file mode 100644 index 0000000..d2f2a91 --- /dev/null +++ b/src/admin/controllers/club.php @@ -0,0 +1,39 @@ + array('required'=>true, 'name'=>'Bezeichnung', 'filter'=>'string') + 'name' => array('required'=>true, 'name'=>'Club-Name', 'filter'=>'string'), + 'address' => array('required'=>true, 'name'=>'Adresse', 'filter'=>'string'), + 'city' => array('required'=>true, 'name'=>'Stadt', 'filter'=>'string'), + 'homepage' => array('required'=>false, 'name'=>'Homepage', 'filter'=>'string'), + 'mail' => array('required'=>true, 'name'=>'E-Mail', 'filter'=>'string'), + 'iban' => array('required'=>true, 'name'=>'IBAN', 'filter'=>'string'), + 'bic' => array('required'=>true, 'name'=>'BIC', 'filter'=>'string'), + 'charitable' => array('skip_null_check'=>True), + 'president' => array('required'=>true, 'name'=>'Vorsitzender', 'skip_null_check'=>True) + ); + } + + protected function filterPreCheck(&$values) + { + if(is_null($values['charitable'])) + $values['charitable'] = false; + else + $values['charitable'] = true; + + $values['president'] = ClubsUser::loadUser((int)($values['president'])); + } +} diff --git a/src/admin/mymodels/club.php b/src/admin/mymodels/club.php index cf2aa52..4700d3d 100644 --- a/src/admin/mymodels/club.php +++ b/src/admin/mymodels/club.php @@ -108,7 +108,7 @@ class ClubsClub extends AbstractClubsModel /** * @param string $homapge */ - public function setHomapge(string $homapge) + public function setHomepage(string $homapge) { $this->homepage = $homapge; } @@ -232,12 +232,12 @@ class ClubsClub extends AbstractClubsModel protected function getDataMappings() { - return array('name', 'address', 'city', 'homepage', 'mail', 'iban', 'bic', 'charitable'); + return array('name', 'address', 'city', 'homepage', 'mail', 'iban', 'bic', 'charitable', 'president'); } protected function getRequiredDataMappings() { - return array('name', 'address', 'city', 'mail', 'iban', 'bic', 'charitable'); + return array('name', 'address', 'city', 'mail', 'iban', 'bic'); } private const tableName = '#__club_clubs'; diff --git a/src/admin/views/club/tmpl/default.php b/src/admin/views/club/tmpl/default.php index a52c08a..a685e8e 100644 --- a/src/admin/views/club/tmpl/default.php +++ b/src/admin/views/club/tmpl/default.php @@ -8,20 +8,72 @@ defined('_JEXEC') or die; ?>
- + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + isNew): ?> - +
Bezeichnung
Adresse + +
Stadt
Homepage
E-Mail
IBAN
BIC
Gemeinnützigobject->isCharitable() ? 'checked' : ''; ?>>
Vorsitzende/r + + +
IDoffer->getId(); ?>object->getId(); ?>
-
'>Zurück zur Übersicht +
'>Zurück zur Übersicht
diff --git a/src/admin/views/club/view.html.php b/src/admin/views/club/view.html.php index 92cf22f..92cecfb 100644 --- a/src/admin/views/club/view.html.php +++ b/src/admin/views/club/view.html.php @@ -1,47 +1,31 @@ input; - $id = $input->get->get('id'); + $this->users = ClubsUser::loadUsers(); - if($id === 'new') - { - $this->address = Route::_('index.php?option=com_clubs&task=offer.new'); - $this->offer = ClubsOffer::createOffer(); - $this->isNew = true; - } - else if(is_numeric($id)) - { - $this->address = Route::_('index.php?option=com_clubs&task=offer.change'); - $this->offer = ClubsOffer::loadOffer((int) $id); - $this->isNew = false; - } - else - throw new Exception('Need a user id.'); - - if($input->get->get('data', null, 'json') != null) - { - // Restore previous data - $dataurl = $input->get->get('data', null, 'json'); - $data = json_decode($dataurl, true); - - $this->offer->setName($data['name']); - - } - - ToolbarHelper::title('Club-Management - Angebot'); parent::display($tpl); } + + protected function getViewName() + { + return 'club'; + } + protected function getElementController() + { + return new ClubsControllerClub(); + } + + }