1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00
freshrss_ynh/sources/app/Models/Category.php

81 lines
1.7 KiB
PHP
Raw Normal View History

2014-07-23 15:52:50 +02:00
<?php
class FreshRSS_Category extends Minz_Model {
private $id = 0;
private $name;
private $nbFeed = -1;
private $nbNotRead = -1;
private $feeds = null;
2015-11-06 16:54:20 +01:00
private $hasFeedsWithError = false;
2014-07-23 15:52:50 +02:00
2015-02-08 18:55:48 +01:00
public function __construct($name = '', $feeds = null) {
$this->_name($name);
if (isset($feeds)) {
$this->_feeds($feeds);
2014-07-23 15:52:50 +02:00
$this->nbFeed = 0;
$this->nbNotRead = 0;
foreach ($feeds as $feed) {
$this->nbFeed++;
2015-02-08 18:55:48 +01:00
$this->nbNotRead += $feed->nbNotRead();
2015-11-06 16:54:20 +01:00
$this->hasFeedsWithError |= $feed->inError();
2014-07-23 15:52:50 +02:00
}
}
}
2015-02-08 18:55:48 +01:00
public function id() {
2014-07-23 15:52:50 +02:00
return $this->id;
}
2015-02-08 18:55:48 +01:00
public function name() {
2014-07-23 15:52:50 +02:00
return $this->name;
}
2015-02-08 18:55:48 +01:00
public function nbFeed() {
2014-07-23 15:52:50 +02:00
if ($this->nbFeed < 0) {
2015-02-08 18:55:48 +01:00
$catDAO = new FreshRSS_CategoryDAO();
$this->nbFeed = $catDAO->countFeed($this->id());
2014-07-23 15:52:50 +02:00
}
return $this->nbFeed;
}
2015-02-08 18:55:48 +01:00
public function nbNotRead() {
2014-07-23 15:52:50 +02:00
if ($this->nbNotRead < 0) {
2015-02-08 18:55:48 +01:00
$catDAO = new FreshRSS_CategoryDAO();
$this->nbNotRead = $catDAO->countNotRead($this->id());
2014-07-23 15:52:50 +02:00
}
return $this->nbNotRead;
}
2015-02-08 18:55:48 +01:00
public function feeds() {
2014-07-23 15:52:50 +02:00
if ($this->feeds === null) {
$feedDAO = FreshRSS_Factory::createFeedDao();
2015-02-08 18:55:48 +01:00
$this->feeds = $feedDAO->listByCategory($this->id());
2014-07-23 15:52:50 +02:00
$this->nbFeed = 0;
$this->nbNotRead = 0;
foreach ($this->feeds as $feed) {
$this->nbFeed++;
2015-02-08 18:55:48 +01:00
$this->nbNotRead += $feed->nbNotRead();
2015-11-06 16:54:20 +01:00
$this->hasFeedsWithError |= $feed->inError();
2014-07-23 15:52:50 +02:00
}
}
return $this->feeds;
}
2015-11-06 16:54:20 +01:00
public function hasFeedsWithError() {
return $this->hasFeedsWithError;
}
2015-02-08 18:55:48 +01:00
public function _id($value) {
2014-07-23 15:52:50 +02:00
$this->id = $value;
}
2015-02-08 18:55:48 +01:00
public function _name($value) {
$this->name = substr(trim($value), 0, 255);
2014-07-23 15:52:50 +02:00
}
2015-02-08 18:55:48 +01:00
public function _feeds($values) {
if (!is_array($values)) {
$values = array($values);
2014-07-23 15:52:50 +02:00
}
$this->feeds = $values;
}
}