2013-09-29 18:31:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Thomas Müller thomas.mueller@tmit.eu
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace OC;
|
|
|
|
|
|
|
|
|
|
|
|
use OCP\Activity\IConsumer;
|
2014-07-03 11:48:15 +00:00
|
|
|
use OCP\Activity\IExtension;
|
2013-10-09 16:06:21 +00:00
|
|
|
use OCP\Activity\IManager;
|
2013-09-29 18:31:12 +00:00
|
|
|
|
2013-10-09 16:06:21 +00:00
|
|
|
class ActivityManager implements IManager {
|
2013-09-29 18:31:12 +00:00
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @var \Closure[]
|
|
|
|
*/
|
2013-09-29 18:31:12 +00:00
|
|
|
private $consumers = array();
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @var \Closure[]
|
|
|
|
*/
|
|
|
|
private $extensions = array();
|
|
|
|
|
2013-09-29 18:31:12 +00:00
|
|
|
/**
|
|
|
|
* @param $app
|
|
|
|
* @param $subject
|
2013-10-09 16:06:21 +00:00
|
|
|
* @param $subjectParams
|
2013-09-29 18:31:12 +00:00
|
|
|
* @param $message
|
2013-10-09 16:06:21 +00:00
|
|
|
* @param $messageParams
|
2013-09-29 18:31:12 +00:00
|
|
|
* @param $file
|
|
|
|
* @param $link
|
2013-10-09 16:06:21 +00:00
|
|
|
* @param $affectedUser
|
|
|
|
* @param $type
|
|
|
|
* @param $priority
|
2013-09-29 18:31:12 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2013-10-09 16:06:21 +00:00
|
|
|
function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
|
2013-09-29 18:31:12 +00:00
|
|
|
foreach($this->consumers as $consumer) {
|
|
|
|
$c = $consumer();
|
|
|
|
if ($c instanceof IConsumer) {
|
2013-10-09 16:06:21 +00:00
|
|
|
try {
|
|
|
|
$c->receive(
|
|
|
|
$app,
|
|
|
|
$subject,
|
|
|
|
$subjectParams,
|
|
|
|
$message,
|
|
|
|
$messageParams,
|
|
|
|
$file,
|
|
|
|
$link,
|
|
|
|
$affectedUser,
|
|
|
|
$type,
|
|
|
|
$priority);
|
|
|
|
} catch (\Exception $ex) {
|
2014-04-21 13:44:54 +00:00
|
|
|
// TODO: log the exception
|
2013-10-09 16:06:21 +00:00
|
|
|
}
|
2013-09-29 18:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In order to improve lazy loading a closure can be registered which will be called in case
|
|
|
|
* activity consumers are actually requested
|
|
|
|
*
|
|
|
|
* $callable has to return an instance of OCA\Activity\IConsumer
|
|
|
|
*
|
|
|
|
* @param \Closure $callable
|
|
|
|
*/
|
|
|
|
function registerConsumer(\Closure $callable) {
|
|
|
|
array_push($this->consumers, $callable);
|
|
|
|
}
|
2013-10-09 16:06:21 +00:00
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* In order to improve lazy loading a closure can be registered which will be called in case
|
|
|
|
* activity consumers are actually requested
|
|
|
|
*
|
|
|
|
* $callable has to return an instance of OCA\Activity\IConsumer
|
|
|
|
*
|
|
|
|
* @param \Closure $callable
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function registerExtension(\Closure $callable) {
|
|
|
|
array_push($this->extensions, $callable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will return additional notification types as specified by other apps
|
|
|
|
*
|
|
|
|
* @param string $languageCode
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function getNotificationTypes($languageCode) {
|
|
|
|
$notificationTypes = array();
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$result = $c->getNotificationTypes($languageCode);
|
|
|
|
if (is_array($result)) {
|
|
|
|
$notificationTypes = array_merge($notificationTypes, $result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notificationTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $types
|
|
|
|
* @param string $filter
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function filterNotificationTypes($types, $filter) {
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$result = $c->filterNotificationTypes($types, $filter);
|
|
|
|
if (is_array($result)) {
|
|
|
|
$types = $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $method
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function getDefaultTypes($method) {
|
|
|
|
$defaultTypes = array();
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$types = $c->getDefaultTypes($method);
|
|
|
|
if (is_array($types)) {
|
|
|
|
$defaultTypes = array_merge($types, $defaultTypes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $defaultTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $app
|
|
|
|
* @param string $text
|
|
|
|
* @param array $params
|
|
|
|
* @param boolean $stripPath
|
|
|
|
* @param boolean $highlightParams
|
|
|
|
* @param string $languageCode
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
|
|
|
|
if (is_string($translation)) {
|
|
|
|
return $translation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $type
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getTypeIcon($type) {
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$icon = $c->getTypeIcon($type);
|
|
|
|
if (is_string($icon)) {
|
|
|
|
return $icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $activity
|
|
|
|
* @return integer|false
|
|
|
|
*/
|
|
|
|
function getGroupParameter($activity) {
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$parameter = $c->getGroupParameter($activity);
|
|
|
|
if ($parameter !== false) {
|
|
|
|
return $parameter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function getNavigation() {
|
|
|
|
$entries = array(
|
|
|
|
'apps' => array(),
|
|
|
|
'top' => array(),
|
|
|
|
);
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$additionalEntries = $c->getNavigation();
|
|
|
|
if (is_array($additionalEntries)) {
|
|
|
|
$entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']);
|
|
|
|
$entries['top'] = array_merge($entries['top'], $additionalEntries['top']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $filterValue
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function isFilterValid($filterValue) {
|
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
if ($c->isFilterValid($filterValue) === true) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $filter
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function getQueryForFilter($filter) {
|
2014-11-28 10:18:15 +00:00
|
|
|
|
|
|
|
$conditions = array();
|
|
|
|
$parameters = array();
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
foreach($this->extensions as $extension) {
|
|
|
|
$c = $extension();
|
|
|
|
if ($c instanceof IExtension) {
|
|
|
|
$result = $c->getQueryForFilter($filter);
|
|
|
|
if (is_array($result)) {
|
2014-11-28 10:18:15 +00:00
|
|
|
list($condition, $parameter) = $result;
|
|
|
|
if ($condition && is_array($parameter)) {
|
|
|
|
$conditions[] = $condition;
|
|
|
|
$parameters = array_merge($parameters, $parameter);
|
|
|
|
}
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-28 10:18:15 +00:00
|
|
|
if (empty($conditions)) {
|
|
|
|
return array(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
2013-09-29 18:31:12 +00:00
|
|
|
}
|