Skip to content

Commit

Permalink
Merge pull request #12 from nswdpc/enh-indexes
Browse files Browse the repository at this point in the history
Add indexes
  • Loading branch information
tardinha authored Mar 28, 2023
2 parents 52e1e85 + 5a47f20 commit 17385f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Models/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class Directive extends DataObject implements PermissionProvider
'UseNonce' => 'Boolean'
];

/**
* Database indexes
* @var array
* @config
*/
private static $indexes = [
'Enabled' => true,
'Key' => true
];

/**
* Defines summary fields commonly used in table columns
* as a quick overview of the data for this dataobject
Expand Down
16 changes: 14 additions & 2 deletions src/Models/Policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ class Policy extends DataObject implements PermissionProvider
'Directives' => Directive::class,
];

/**
* Database indexes
* @var array
* @config
*/
private static $indexes = [
'Enabled' => true,
'IsLive' => true,
'DeliveryMethod' => true,
'IsBasePolicy' => true
];

/**
* Has_many relationship
* @var array
Expand Down Expand Up @@ -432,15 +444,15 @@ public function setMergeFromPolicy(Policy $merge_from_policy)
*/
public function getPolicy($enabled = 1, $pretty = false)
{
$directives = $this->Directives();
$directives = $this->Directives()->sort("ID ASC");
if (!is_null($enabled)) {
$directives = $directives->filter('Enabled', (bool)$enabled);
}
$policy = "";

$merge_from_policy_directives = null;
if ($this->merge_from_policy instanceof Policy) {
$merge_from_policy_directives = $this->merge_from_policy->Directives();
$merge_from_policy_directives = $this->merge_from_policy->Directives()->sort("ID ASC");
if (!is_null($enabled)) {
$merge_from_policy_directives = $merge_from_policy_directives->filter('Enabled', (bool)$enabled);
}
Expand Down

0 comments on commit 17385f9

Please sign in to comment.