mirror of
https://github.com/flextype/flextype.git
synced 2025-08-23 13:23:18 +02:00
refactor(core): refactor entries fetch methods naming #315
We have: fetch - for single and collection entries request. fetchSingle - for single entry request. fetchCollection - for collection entries request. Important: fetchAll - should be removed. BREAKING CHANGES method fetchAll removed! please use fetch, fetchSingle or fetchCollection.
This commit is contained in:
@@ -104,16 +104,36 @@ class Entries
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch entry(enries)
|
||||
*
|
||||
* @param string $id Entry ID
|
||||
* @param array|null $args Query arguments.
|
||||
*
|
||||
* @return array The entry array data.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id, $args = null) : array
|
||||
{
|
||||
// If args is array then it is entries collection request
|
||||
if (is_array($args)) {
|
||||
return $this->fetchCollection($id, $args);
|
||||
} else {
|
||||
return $this->fetchSingle($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch single entry
|
||||
*
|
||||
* @param string $id Entry ID
|
||||
*
|
||||
* @return array|false The entry array data or false on failure.
|
||||
* @return array The entry array data.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
public function fetchSingle(string $id) : array
|
||||
{
|
||||
// Get entry file location
|
||||
$entry_file = $this->getFileLocation($id);
|
||||
@@ -139,7 +159,8 @@ class Entries
|
||||
return $entry;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Return empty array
|
||||
return [];
|
||||
|
||||
// else Try to get requested entry from the filesystem
|
||||
}
|
||||
@@ -170,19 +191,21 @@ class Entries
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch entries collection
|
||||
*
|
||||
* @param array $args Query arguments
|
||||
* @param string $id Entry ID
|
||||
* @param array $args Query arguments.
|
||||
*
|
||||
* @return array The entries array data
|
||||
* @return array The entries array data.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetchAll(string $id, array $args = []) : array
|
||||
public function fetchCollection(string $id, array $args = []) : array
|
||||
{
|
||||
// Init Entries
|
||||
$entries = [];
|
||||
|
@@ -53,19 +53,27 @@ class EntriesTwig
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch entry(entries)
|
||||
*/
|
||||
public function fetch(string $id, $args = null) : array
|
||||
{
|
||||
return $this->flextype['entries']->fetch($id, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch single entry
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
public function fetchSingle(string $id) : array
|
||||
{
|
||||
return $this->flextype['entries']->fetch($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all entries
|
||||
* Fetch entries collection
|
||||
*/
|
||||
public function fetchAll(string $id, array $args = []) : array
|
||||
public function fetchCollection(string $id, array $args = []) : array
|
||||
{
|
||||
return $this->flextype['entries']->fetchAll($id, $args);
|
||||
return $this->flextype['entries']->fetch($id, $args);
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ class EntriesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/content/entries/index.html',
|
||||
[
|
||||
'entries_list' => $this->entries->fetchAll($this->getEntryID($query), ['order_by' => ['field' => 'published_at', 'direction' => 'desc']]),
|
||||
'entries_list' => $this->entries->fetch($this->getEntryID($query), ['order_by' => ['field' => 'published_at', 'direction' => 'desc']]),
|
||||
'id_current' => $this->getEntryID($query),
|
||||
'menu_item' => 'entries',
|
||||
'parts' => $parts,
|
||||
@@ -144,7 +144,7 @@ class EntriesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/content/entries/add.html',
|
||||
[
|
||||
'entries_list' => $this->entries->fetchAll($this->getEntryID($query), ['order_by' => ['field' => 'title', 'direction' => 'asc']]),
|
||||
'entries_list' => $this->entries->fetch($this->getEntryID($query), ['order_by' => ['field' => 'title', 'direction' => 'asc']]),
|
||||
'menu_item' => 'entries',
|
||||
'fieldsets' => $fieldsets,
|
||||
'current_id' => $this->getEntryID($query),
|
||||
@@ -399,7 +399,7 @@ class EntriesController extends Controller
|
||||
|
||||
// Get entries list
|
||||
$entries_list['/'] = '/';
|
||||
foreach ($this->entries->fetchAll('', ['order_by' => ['field' => ['slug']], 'recursive' => true]) as $_entry) {
|
||||
foreach ($this->entries->fetch('', ['order_by' => ['field' => ['slug']], 'recursive' => true]) as $_entry) {
|
||||
if ($_entry['slug'] != '') {
|
||||
$entries_list[$_entry['slug']] = $_entry['slug'];
|
||||
} else {
|
||||
|
@@ -32,7 +32,7 @@ class SettingsController extends Controller
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
$entries = [];
|
||||
foreach ($this->entries->fetchAll('', ['order_by' => ['field' => 'published_at', 'direction' => 'desc']]) as $entry) {
|
||||
foreach ($this->entries->fetch('', ['order_by' => ['field' => 'published_at', 'direction' => 'desc']]) as $entry) {
|
||||
$entries[$entry['slug']] = $entry['title'];
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@
|
||||
{% if cache.contains(entry.slug ~ '_counter') %}
|
||||
{% set _entries_length = cache.fetch(entry.slug ~ '_counter') %}
|
||||
{% else %}
|
||||
{% set _entries = entries.fetchAll(entry.slug) %}
|
||||
{% set _entries = entries.fetch(entry.slug, {}) %}
|
||||
{% set _entries_length = _entries|length %}
|
||||
{% do cache.save(entry.slug ~ '_counter', _entries_length) %}
|
||||
{% endif %}
|
||||
|
@@ -36,7 +36,7 @@
|
||||
</button>
|
||||
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
{% for item in entries.fetchAll('', {'order_by': {'field': 'menu_item_order', 'direction': 'asc'}}) %}
|
||||
{% for item in entries.fetch('', {'order_by': {'field': 'menu_item_order', 'direction': 'asc'}}) %}
|
||||
{% if item.menu_item_title %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if item.menu_item_url in entry.slug %}active{% endif %}" href="{{ base_url() }}/{{ item.menu_item_url }}">{{ item.menu_item_title }}</a>
|
||||
|
Reference in New Issue
Block a user