-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move config definitions out of DB into code (#1817)
* Proof of concept. Probably still has bugs * fix order and value setting * more cleanup and upgrade script * closes #1670 * Apply fixes from StyleCI * fix sql style * gettext for config descriptions * more gettext * fix annoying second refresh settings bug * Apply fixes from StyleCI * better null checking, and cleanup old code * Remove special handling of country and timezone settings. They are simple "choice" settings. * Apply fixes from StyleCI * move another country * Fix issue with choices containing a space
- Loading branch information
1 parent
870c98a
commit ef1e054
Showing
13 changed files
with
477 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
namespace ChurchCRM\dto; | ||
|
||
use ChurchCRM\Config; | ||
|
||
class ConfigItem | ||
{ | ||
private static $id, $name, $value, $type, $default, $tooltip, $data, $dbConfigItem; | ||
public function __construct($id, $name, $type, $default, $tooltip, $data) { | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->type = $type; | ||
$this->default = $default; | ||
$this->tooltip = $tooltip; | ||
$this->data = $data; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setDBConfigObject($dbConfigItem) | ||
{ | ||
$this->dbConfigItem = $dbConfigItem; | ||
$this->value = $dbConfigItem->getValue(); | ||
} | ||
|
||
public function getDBConfigObject() | ||
{ | ||
return $this->dbConfigItem ; | ||
} | ||
|
||
public function getValue() | ||
{ | ||
if ( isset( $this->value ) ) | ||
{ | ||
return $this->value; | ||
} | ||
else | ||
{ | ||
return $this->default; | ||
} | ||
} | ||
|
||
public function getBooleanValue() | ||
{ | ||
return boolval($this->getValue()); | ||
} | ||
|
||
public function setValue($value) | ||
{ | ||
if ( $value == $this->getDefault() ) | ||
{ | ||
//if the value is being set to the default value | ||
if ( isset ($this->dbConfigItem) ) //and the item exists | ||
{ | ||
//delete the item | ||
$this->dbConfigItem->delete(); | ||
} | ||
} | ||
else | ||
{ | ||
//if the value is being set to a non-default value | ||
if ( ! isset ($this->dbConfigItem) ) | ||
{ | ||
//create the item if it doesnt exist | ||
$this->dbConfigItem = new Config(); | ||
$this->dbConfigItem->setId($this->getId()); | ||
$this->dbConfigItem->setName($this->getName()); | ||
} | ||
//set the values, and seve it | ||
$this->dbConfigItem->setValue($value); | ||
$this->dbConfigItem->save(); | ||
$this->value=$value; | ||
} | ||
} | ||
|
||
public function getDefault() | ||
{ | ||
return $this->default; | ||
} | ||
|
||
|
||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getTooltip() | ||
{ | ||
return $this->tooltip; | ||
} | ||
|
||
public function getSection() | ||
{ | ||
return $this->section; | ||
} | ||
|
||
public function getCategory() | ||
{ | ||
return $this->category; | ||
} | ||
|
||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
} |
Oops, something went wrong.