1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 <?php
namespace hji\geofarms\models;
use \hji\common\AbstractSettingsModel;
use \hji\membership\Membership;
use \hji\geofarms\GeoFarms;
require_once(Membership::$dir . '/common/interfaces/AbstractSettingsModel.php');
class Settings extends \hji\common\interfaces\AbstractSettingsModel
{
    // This is a required variable
    protected static $__CLASS__ = __CLASS__; // Provide this in each singleton class.
    // Option Groups
    // each settings page has it's own option group or option key
    // all settings values are simply an array of values that is
    // assigned to an option key.
    protected $optionGroups = array(
        'general' => 'General',
    );
    // Keep in mind:
    // option groups are saved all together in a single array
    // under the same $settingsKey
    // By default $settingsKey = 'hji-{$pluginSlug}-settings"
    // You can redefine it by passing your own settingsKey
    // as a second parameter in the AbstractSettingsModel::__construct()
    public function __construct()
    {
        // Adds the upgrade tab if neighborhoods is installed and active
        if (is_plugin_active('hji-neighborhoods/hji-neighborhoods.php'))
        {
            $this->optionGroups['upgrade'] = 'Neighborhoods Upgrade';
        }
        parent::__construct(GeoFarms::$slug, GeoFarms::$settings_key);
        // Loads all settings into a single array
        // Tor retrieve option values use Settings::getOptions()
        // See the AbstractSettingsModel for more info.
        $this->loadOptions();
    }
    // TODO: write custom methods for all sorts of crazy data manipulation of the settings of your plugin
}