Hi, this is my first and I am new to Yii. I am currently working on a user/server settings manager component, each of which is completely configurable. For example, when a user logs in he or she has these settings, but if he or she doesn’t I want them to load from the server settings. The best use case I have is timezones, a user can setting there own timezone, but if he or she doesn’t care it will default to configured server settings.
Here is how I am attempting to solve it and I was wondering if it follows MVC/ Yii convention.
User and Server Settings has a Model/View/Controller
User settings will be loaded when the $user is logged in. Desired reference $user->setting_name;
Server settings are loaded when the app is loaded. Yii:app()->setting_name
In some cases the user setting and server setting will be the same like the timezone.
I have a model called Job.
In the afterFind(I am just showing the snippit I am concerned with/ I do not have code written yet, I learn better by writing it out on paper
*Note the $convertedTimeZone will probably be another component for international time.
public function afterFind() {
// Looping through each result
if ($user->timezone)
{
$this->openDate = $convertedTimeZone // $convertedTimeZone is a placeholder for converting GMT to localtimezone
} else if (Yii::app()->timezone)
$this->openDate = $convertedTimeZone // $convertTimeZone is a placeholder for converting GMT to servertimezone
}
I was also wondering if I created a helper component that would do that comparison for me
function convertTimeZone($time) {
$userTZ = UserSettings::getTimeZone(); // UsersSettings will query the database and give me back the tz
$serverTZ = ServerSettings::getTimeZone(); // Server Settings will query the database and give me back the tz
/* another way */
$usersettings = UserSettings::find();
$serversettings = ServerSettings::find();
if ($tz = $usersettings->name['timezone']) {
$convertTimeZone($tz);
} elseif ($tz = $settings->name['timezone']) { // else if to have a hard coded value just in case implied on other examples'
$convertTimeZone($tz);
}
return $userTZ ? $convertTimeZone($userTZ) : $convertTimeZone($serverTZ);
}
public function afterFind() {
// looping through each result
$this->openDate = Yii:app()->convertTimeZone($this->openDate);
}
Thanks in advance, I am sorry if I wasn’t clear on anything, please let me know how to improve my posts for the next time; which I bet there will be .