2017-01-24 09:47:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
|
|
|
* @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Core\Controller;
|
|
|
|
|
|
|
|
use OC\Contacts\ContactsMenu\Manager;
|
|
|
|
use OCP\AppFramework\Controller;
|
2017-04-24 12:39:03 +03:00
|
|
|
use OCP\AppFramework\Http;
|
2017-01-24 09:47:14 +03:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\IRequest;
|
2017-04-03 19:04:14 +03:00
|
|
|
use OCP\IUserSession;
|
2017-01-24 09:47:14 +03:00
|
|
|
|
|
|
|
class ContactsMenuController extends Controller {
|
|
|
|
|
|
|
|
/** @var Manager */
|
|
|
|
private $manager;
|
|
|
|
|
2017-04-03 19:04:14 +03:00
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
2017-01-24 09:47:14 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IRequest $request
|
2017-04-03 19:04:14 +03:00
|
|
|
* @param IUserSession $userSession
|
2017-01-24 09:47:14 +03:00
|
|
|
* @param Manager $manager
|
|
|
|
*/
|
2017-04-03 19:04:14 +03:00
|
|
|
public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
|
2017-01-24 09:47:14 +03:00
|
|
|
parent::__construct('core', $request);
|
2017-04-03 19:04:14 +03:00
|
|
|
$this->userSession = $userSession;
|
2017-01-24 09:47:14 +03:00
|
|
|
$this->manager = $manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string|null filter
|
2017-07-19 17:30:17 +03:00
|
|
|
* @return \JsonSerializable[]
|
2017-01-24 09:47:14 +03:00
|
|
|
*/
|
|
|
|
public function index($filter = null) {
|
2017-04-03 19:04:14 +03:00
|
|
|
return $this->manager->getEntries($this->userSession->getUser(), $filter);
|
2017-01-24 09:47:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-24 12:39:03 +03:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param integer $shareType
|
|
|
|
* @param string $shareWith
|
2017-07-19 17:30:17 +03:00
|
|
|
* @return JSONResponse|\JsonSerializable
|
2017-04-24 12:39:03 +03:00
|
|
|
*/
|
|
|
|
public function findOne($shareType, $shareWith) {
|
|
|
|
$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
|
|
|
|
|
|
|
|
if ($contact) {
|
|
|
|
return $contact;
|
|
|
|
}
|
2017-07-19 17:30:17 +03:00
|
|
|
return new JSONResponse([], Http::STATUS_NOT_FOUND);
|
2017-04-24 12:39:03 +03:00
|
|
|
}
|
2017-01-24 09:47:14 +03:00
|
|
|
}
|