X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fhistory%2Fsrc%2FPlugin%2Fviews%2Ffilter%2FHistoryUserTimestamp.php;fp=web%2Fcore%2Fmodules%2Fhistory%2Fsrc%2FPlugin%2Fviews%2Ffilter%2FHistoryUserTimestamp.php;h=92a57991ca7bfc7aa6c491542a61efeb1972b20f;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/web/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php new file mode 100644 index 000000000..92a57991c --- /dev/null +++ b/web/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php @@ -0,0 +1,99 @@ +get('exposed')) { + if (isset($this->options['expose']['label'])) { + $label = $this->options['expose']['label']; + } + else { + $label = $this->t('Has new content'); + } + $form['value'] = [ + '#type' => 'checkbox', + '#title' => $label, + '#default_value' => $this->value, + ]; + } + } + + public function query() { + // This can only work if we're authenticated in. + if (!\Drupal::currentUser()->isAuthenticated()) { + return; + } + + // Don't filter if we're exposed and the checkbox isn't selected. + if ((!empty($this->options['exposed'])) && empty($this->value)) { + return; + } + + // Hey, Drupal kills old history, so nodes that haven't been updated + // since HISTORY_READ_LIMIT are bzzzzzzzt outta here! + + $limit = REQUEST_TIME - HISTORY_READ_LIMIT; + + $this->ensureMyTable(); + $field = "$this->tableAlias.$this->realField"; + $node = $this->query->ensureTable('node_field_data', $this->relationship); + + $clause = ''; + $clause2 = ''; + if ($ces = $this->query->ensureTable('comment_entity_statistics', $this->relationship)) { + $clause = ("OR $ces.last_comment_timestamp > (***CURRENT_TIME*** - $limit)"); + $clause2 = "OR $field < $ces.last_comment_timestamp"; + } + + // NULL means a history record doesn't exist. That's clearly new content. + // Unless it's very very old content. Everything in the query is already + // type safe cause none of it is coming from outside here. + $this->query->addWhereExpression($this->options['group'], "($field IS NULL AND ($node.changed > (***CURRENT_TIME*** - $limit) $clause)) OR $field < $node.changed $clause2"); + } + + public function adminSummary() { + if (!empty($this->options['exposed'])) { + return $this->t('exposed'); + } + } + +}