tasks/lib/Service/CollectionsService.php

126 lines
3.1 KiB
PHP
Raw Normal View History

2015-06-23 10:08:52 +00:00
<?php
2015-07-19 12:05:29 +00:00
/**
* Nextcloud - Tasks
2015-07-19 12:05:29 +00:00
*
* @author Raimund Schlüßler
2018-08-19 20:33:26 +00:00
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
2015-07-19 12:05:29 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
2015-07-19 12:05:29 +00:00
2015-06-23 10:08:52 +00:00
namespace OCA\Tasks\Service;
use OCP\IConfig;
2016-03-08 22:20:46 +00:00
use OCP\IL10N;
2015-06-23 10:08:52 +00:00
class CollectionsService {
2019-01-26 20:47:53 +00:00
/**
* @var string
*/
2015-06-23 10:08:52 +00:00
private $userId;
2019-01-26 20:47:53 +00:00
/**
* @var IL10N
*/
2015-06-23 10:08:52 +00:00
private $l10n;
2019-01-26 20:47:53 +00:00
/**
* @var IConfig
*/
2015-06-23 10:08:52 +00:00
private $settings;
2019-01-26 20:47:53 +00:00
/**
* @var string
*/
2015-06-23 10:08:52 +00:00
private $appName;
2019-01-26 20:47:53 +00:00
/**
* @param string $userId
* @param IL10N $l10n
* @param IConfig $settings
* @param string $appName
*/
public function __construct(string $userId, IL10N $l10n, IConfig $settings, string $appName) {
2015-06-23 10:08:52 +00:00
$this->userId = $userId;
$this->l10n = $l10n;
$this->settings = $settings;
$this->appName = $appName;
}
/**
2019-01-26 20:47:53 +00:00
* Get all collections
2015-06-23 10:08:52 +00:00
*
* @return array
*/
2019-01-26 20:47:53 +00:00
public function getAll():array {
2015-06-23 10:08:52 +00:00
$collections = array(
array(
'id' => "starred",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('Important'),
'show' => 2,
'icon' => 'icon-task-star'),
2015-06-23 10:08:52 +00:00
array(
'id' => "today",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('Today'),
'show' => 2,
'icon' => 'icon-calendar'),
2015-06-23 10:08:52 +00:00
array(
'id' => "week",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('Week'),
'show' => 2,
'icon' => 'icon-calendar'),
2015-06-23 10:08:52 +00:00
array(
'id' => "all",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('All'),
'show' => 2,
'icon' => 'icon-all'),
2015-06-23 10:08:52 +00:00
array(
'id' => "current",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('Current'),
'show' => 2,
'icon' => 'icon-current'),
2015-06-23 10:08:52 +00:00
array(
'id' => "completed",
2018-11-01 19:06:41 +00:00
'displayName' => (string)$this->l10n->t('Completed'),
'show' => 2,
'icon' => 'icon-checkmark')
2015-06-23 10:08:52 +00:00
);
foreach ($collections as $key => $collection){
2015-07-19 12:05:29 +00:00
$tmp = $this->settings->getUserValue($this->userId, $this->appName,'show_'.$collection['id']);
if (!in_array($tmp, array('0','1','2'))) {
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collection['id'],$collections[$key]['show']);
} else {
$collections[$key]['show'] = (int)$tmp;
2015-06-23 10:08:52 +00:00
}
}
return $collections;
}
/**
2019-01-26 20:47:53 +00:00
* Set the visibility of a collection by collectionID
2015-06-23 10:08:52 +00:00
*
2019-01-26 20:47:53 +00:00
* @param string $collectionID
2015-06-23 10:08:52 +00:00
* @param int $visibility
* @return bool
*/
2019-01-26 20:47:53 +00:00
public function setVisibility(string $collectionID, int $visibility):bool {
2015-06-23 10:08:52 +00:00
if (in_array($visibility, array(0,1,2))){
2015-07-19 12:05:29 +00:00
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collectionID,$visibility);
2015-06-23 10:08:52 +00:00
}
return true;
}
2015-07-19 12:05:29 +00:00
}