Skip to content

Commit

Permalink
WIP library access to campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
ammopt committed Nov 12, 2024
1 parent 8101e89 commit b67edf2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
47 changes: 47 additions & 0 deletions code/web/sys/Community/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_once ROOT_DIR . '/sys/Community/UserCampaign.php';
require_once ROOT_DIR . '/sys/Community/Reward.php';
require_once ROOT_DIR . '/sys/Community/CampaignPatronTypeAccess.php';
require_once ROOT_DIR . '/sys/Community/CampaignLibraryAccess.php';
require_once ROOT_DIR . '/sys/Account/User.php';


Expand All @@ -24,12 +25,14 @@ class Campaign extends DataObject {
private $_availableMilestones;

protected $_allowPatronTypeAccess;
protected $_allowLibraryAccess;

public static function getObjectStructure($context = ''): array {
$milestoneList = Milestone::getMilestoneList();
$milestoneStructure = CampaignMilestone::getObjectStructure($context);
unset($milestoneStructure['campaignId']);

$libraryList = Library::getLibraryList();
$patronTypeList = PType::getPatronTypeList();
$rewardList = Reward::getRewardList();
return [
Expand Down Expand Up @@ -99,6 +102,15 @@ public static function getObjectStructure($context = ''): array {
'values' => $patronTypeList,
'hideInLists' => false,
],
'libraries' => [
'property' => 'libraries',
'type' => 'multiSelect',
'listStyle' => 'checkboxSimple',
'label' => 'Libraries',
'description' => 'Define libraries that use these settings',
'values' => $libraryList,
'hideInLists' => true,
],
];
}

Expand All @@ -115,6 +127,19 @@ public function getPatronTypeAccess() {
return $this->_allowPatronTypeAccess;
}

public function getLibrariesAccess(): ?array {
if (!isset($this->_libraries) && $this->id) {
$this->_libraries = [];
$libraryLink = new CampaignLibraryAccess();
$libraryLink->campaignId = $this->id;
$libraryLink->find();
while ($libraryLink->fetch()) {
$this->_allowLibraryAccess[$libraryLink->libraryId] = $libraryLink->libraryId;
}
}
return $this->_allowLibraryAccess;
}

public function savePatronTypeAccess() {
if (isset($this->_allowPatronTypeAccess) && is_array($this->_allowPatronTypeAccess)) {
$this->clearPatronTypeAccess();
Expand All @@ -129,13 +154,35 @@ public function savePatronTypeAccess() {
}
}

public function saveLibraries() {
if (isset($this->_allowLibraryAccess) && is_array($this->_allowLibraryAccess)) {
$this->clearLibraryAccess();

foreach ($this->_allowLibraryAccess as $libraryId) {
$libraryLink = new CampaignLibraryAccess();

$libraryLink->campaignId = $this->id;
$libraryLink->libraryId = $libraryId;
$libraryLink->insert();
}
unset($this->_allowLibraryAccess);
}
}

private function clearPatronTypeAccess() {
//Delete links to the patron types
$link = new CampaignPatronTypeAccess();
$link->campaignId = $this->id;
return $link->delete(true);
}

private function clearLibraryAccess() {
//Delete links to the libraries
$libraryLink = new CampaignLibraryAccess();
$libraryLink->campaignId = $this->id;
return $libraryLink->delete(true);
}

public function getUsers() {
if (is_null($this->_users)) {
$this->_users = [];
Expand Down
9 changes: 9 additions & 0 deletions code/web/sys/Community/CampaignLibraryAccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php


class CampaignLibraryAccess extends DataObject {
public $__table = 'ce_campaign_library_access';
public $id;
public $campaignId;
public $libraryId;
}
11 changes: 11 additions & 0 deletions code/web/sys/DBMaintenance/community_engagement_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ function getCommunityEngagementUpdates() {
) ENGINE = InnoDB",
],
],
'create_campaign_library_access' => [
'title' => 'Create Campaign Library Access',
'description' => 'Add table for library campaign access',
'sql' => [
"CREATE TABLE ce_campaign_library_access (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
campaignId INT NOT NULL,
libraryId INT NOT NULL
) ENGINE = InnoDB",
],
],
'create_milestones' => [
'title' => 'Create Milestones',
'description' => 'Add table for milestones',
Expand Down

0 comments on commit b67edf2

Please sign in to comment.