Skip to content

Commit

Permalink
Add list(id) type of conditional field
Browse files Browse the repository at this point in the history
  • Loading branch information
ammopt committed Nov 6, 2024
1 parent 561cb14 commit 870ce68
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion code/web/sys/Community/Milestone.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static function getObjectStructure($context = ''): array {
'values' => [
'user_checkout' => 'Checkout',
'user_hold' => 'Hold',
'user_list' => 'List',
'user_work_review' => 'Rating',
],
'onchange' => 'updateConditionalField(this.value)',
Expand All @@ -53,6 +52,7 @@ public static function getObjectStructure($context = ''): array {
'title_display' => 'Title',
'author_display' => 'Author',
'subject_facet' => 'Subject',
'user_list' => 'List (id)',
// 'hold_title' => 'Title',
// 'hold_author' => 'Author',
// 'list_id' => 'List Name',
Expand Down Expand Up @@ -225,6 +225,10 @@ protected function conditionalsCheck($object)
if (!$object->groupedWorkId)
return false;

if( $this->conditionalField == 'user_list' && is_numeric($this->conditionalValue) ) {
return $this->conditionalsListCheck($object);
}

require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
$groupedWorkDriver = new GroupedWorkDriver($object->groupedWorkId);

Expand Down Expand Up @@ -262,6 +266,23 @@ protected function conditionalsCheck($object)
return false;
}

/**
* Checks if a grouped work is on a certain list.
*
* @param $object The grouped work object to check.
*
* @return bool true if the grouped work is on the list, false otherwise.
*/
protected function conditionalsListCheck($object){
require_once ROOT_DIR . '/sys/UserLists/UserListEntry.php';
$listEntry = new UserListEntry();
$listEntry->whereAdd("source ='GroupedWork'");
$listEntry->whereAdd("sourceId ='" . $object->groupedWorkId . "'");
$whereOp = $this->conditionalOperator == 'is_not' ? '!=' : '=';
$listEntry->whereAdd('listId '.$whereOp. ' ' . $this->conditionalValue);
return $listEntry->find(true);
}

/**
* @return array
*/
Expand Down

0 comments on commit 870ce68

Please sign in to comment.