Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

easy settings class

y2kbgy2kbg New
edited February 2007 in Vanilla 1.0 Help
Is there anyone who has the need or want for a class that will greatly simplify the process of adding admin settings to an extension?

instead of a hundred lines of code to make an admin area, just include easysettings.php and 2 other lines of code and then 1 for each setting you want to add?

I would make this if anyone wants it.

Comments

  • YES PLEASE!

    I would love that :D
  • ok cool just making sure i wasn't doing a foolish think that would unnecessarily bloat code. Then it is done.(I mean will be done in about a week.)

    ok heres a question, should I make it an extension that has to be enabled and then all extensions that use this Would require this extension? I could also use this dependence to create continuity between extensions. This was noted to be desire by someone who said they they wanted ALL extension option to be under the 'Extension Options' category.

    I hope to make this work well and efficient so that it will be the (Vanilla) Industry standard for saving settings. Any tips from some gurus on how to accomplish this.

    ok I have already started so anticipate, but don't hold your breath.
  • OK question would you guys guys prefer to have many definitions and easy to call functions, Or include the Description you want next to the setting in the control panel?
  • I'd say that you should require other extensions to require this one to be enabled first.

    Could you give some examples of both options you're asking about as I don't completely understand what you're asking.
  • ok, either have:
    $Context->Dictionary['Friends_AllowGuests_Description'] = ' Allow Guest to View People Page'; $Context->Dictionary['Friends_Request_Description'] = ' Uncheck to Disable Request'; $EasySettingsForm->ExtensionName = "Friends"; $EasySettingsForm->AddEasySetting('AllowGuests'); $EasySettingsForm->AddEasySetting('Request');
    or
    $EasySettingsForm->ExtensionName = "Friends"; $EasySettingsForm->AddEasySetting('AllowGuests, ' Allow Guest to View People Page''; $EasySettingsForm->AddEasySetting('Request', ' Uncheck to Disable Request';
  • First one is better IMO as it allows for language files in the future no?
  • yes but more writing for you, and you would have add the friends_ and the description your self. I will make it the first way if someone seconds this suggestion.
  • Seconded...that's the way permissions etc work at the moment. Makes sense to build similarity and consistency.
  • ok good now i will proceeds with my development.
  • y2kbgy2kbg New
    edited January 2007
    ok
    so i got kinda far but i don't really know if I am on the right track!

    Here is a preview of how to add a settings page:
    if ($Context->SelfUrl == "settings.php" && $Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS') && array_key_exists('Friends_Settings_V', $Configuration)) { include 'php/easysetting.php'; $EasySettingsForm = $Context->ObjectFactory->NewContextObject($Context,'EasySettingsForm'); $EasySettingsForm->ExtensionName = 'Friends'; $EasySettingsForm->AddAnEasySetting('AllowGuests'); $EasySettingsForm->AddAnEasySetting('Request') $EasySettingsForm->AddAnEasySetting('PeoplesTab') $EasySettingsForm->AddEasySettingHeader('Select the Columns you would like to display:') $EasySettingsForm->AddAnEasySetting('NameCell') $EasySettingsForm->AddAnEasySetting('DateRegistered') $EasySettingsForm->AddAnEasySetting('MemberIcons') $EasySettingsForm->AddAnEasySetting('VisitCount') $EasySettingsForm->AddAnEasySetting('Email') $EasySettingsForm->AddAnEasySetting('PostCount') $EasySettingsForm->AddAnEasySetting('Role') $Page->AddRenderControl($EasySettingsForm,$Configuration["CONTROL_POSITION_BODY_ITEM"] + 1); $Panel->AddList('Extension Options', 10); $Panel->AddListItem('Extension Options',$ExtensionName.' Settings,GetUrl($Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction='.$ExtensionName)); }
    Does this look like I am using the object created by the object factory correctly?
    As of right now it only creates checkboxs as those are the only kind I know how to do at the moment, could someone enlighten me as how to do this correctly? I need some help on this and if I don't it will delay the release of Friends 2.0.

    Here is the class:
    <?php class EasySettingsForm extends PostBackControl { var $ConfigurationManager; var $ExtensionName; var $EasySettingDisplay = ''; var $EasySettingGet; function AddAnEasySetting($NewSetting){ $EasySettingDisplay .= GetDynamicCheckBox($ExtensionName.'_'.$NewSetting, 1,$this->ConfigurationManager->GetSetting($ExtensionName.'_'.$NewSetting),'',$this->Context->GetDefinition($ExtensionName.'_'.$NewSetting.'_Description')); } function AddEasySettingHeader($Header){ $EasySettingDisplay .= '</br><H2>'.$Header.'</H2>' } function EasySettingsForm(&$Context) { $this->Name = $ExtensionName.'SettingsForm'; $this->ValidActions = array($ExtensionName, 'Process'.$ExtensionName); $this->Constructor($Context); if (!$this->Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) { $this->IsPostBack = 0; } elseif( $this->IsPostBack ) { $SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php'; $this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context,'ConfigurationManager'); if ($this->PostBackAction == 'Process'.$ExtensionName) { $this->ConfigurationManager->GetSettingsFromForm($SettingsFile); // Forces checkbox result and saves all submitted fields $this->ConfigurationManager->DefineSetting('Friends_AllowGuests',ForceIncomingBool('Friends_AllowGuests', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Request',ForceIncomingBool('Friends_Request', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_NameCell',ForceIncomingBool('Friends_NameCell', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_DateRegistered',ForceIncomingBool('Friends_DateRegistered', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_MemberIcons',ForceIncomingBool('Friends_MemberIcons', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_VisitCount',ForceIncomingBool('Friends_VisitCount', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Email',ForceIncomingBool('Friends_Email', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_PostCount',ForceIncomingBool('Friends_PostCount', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Role',ForceIncomingBool('Friends_Role', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_PeoplesTab',ForceIncomingBool('Friends_PeoplesTab', 0), 0); if($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) { header('location:'.GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction='.$ExtensionName.'Success=1')); } else { $this->PostBackAction = $ExtensionName; } } } $this->CallDelegate('Constructor'); } function Render() { if ($this->IsPostBack) { $this->CallDelegate('PreRender'); $this->PostBackParams->Clear(); if ($this->PostBackAction == $ExtensionName) { $this->PostBackParams->Set('PostBackAction', "Process".$ExtensionName); echo ' <div id="Form" class="Account '.$ExtensionName.'Settings"> <fieldset> <legend>'.$ExtensionName.'&nbsp;Settings</legend> '.$this->Get_Warnings().' '.$this->Get_PostBackForm('frm'.$ExtensionName).' <H2>'.$ExtensionName.'&nbsp;Options:</H2>'.$EasySettingDisplay).' <div class="Submit"> <input type="submit" name="btnSave" value="'.$this->Context->GetDefinition('Save').'" class="Button SubmitButton" /> <a href="'.GetUrl($this->Context->Configuration,$this->Context->SelfUrl).'"class="CancelButton">'.$this->Context->GetDefinition('Cancel').'</a> </div> </form> </fieldset> </div>'; } } $this->CallDelegate('PostRender'); } } ?>
    I am new to classes and this was meant to be a learning experience. So if a "Great and Power One(coder)" could help me out it would be appreciated. I haven't even test this code yet because I don't think it is even ready to be tested.
  • ok i have worked ot some syntax bugs and stff and now I get this error:

    Fatal error: Call to a member function GetSetting() on a non-object in C:\Documents and Settings\Kaz\Desktop\server\mysite\extensions\Friends\php\easysetting.php on line 8
    line 8 is the middle line:
    function AddAnEasySetting($NewSetting){ $EasySettingDisplay .= GetDynamicCheckBox($ExtensionName.'_'.$NewSetting, 1,$this->ConfigurationManager->GetSetting($ExtensionName.'_'.$NewSetting),'',$this->Context->GetDefinition($ExtensionName.'_'.$NewSetting.'_Description')); }
  • If you could give us an example of how to use it as well, that would be cool ;)
  • yea the first one that said: "Here is a preview of how to add a settings page:"

    is how to add one. it has a lot of settings so it looks long. I also added the feature to add heading to the page such.
  • The moment you have all been waiting for is here, but I don't know about sing it in two extensions at once, it hasn't been tested like that. I will release it as soon as i get the proper Documentation written.
  • also have posted about once last little question so that may hold me up a bit.
  • I wait with baited breath...
  • oops i should say that i have finished this....
  • Yeah you should, I've been waiting for it :P I'll see if I can figure it out now. Thanks y2kbg.
  • lol i had started another thread about it a month ago, sorry!
This discussion has been closed.