mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Refactor of client settings and cascading settings Client > Group > Company finished
This commit is contained in:
parent
ac19a4bb12
commit
0d4d1041f5
@ -151,7 +151,7 @@ class Client extends BaseModel
|
||||
if($this->group_settings !== null)
|
||||
{
|
||||
|
||||
$group_settings = ClientSettings::buildClientSettings(new ClientSettings($this->group_settings()), new ClientSettings($this->settings));
|
||||
$group_settings = ClientSettings::buildClientSettings(new ClientSettings($this->group_settings->settings), new ClientSettings($this->settings));
|
||||
|
||||
return ClientSettings::buildClientSettings(new CompanySettings($this->company->settings), $group_settings);
|
||||
|
||||
@ -162,28 +162,20 @@ class Client extends BaseModel
|
||||
|
||||
public function getSetting($setting)
|
||||
{
|
||||
// Log::error('does prop exist? = ' . property_exists($this->settings, $setting));
|
||||
// Log::error('does prop have val? = ' . isset($this->settings->{str_replace("'","",$setting)}));
|
||||
// Log::error('client');
|
||||
// Log::error(print_r($this,1));
|
||||
// Log::error('company');
|
||||
// Log::error(print_r($this->company,1));
|
||||
// Log::error('company settings');
|
||||
// Log::error(print_r($this->company->settings,1));
|
||||
// Log::error('cli = '.$this->settings->{$setting});
|
||||
// Log::error('co = '.$this->company->settings->{$setting});
|
||||
|
||||
|
||||
//check client level first
|
||||
if($this->settings && isset($this->settings->{$setting}) && property_exists($this->settings, $setting))
|
||||
return $this->settings->{$setting};
|
||||
|
||||
//check group level (if a group is assigned)
|
||||
if($this->group_settings && isset($this->group_settings->settings->{$setting}) && property_exists($this->group_settings->settings, $setting))
|
||||
return $this->group_settings->{$setting};
|
||||
return $this->group_settings->settings->{$setting};
|
||||
|
||||
|
||||
//check company level
|
||||
if(isset($this->company->settings->{$setting}) && property_exists($this->company->settings, $setting))
|
||||
return $this->company->settings->{$setting};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -70,14 +70,6 @@ class GroupSettingsTest extends TestCase
|
||||
|
||||
$this->client->fresh();
|
||||
|
||||
// \Log::error(print_r($this->client,1));
|
||||
\Log::error(print_r($this->client->settings,1));
|
||||
\Log::error(print_r($this->client->settings->timezone_id,1));
|
||||
\Log::error(print_r($this->client->settings->date_format,1));
|
||||
\Log::error(print_r($this->client->group_settings->settings->timezone_id,1));
|
||||
\Log::error(print_r($this->client->group_settings->settings,1));
|
||||
\Log::error(print_r($this->client->company->settings->timezone_id,1));
|
||||
|
||||
$this->assertEquals($this->client->group_settings->settings->timezone_id, 'SPOCK');
|
||||
$this->assertEquals($this->client->getSetting('timezone_id'), 'SPOCK');
|
||||
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'SPOCK');
|
||||
@ -89,14 +81,28 @@ class GroupSettingsTest extends TestCase
|
||||
public function testClientDefaults()
|
||||
{
|
||||
|
||||
$this->company_settings->timezone_id = NULL;
|
||||
$this->client->group_settings->settings->timezone_id = NULL;
|
||||
$this->client->settings->timezone_id = 'SCOTTY';
|
||||
$this->client->company->settings = $this->company_settings;
|
||||
|
||||
$this->client->save();
|
||||
$this->client->company->save();
|
||||
$cs = $this->client->company->settings;
|
||||
$cs->timezone_id = NULL;
|
||||
|
||||
$this->client->company->settings = $cs;
|
||||
|
||||
$gs = $this->client->group_settings->settings;
|
||||
$gs->timezone_id = NULL;
|
||||
|
||||
$this->client->group_settings->settings = $gs;
|
||||
|
||||
$cls = $this->client->settings;
|
||||
$cls->timezone_id = 'SCOTTY';
|
||||
$cls->date_format = 'sharleen';
|
||||
|
||||
$this->client->settings = $cls;
|
||||
|
||||
$this->client->group_settings->save();
|
||||
$this->client->company->save();
|
||||
$this->client->save();
|
||||
|
||||
$this->client->fresh();
|
||||
|
||||
$this->assertEquals($this->client->settings->timezone_id, 'SCOTTY');
|
||||
$this->assertEquals($this->client->getSetting('timezone_id'), 'SCOTTY');
|
||||
|
Loading…
Reference in New Issue
Block a user