mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-29 23:51:04 -05:00
* PDO refactor * Automatic prefix when using the syntax `_tableName` * Uniformity: MySQL is now PDO::ATTR_EMULATE_PREPARES = false just like SQLite and PostgreSQL, with consequences such as only one statement per query * Use PDO methods exec(), query(), prepare() + execute() in a more efficient way * Remove auto-update SQL code for versions older than FreshRSS 1.5 (3 years old) * The name of the default category is set in PHP instead of in the DB (simplies SQL and allows changing the name according to the FreshRSS language) * Rename `->bd` to `->pdo` (less of a frenshism, and more informative) * Fix some requests, which were not compatible with MySQL prepared statements * Whitespace * Fix syntax for PostgreSQL sequences + MySQL install * Minor formatting * Fix lastInsertId for PostgreSQL * Use PHP 5.6+ const Take advantage of https://github.com/FreshRSS/FreshRSS/pull/2527 https://www.php.net/manual/en/migration56.new-features.php * A bit of forgotten PHP 5.6 simplification for cURL * Forgotten $s * Mini fix custom user config https://github.com/FreshRSS/FreshRSS/pull/2490/files#r326290346 * More work on install.php but not finished * install.php working * More cleaning of PDO in install * Even more simplification Take advantage of PDO->exec() to run multiple statements * Disallow changing the name of the default category https://github.com/FreshRSS/FreshRSS/pull/2522#discussion_r326967724
91 lines
2.0 KiB
PHP
91 lines
2.0 KiB
PHP
<?php
|
|
|
|
class FreshRSS_Category extends Minz_Model {
|
|
private $id = 0;
|
|
private $name;
|
|
private $nbFeed = -1;
|
|
private $nbNotRead = -1;
|
|
private $feeds = null;
|
|
private $hasFeedsWithError = false;
|
|
private $isDefault = false;
|
|
|
|
public function __construct($name = '', $feeds = null) {
|
|
$this->_name($name);
|
|
if (isset($feeds)) {
|
|
$this->_feeds($feeds);
|
|
$this->nbFeed = 0;
|
|
$this->nbNotRead = 0;
|
|
foreach ($feeds as $feed) {
|
|
$this->nbFeed++;
|
|
$this->nbNotRead += $feed->nbNotRead();
|
|
$this->hasFeedsWithError |= $feed->inError();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function id() {
|
|
return $this->id;
|
|
}
|
|
public function name() {
|
|
return $this->name;
|
|
}
|
|
public function isDefault() {
|
|
return $this->isDefault;
|
|
}
|
|
public function nbFeed() {
|
|
if ($this->nbFeed < 0) {
|
|
$catDAO = FreshRSS_Factory::createCategoryDao();
|
|
$this->nbFeed = $catDAO->countFeed($this->id());
|
|
}
|
|
|
|
return $this->nbFeed;
|
|
}
|
|
public function nbNotRead() {
|
|
if ($this->nbNotRead < 0) {
|
|
$catDAO = FreshRSS_Factory::createCategoryDao();
|
|
$this->nbNotRead = $catDAO->countNotRead($this->id());
|
|
}
|
|
|
|
return $this->nbNotRead;
|
|
}
|
|
public function feeds() {
|
|
if ($this->feeds === null) {
|
|
$feedDAO = FreshRSS_Factory::createFeedDao();
|
|
$this->feeds = $feedDAO->listByCategory($this->id());
|
|
$this->nbFeed = 0;
|
|
$this->nbNotRead = 0;
|
|
foreach ($this->feeds as $feed) {
|
|
$this->nbFeed++;
|
|
$this->nbNotRead += $feed->nbNotRead();
|
|
$this->hasFeedsWithError |= $feed->inError();
|
|
}
|
|
}
|
|
|
|
return $this->feeds;
|
|
}
|
|
|
|
public function hasFeedsWithError() {
|
|
return $this->hasFeedsWithError;
|
|
}
|
|
|
|
public function _id($id) {
|
|
$this->id = $id;
|
|
if ($id == FreshRSS_CategoryDAO::DEFAULTCATEGORYID) {
|
|
$this->_name(_t('gen.short.default_category'));
|
|
}
|
|
}
|
|
public function _name($value) {
|
|
$this->name = trim($value);
|
|
}
|
|
public function _isDefault($value) {
|
|
$this->isDefault = $value;
|
|
}
|
|
public function _feeds($values) {
|
|
if (!is_array($values)) {
|
|
$values = array($values);
|
|
}
|
|
|
|
$this->feeds = $values;
|
|
}
|
|
}
|