aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Context.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2022-08-10 09:37:11 +0200
committerGravatar GitHub <noreply@github.com> 2022-08-10 09:37:11 +0200
commit09aeeeb3254b2b7ad6d588bc21223d567390ae58 (patch)
tree1682ba448e8ad309ffacc99d1cdb45f6365c5785 /app/Models/Context.php
parente86c10e2f554ba60e95f745b3b062262b37c7188 (diff)
Refactor updateContext into its own FreshRSS_Context class (#4496)
So that it is both cleaner and easier to call from other controllers and extensions
Diffstat (limited to 'app/Models/Context.php')
-rw-r--r--app/Models/Context.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/Models/Context.php b/app/Models/Context.php
index db8dd1f09..5b7c89089 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -144,6 +144,60 @@ class FreshRSS_Context {
}
/**
+ * This action updates the Context object by using request parameters.
+ *
+ * Parameters are:
+ * - state (default: conf->default_view)
+ * - search (default: empty string)
+ * - order (default: conf->sort_order)
+ * - nb (default: conf->posts_per_page)
+ * - next (default: empty string)
+ * - hours (default: 0)
+ */
+ public static function updateUsingRequest() {
+ if (empty(self::$categories)) {
+ $catDAO = FreshRSS_Factory::createCategoryDao();
+ self::$categories = $catDAO->listSortedCategories();
+ }
+
+ // Update number of read / unread variables.
+ $entryDAO = FreshRSS_Factory::createEntryDao();
+ self::$total_starred = $entryDAO->countUnreadReadFavorites();
+ self::$total_unread = FreshRSS_CategoryDAO::CountUnreads(
+ self::$categories, 1
+ );
+
+ self::_get(Minz_Request::param('get', 'a'));
+
+ self::$state = Minz_Request::param(
+ 'state', self::$user_conf->default_state
+ );
+ $state_forced_by_user = Minz_Request::param('state', false) !== false;
+ if (!$state_forced_by_user && !self::isStateEnabled(FreshRSS_Entry::STATE_READ)) {
+ if (self::$user_conf->default_view === 'adaptive' && self::$get_unread <= 0) {
+ self::$state |= FreshRSS_Entry::STATE_READ;
+ }
+ if (self::$user_conf->show_fav_unread &&
+ (self::isCurrentGet('s') || self::isCurrentGet('T') || self::isTag())) {
+ self::$state |= FreshRSS_Entry::STATE_READ;
+ }
+ }
+
+ self::$search = new FreshRSS_BooleanSearch(Minz_Request::param('search', ''));
+ self::$order = Minz_Request::param(
+ 'order', self::$user_conf->sort_order
+ );
+ self::$number = intval(Minz_Request::param('nb', self::$user_conf->posts_per_page));
+ if (self::$number > self::$user_conf->max_posts_per_rss) {
+ self::$number = max(
+ self::$user_conf->max_posts_per_rss,
+ self::$user_conf->posts_per_page);
+ }
+ self::$first_id = Minz_Request::param('next', '');
+ self::$sinceHours = intval(Minz_Request::param('hours', 0));
+ }
+
+ /**
* Returns if the current state includes $state parameter.
* @param int $state
*/