Skip to content

Commit 52cd3f4

Browse files
[5.4] Add checkedout filter to the Article Manager (joomla#45761)
* API filter articles by their checked out status and user * Administrator backend with checked out article filter
1 parent 283a4c5 commit 52cd3f4

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

administrator/components/com_content/forms/filter_articles.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@
8989
<option value="*">JALL</option>
9090
</field>
9191

92+
<field
93+
name="checked_out"
94+
type="list"
95+
label="COM_CONTENT_CHECKED_OUT"
96+
class="js-select-submit-on-change"
97+
default=""
98+
validate="options"
99+
>
100+
<option value="">COM_CONTENT_SELECT_CHECKED_OUT</option>
101+
<option value="0">COM_CONTENT_FILTER_CHECKED_OUT_NO</option>
102+
<option value="-1">COM_CONTENT_FILTER_CHECKED_OUT_YES</option>
103+
</field>
104+
92105
<field
93106
name="tag"
94107
type="tag"

administrator/components/com_content/src/Model/ArticlesModel.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
145145
$this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');
146146
$this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
147147
$this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
148+
$this->getUserStateFromRequest($this->context . '.filter.checked_out', 'filter_checked_out', '');
148149

149150
// List state information.
150151
parent::populateState($ordering, $direction);
@@ -179,6 +180,7 @@ protected function getStoreId($id = '')
179180
$id .= ':' . serialize($this->getState('filter.author_id'));
180181
$id .= ':' . $this->getState('filter.language');
181182
$id .= ':' . serialize($this->getState('filter.tag'));
183+
$id .= ':' . $this->getState('filter.checked_out');
182184

183185
return parent::getStoreId($id);
184186
}
@@ -482,6 +484,24 @@ protected function getListQuery()
482484
->bind(':language', $language);
483485
}
484486

487+
// Filter by checked out status.
488+
$checkedOut = $this->getState('filter.checked_out');
489+
490+
if (is_numeric($checkedOut)) {
491+
if ($checkedOut == -1) {
492+
// Only checked out articles
493+
$query->where($db->quoteName('a.checked_out') . ' > 0');
494+
} elseif ($checkedOut == 0) {
495+
// Only not checked out articles (checked_out is 0 or NULL)
496+
$query->where('(' . $db->quoteName('a.checked_out') . ' = 0 OR ' . $db->quoteName('a.checked_out') . ' IS NULL)');
497+
} else {
498+
// Checked out by specific user
499+
$checkedOut = (int) $checkedOut;
500+
$query->where($db->quoteName('a.checked_out') . ' = :checkedOutUser')
501+
->bind(':checkedOutUser', $checkedOut, ParameterType::INTEGER);
502+
}
503+
}
504+
485505
// Filter by a single or group of tags.
486506
$tag = $this->getState('filter.tag');
487507

administrator/language/en-GB/com_content.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COM_CONTENT_BATCH_OPTIONS="Batch process the selected articles"
1414
COM_CONTENT_BATCH_TIP="If a category is selected for move/copy, any actions selected will be applied to the copied or moved articles. Otherwise, all actions are applied to the selected articles."
1515
COM_CONTENT_CHANGE_STAGE="Change stage"
1616
COM_CONTENT_CHANGE_STAGE_AMBIGUOUS_TRANSITIONS="Some transitions are ambiguous for this condition. Please select your preferred transition and proceed."
17+
COM_CONTENT_CHECKED_OUT="Checked Out"
1718
COM_CONTENT_CONFIG_ARTICLE_SETTINGS_DESC="These settings apply for article layouts unless they are changed for a specific menu item or article."
1819
COM_CONTENT_CONFIG_BLOG_SETTINGS_DESC="These settings apply for blog or featured layouts unless they are changed for a specific menu item."
1920
COM_CONTENT_CONFIG_BLOG_SETTINGS_LABEL="Blog/Featured Layouts"
@@ -104,6 +105,8 @@ COM_CONTENT_FIELDSET_PUBLISHING="Publishing"
104105
COM_CONTENT_FIELDSET_RULES="Permissions"
105106
COM_CONTENT_FIELDSET_URLS_AND_IMAGES="Images and Links"
106107
COM_CONTENT_FILTER_AUTHORS_BY_ME="- Created by me -"
108+
COM_CONTENT_FILTER_CHECKED_OUT_NO="Not Checked Out"
109+
COM_CONTENT_FILTER_CHECKED_OUT_YES="Checked Out"
107110
COM_CONTENT_FILTER_FEATURED_NO="Unfeatured Articles"
108111
COM_CONTENT_FILTER_FEATURED_YES="Featured Articles"
109112
COM_CONTENT_FILTER_SEARCH_DESC="Search in title, alias and note. Prefix with ID: or AUTHOR: or CONTENT: to search for an article ID, article author or search in article content. Prefix with CHECKEDOUT: to search for content checked out by a specified user."
@@ -165,6 +168,7 @@ COM_CONTENT_RUN_TRANSITIONS="Run Transitions"
165168
COM_CONTENT_SAVE_SUCCESS="Article saved."
166169
COM_CONTENT_SAVE_WARNING="Alias already existed so a number was added at the end. You can re-edit the article to customise the alias."
167170
COM_CONTENT_SELECT_AN_ARTICLE="Select an Article"
171+
COM_CONTENT_SELECT_CHECKED_OUT="- Select Checked Out -"
168172
COM_CONTENT_SELECT_FEATURED="- Select Featured -"
169173
COM_CONTENT_SHARED_DESC="These settings apply for Shared Options in List, Blog and Featured unless they are changed by the menu settings."
170174
COM_CONTENT_SHARED_LABEL="Shared"

api/components/com_content/src/Controller/ArticlesController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function displayList()
8282
$this->modelState->set('filter.language', $filter->clean($apiFilterInfo['language'], 'STRING'));
8383
}
8484

85+
if (\array_key_exists('checked_out', $apiFilterInfo)) {
86+
$this->modelState->set('filter.checked_out', $filter->clean($apiFilterInfo['checked_out'], 'INT'));
87+
}
88+
8589
$apiListInfo = $this->input->get('list', [], 'array');
8690

8791
if (\array_key_exists('ordering', $apiListInfo)) {

components/com_content/src/Model/ArticlesModel.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,24 @@ protected function getListQuery()
491491
$query->where($authorWhere . $authorAliasWhere);
492492
}
493493

494+
// Filter by checked_out status
495+
$checkedOut = $this->getState('filter.checked_out', null);
496+
497+
if (is_numeric($checkedOut)) {
498+
if ($checkedOut == -1) {
499+
// Only checked out articles
500+
$query->where($db->quoteName('a.checked_out') . ' > 0');
501+
} elseif ($checkedOut == 0) {
502+
// Only not checked out articles
503+
$query->where('(' . $db->quoteName('a.checked_out') . ' = 0 OR ' . $db->quoteName('a.checked_out') . ' IS NULL)');
504+
} else {
505+
// Checked out by specific user
506+
$checkedOut = (int) $checkedOut;
507+
$query->where($db->quoteName('a.checked_out') . ' = :checkedOutUser')
508+
->bind(':checkedOutUser', $checkedOut, ParameterType::INTEGER);
509+
}
510+
}
511+
494512
// Filter by start and end dates.
495513
if (
496514
!(is_numeric($condition) && $condition == ContentComponent::CONDITION_UNPUBLISHED)

0 commit comments

Comments
 (0)