diff --git a/index.php b/index.php index 8583d67..2e8431d 100644 --- a/index.php +++ b/index.php @@ -345,10 +345,19 @@ Router\get_action('refresh-all', function() { Router\get_action('feeds', function() { $empty_feeds = Model\get_empty_feeds(); - if (count($empty_feeds) > 0) { - $message = t('The following feeds are empty, there may be an error : ') . implode(', ', $empty_feeds); + + if (! empty($empty_feeds)) { + + $listing = array(); + + foreach ($empty_feeds as &$feed) { + $listing[] = '"'.$feed['title'].'"'; + } + + $message = t('The following feeds are empty, there is maybe an error: %s', implode(', ', $listing)); Session\flash_error($message); } + Response\html(Template\layout('feeds', array( 'feeds' => Model\get_feeds(), 'nothing_to_read' => Request\int_param('nothing_to_read'), diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 3acad94..cf73dc7 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,8 +1,8 @@ - 'Les abonnements suivants sont vides, il doit y avoir une erreur :', + 'The following feeds are empty, there is maybe an error: %s' => + 'Les abonnements suivants sont vides, il y a peut-être une erreur : %s', 'Items per page' => 'Nombre d\'éléments par page', 'Previous page' => 'Page précédente', 'Next page' => 'Page suivante', diff --git a/model.php b/model.php index 541cb7a..0489de3 100644 --- a/model.php +++ b/model.php @@ -247,28 +247,25 @@ function get_feed($feed_id) ->findOne(); } + function get_empty_feeds() { $feeds = \PicoTools\singleton('db') ->table('feeds') - ->gt('last_checked', 0) - ->asc('id') - ->listing('id', 'title'); - $ids = array_keys($feeds); + ->columns('feeds.id', 'feeds.title', 'COUNT(items.id) AS nb_items') + ->join('items', 'feed_id', 'id') + ->isNull('feeds.last_checked') + ->groupBy('items.feed_id') + ->findAll(); - // fake DISTINCT - $not_empty_feeds = \PicoTools\singleton('db') - ->table('items') - ->asc('feed_id') - ->listing('feed_id', 'feed_id'); - $not_empty_ids = array_keys($not_empty_feeds); + foreach ($feeds as $key => &$feed) { - $diff = array_diff($ids, $not_empty_ids); - $return = array(); - foreach ($diff as $id) { - $return[$id] = $feeds[$id]; + if ($feed['nb_items'] > 0) { + unset($feeds[$key]); + } } - return $return; + + return $feeds; } diff --git a/vendor/PicoDb/Database.php b/vendor/PicoDb/Database.php index c0094e9..3ec302a 100644 --- a/vendor/PicoDb/Database.php +++ b/vendor/PicoDb/Database.php @@ -38,7 +38,7 @@ class Database public function getLogMessages() { - return implode(', ', $this->logs); + return $this->logs; } diff --git a/vendor/PicoDb/Drivers/Sqlite.php b/vendor/PicoDb/Drivers/Sqlite.php index 7e276c0..6555e73 100644 --- a/vendor/PicoDb/Drivers/Sqlite.php +++ b/vendor/PicoDb/Drivers/Sqlite.php @@ -42,6 +42,7 @@ class Sqlite extends \PDO { public function escapeIdentifier($value) { + if (strpos($value, '.') !== false) return $value; return '"'.$value.'"'; } } \ No newline at end of file diff --git a/vendor/PicoDb/Table.php b/vendor/PicoDb/Table.php index 06f3484..0275c8a 100644 --- a/vendor/PicoDb/Table.php +++ b/vendor/PicoDb/Table.php @@ -14,6 +14,8 @@ class Table private $is_or_condition = false; private $columns = array(); private $values = array(); + private $distinct = false; + private $group_by = array(); private $db; @@ -134,6 +136,15 @@ class Table } + public function findAllByColumn($column) + { + $rq = $this->db->execute($this->buildSelectQuery(), $this->values); + if (false === $rq) return false; + + return $rq->fetchAll(\PDO::FETCH_COLUMN, 0); + } + + public function findOne() { $this->limit(1); @@ -158,11 +169,13 @@ class Table public function buildSelectQuery() { return sprintf( - 'SELECT %s FROM %s %s %s %s %s %s', + 'SELECT %s %s FROM %s %s %s %s %s %s %s', + $this->distinct ? 'DISTINCT' : '', empty($this->columns) ? '*' : implode(', ', $this->columns), $this->db->escapeIdentifier($this->table_name), implode(' ', $this->joins), $this->conditions(), + empty($this->group_by) ? '' : 'GROUP BY '.implode(', ', $this->group_by), $this->sql_order, $this->sql_limit, $this->sql_offset @@ -286,6 +299,13 @@ class Table } + public function groupBy() + { + $this->group_by = \func_get_args(); + return $this; + } + + public function columns() { $this->columns = \func_get_args(); @@ -293,20 +313,23 @@ class Table } + public function distinct() + { + $this->columns = \func_get_args(); + $this->distinct = true; + return $this; + } + + public function __call($name, array $arguments) { - if (2 !== count($arguments)) { - - throw new \LogicException('You must define a column and a value.'); - } - $column = $arguments[0]; $sql = ''; - switch ($name) { + switch (strtolower($name)) { case 'in': - if (is_array($arguments[1])) { + if (isset($arguments[1]) && is_array($arguments[1])) { $sql = sprintf( '%s IN (%s)', @@ -317,7 +340,7 @@ class Table break; case 'notin': - if (is_array($arguments[1])) { + if (isset($arguments[1]) && is_array($arguments[1])) { $sql = sprintf( '%s NOT IN (%s)', @@ -338,40 +361,50 @@ class Table break; case 'gt': - case 'greaterThan': + case 'greaterthan': $sql = sprintf('%s > ?', $this->db->escapeIdentifier($column)); break; case 'lt': - case 'lowerThan': + case 'lowerthan': $sql = sprintf('%s < ?', $this->db->escapeIdentifier($column)); break; case 'gte': - case 'greaterThanOrEquals': + case 'greaterthanorequals': $sql = sprintf('%s >= ?', $this->db->escapeIdentifier($column)); break; case 'lte': - case 'lowerThanOrEquals': + case 'lowerthanorequals': $sql = sprintf('%s <= ?', $this->db->escapeIdentifier($column)); break; + + case 'isnull': + $sql = sprintf('%s IS NULL', $this->db->escapeIdentifier($column)); + break; + + case 'notnull': + $sql = sprintf('%s IS NOT NULL', $this->db->escapeIdentifier($column)); + break; } - if ('' !== $sql) { + if ($sql !== '') { $this->addCondition($sql); - if (is_array($arguments[1])) { + if (isset($arguments[1])) { - foreach ($arguments[1] as $value) { + if (is_array($arguments[1])) { - $this->values[] = $value; + foreach ($arguments[1] as $value) { + $this->values[] = $value; + } } - } - else { + else { - $this->values[] = $arguments[1]; + $this->values[] = $arguments[1]; + } } }