1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Align controllers to owncloud/core#8017

This commit is contained in:
Thomas Tanghus 2014-04-07 22:29:15 +02:00
parent a1e16fec23
commit 70438c997d
11 changed files with 127 additions and 77 deletions

View File

@ -36,10 +36,8 @@ class Controller extends BaseController {
*/
protected $app;
public function __construct(IAppContainer $container, App $app) {
$this->api = $container->query('API');
$this->request = $container->query('Request');
$this->server = $container->getServer();
public function __construct($appName, IRequest $request, App $app) {
parent::__construct($appName, $request);
$this->app = $app;
}

View File

@ -14,13 +14,21 @@ use OCA\Contacts\App,
OCA\Contacts\ImageResponse,
OCA\Contacts\Utils\Properties,
OCA\Contacts\Utils\TemporaryPhoto,
OCA\Contacts\Controller;
OCA\Contacts\Controller,
OCP\IRequest,
OCP\ICache;
/**
* Controller class For Contacts
*/
class ContactPhotoController extends Controller {
public function __construct($appName, IRequest $request, App $app, ICache $cache) {
parent::__construct($appName, $request);
$this->app = $app;
$this->cache = $cache;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
@ -34,7 +42,7 @@ class ContactPhotoController extends Controller {
$contact = $addressBook->getChild($params['contactId']);
$tempPhoto = TemporaryPhoto::create(
$this->server,
$this->cache,
TemporaryPhoto::PHOTO_CURRENT,
$contact
);

View File

@ -13,37 +13,44 @@ namespace OCA\Contacts\Controller;
use OCA\Contacts\App,
OCA\Contacts\JSONResponse,
OCA\Contacts\Controller,
OCP\AppFramework\Http;
OCP\AppFramework\Http,
OCP\ITags,
OCP\IRequest;
/**
* Controller class for groups/categories
*/
class GroupController extends Controller {
public function __construct($appName, IRequest $request, App $app, ITags $tags) {
parent::__construct($appName, $request, $app);
$this->app = $app;
$this->tagMgr = $tags;
}
/**
* @NoAdminRequired
*/
public function getGroups() {
$tagMgr = $this->server->getTagManager()->load('contact');
$tags = $tagMgr->getTags();
$tags = $this->tagMgr->getTags();
foreach ($tags as &$tag) {
try {
$ids = $tagMgr->getIdsForTag($tag['name']);
$ids = $this->tagMgr->getIdsForTag($tag['name']);
$tag['contacts'] = $ids;
} catch(\Exception $e) {
$this->api->log(__METHOD__ . ' ' . $e->getMessage());
}
}
$favorites = $tagMgr->getFavorites();
$favorites = $this->tagMgr->getFavorites();
$groups = array(
'categories' => $tags,
'favorites' => $favorites,
'shared' => \OCP\Share::getItemsSharedWith('addressbook', \OCA\Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS),
'lastgroup' => \OCP\Config::getUserValue($this->api->getUserId(), 'contacts', 'lastgroup', 'all'),
'sortorder' => \OCP\Config::getUserValue($this->api->getUserId(), 'contacts', 'groupsort', ''),
'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'),
'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''),
);
return new JSONResponse($groups);
@ -61,8 +68,7 @@ class GroupController extends Controller {
$response->bailOut(App::$l10n->t('No group name given.'));
}
$tagMgr = $this->server->getTagManager()->load('contact');
$id = $tagMgr->add($name);
$id = $this->tagMgr->add($name);
if ($id === false) {
$response->bailOut(App::$l10n->t('Error adding group.'));
@ -85,10 +91,8 @@ class GroupController extends Controller {
return $response;
}
$tagMgr = $this->server->getTagManager()->load('contact');
try {
$ids = $tagMgr->getIdsForTag($name);
$ids = $this->tagMgr->getIdsForTag($name);
} catch(\Exception $e) {
$response->setErrorMessage($e->getMessage());
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
@ -124,7 +128,7 @@ class GroupController extends Controller {
}
try {
$tagMgr->delete($name);
$this->tagMgr->delete($name);
} catch(\Exception $e) {
$response->setErrorMessage($e->getMessage());
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
@ -152,14 +156,12 @@ class GroupController extends Controller {
return $response;
}
$tagMgr = $this->server->getTagManager()->load('contact');
if (!$tagMgr->rename($from, $to)) {
if (!$this->tagMgr->rename($from, $to)) {
$response->bailOut(App::$l10n->t('Error renaming group.'));
return $response;
}
$ids = $tagMgr->getIdsForTag($to);
$ids = $this->tagMgr->getIdsForTag($to);
if ($ids !== false) {
@ -225,7 +227,6 @@ class GroupController extends Controller {
}
$backend = $this->app->getBackend('local');
$tagMgr = $this->server->getTagManager()->load('contact');
foreach ($ids as $contactId) {
@ -244,7 +245,7 @@ class GroupController extends Controller {
}
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
$tagMgr->tagAs($contactId, $categoryId);
$this->tagMgr->tagAs($contactId, $categoryId);
}
return $response;
@ -283,7 +284,6 @@ class GroupController extends Controller {
}
$backend = $this->app->getBackend('local');
$tagMgr = $this->server->getTagManager()->load('contact');
foreach ($ids as $contactId) {
@ -314,7 +314,7 @@ class GroupController extends Controller {
}
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
$tagMgr->unTag($contactId, $categoryId);
$this->tagMgr->unTag($contactId, $categoryId);
}
return $response;

View File

@ -15,13 +15,20 @@ use OCA\Contacts\App,
OCA\Contacts\Controller,
Sabre\VObject,
OCA\Contacts\VObject\VCard as MyVCard,
OCA\Contacts\ImportManager;
OCA\Contacts\ImportManager,
OCP\IRequest;
/**
* Controller importing contacts
*/
class ImportController extends Controller {
public function __construct($appName, IRequest $request, App $app, ICache $cache) {
parent::__construct($appName, $request);
$this->app = $app;
$this->cache = $cache;
}
/**
* @NoAdminRequired
*/
@ -150,7 +157,7 @@ class ImportController extends Controller {
$request = $this->request;
$response = new JSONResponse();
$params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$app = new App(\OCP\User::getUser());
$addressBookId = $params['addressBookId'];
$format = $params['importType'];
@ -186,16 +193,16 @@ class ImportController extends Controller {
\OC_FileProxy::$enabled = $proxyStatus;
$writeProgress = function($pct, $total) use ($progresskey) {
\OC_Cache::set($progresskey, $pct, 300);
\OC_Cache::set($progresskey.'_total', $total, 300);
$this->cache->set($progresskey, $pct, 300);
$this->cache->set($progresskey.'_total', $total, 300);
};
$cleanup = function() use ($view, $filename, $progresskey, $response) {
if(!$view->unlink('/imports/' . $filename)) {
$response->debug('Unable to unlink /imports/' . $filename);
}
\OC_Cache::remove($progresskey);
\OC_Cache::remove($progresskey.'_total');
$this->cache->remove($progresskey);
$this->cache->remove($progresskey.'_total');
};
$importManager = new ImportManager();
@ -301,8 +308,8 @@ class ImportController extends Controller {
return $response;
}
error_log("progresskey: ".\OC_Cache::get($progresskey)." total: ".\OC_Cache::get($progresskey.'_total') );
$response->setParams(array('progress' => \OC_Cache::get($progresskey), 'total' => \OC_Cache::get($progresskey.'_total') ));
error_log("progresskey: ".$this->cache->get($progresskey)." total: ".$this->cache->get($progresskey.'_total') );
$response->setParams(array('progress' => $this->cache->get($progresskey), 'total' => $this->cache->get($progresskey.'_total') ));
return $response;
}
}

View File

@ -11,7 +11,7 @@
namespace OCA\Contacts\Controller;
use OCA\Contacts\App,
OCA\Contacts\Controller,
OCP\AppFramework\Controller,
OCA\Contacts\Utils\Properties,
OCP\AppFramework\Http\TemplateResponse;
@ -26,7 +26,7 @@ class PageController extends Controller {
* @NoCSRFRequired
*/
public function index() {
\OC::$server->getNavigationManager()->setActiveEntry('contacts');
\OC::$server->getNavigationManager()->setActiveEntry($this->appName);
$imppTypes = Properties::getTypesForProperty('IMPP');
$adrTypes = Properties::getTypesForProperty('ADR');
@ -58,7 +58,7 @@ class PageController extends Controller {
\OCP\Util::addStyle('3rdparty/Jcrop', 'jquery.Jcrop');
\OCP\Util::addStyle('contacts', 'contacts');
$response = new TemplateResponse('contacts', 'contacts');
$response = new TemplateResponse($this->appName, 'contacts');
$response->setParams(array(
'uploadMaxFilesize' => $maxUploadFilesize,
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),

View File

@ -12,7 +12,7 @@ namespace OCA\Contacts\Controller;
use OCA\Contacts\App,
OCA\Contacts\JSONResponse,
OCA\Contacts\Controller,
OCP\AppFramework\Controller,
OCA\AppFramework\Core\API;
@ -40,7 +40,7 @@ class SettingsController extends Controller {
$response->bailOut(App::$l10n->t('No value is given.'));
}
if(\OCP\Config::setUserValue($this->api->getUserId(), 'contacts', $key, $value)) {
if(\OCP\Config::setUserValue(\OCP\User::getUser(), 'contacts', $key, $value)) {
$response->setParams(array(
'key' => $key,
'value' => $value)

View File

@ -30,44 +30,75 @@ use OCP\AppFramework\App as MainApp,
*/
class Dispatcher extends MainApp {
/**
* @var App
* @var string
*/
protected $appName;
/**
* @var OCA\Contacts\App
*/
protected $app;
/**
* @var \OCP\IServerContainer
*/
protected $server;
/**
* @var OCP\AppFramework\IAppContainer
*/
protected $container;
public function __construct($params) {
parent::__construct('contacts', $params);
$this->appName = 'contacts';
parent::__construct($this->appName, $params);
$this->container = $this->getContainer();
$this->container->registerMiddleware(new HttpMiddleware());
$this->server = $this->container->getServer();
$this->app = new App($this->container->query('API')->getUserId());
$this->registerServices();
}
public function registerServices() {
$appName = $this->appName;
$app = $this->app;
$this->container->registerService('PageController', function(IAppContainer $container) use($app) {
return new PageController($container, $app);
$this->container->registerService('PageController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
return new PageController($appName, $request);
});
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app) {
return new AddressBookController($container, $app);
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
return new AddressBookController($appName, $request, $app);
});
$this->container->registerService('GroupController', function(IAppContainer $container) use($app) {
return new GroupController($container, $app);
$this->container->registerService('GroupController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
$tags = $this->server->getTagManager()->load('contact');
return new GroupController($this->appName, $request, $app, $tags);
});
$this->container->registerService('ContactController', function(IAppContainer $container) use($app) {
return new ContactController($container, $app);
$this->container->registerService('ContactController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
return new ContactController($this->appName, $request, $app);
});
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app) {
return new ContactPhotoController($container, $app);
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
$cache = $this->server->getCache();
return new ContactPhotoController($this->appName, $request, $app, $cache);
});
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app) {
return new SettingsController($container, $app);
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
return new SettingsController($this->appName, $request, $app);
});
$this->container->registerService('ImportController', function(IAppContainer $container) use($app) {
return new ImportController($container, $app);
$this->container->registerService('ImportController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
$cache = $this->server->getCache();
return new ImportController($this->appName, $request, $app, $cache);
});
$this->container->registerService('ExportController', function(IAppContainer $container) use($app) {
return new ExportController($container, $app);
$this->container->registerService('ExportController', function(IAppContainer $container) use($app, $appName) {
$request = $container->query('Request');
return new ExportController($this->appName, $request, $app);
});
}

View File

@ -22,6 +22,9 @@
namespace OCA\Contacts\Utils;
use OCP\ICache,
OCP\Image;
/**
* This class is used for getting a temporary contact photo for cropping.
*
@ -82,8 +85,8 @@ class TemporaryPhoto {
* Always call parents ctor:
* parent::__construct($server);
*/
public function __construct(\OCP\IServerContainer $server, $key = null) {
$this->server = $server;
public function __construct(ICache $cache, $key = null) {
$this->cache = $cache;
$this->key = $key;
if (!is_null($key)) {
$this->processImage();
@ -97,9 +100,9 @@ class TemporaryPhoto {
* @param int|null $type One of the pre-defined types.
* @param mixed|null $data Whatever data is needed to load the photo.
*/
public static function create(\OCP\IServerContainer $server, $type = null, $data = null) {
public static function create(ICache $cache, $type = null, $data = null) {
if (isset(self::$classMap[$type])) {
return new self::$classMap[$type]($server, $data);
return new self::$classMap[$type]($cache, $data);
} else {
return new self($data, $data);
}
@ -111,7 +114,7 @@ class TemporaryPhoto {
* @param string $key
*/
public function remove($key) {
return $this->server->getCache()->remove($key);
return $this->cache->remove($key);
}
/**
@ -121,8 +124,8 @@ class TemporaryPhoto {
* instance of \OCP\Image.
*/
protected function processImage() {
$this->image = new \OCP\Image();
$this->image->loadFromData($this->server->getCache()->get($this->key));
$this->image = new Image();
$this->image->loadFromData($this->cache->get($this->key));
}
/**
@ -131,7 +134,7 @@ class TemporaryPhoto {
* @return bool
*/
public function isValid() {
return (($this->image instanceof \OCP\Image) && $this->image->valid());
return (($this->image instanceof Image) && $this->image->valid());
}
/**
@ -164,14 +167,14 @@ class TemporaryPhoto {
return;
}
if (!$this->image instanceof \OCP\Image) {
if (!$this->image instanceof Image) {
$this->processImage();
}
$this->normalizePhoto();
$data = $this->image->data();
$this->key = uniqid('photo-');
$this->server->getCache()->set($this->key, $data, 600);
$this->cache->set($this->key, $data, 600);
}
/**

View File

@ -23,7 +23,8 @@
namespace OCA\Contacts\Utils\TemporaryPhoto;
use OCA\Contacts\Contact as ContactObject,
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto;
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
OCP\ICache;
/**
* This class loads the PHOTO or LOGO property from a contact.
@ -37,7 +38,7 @@ class Contact extends BaseTemporaryPhoto {
*/
protected $contact;
public function __construct(\OCP\IServerContainer $server, $contact) {
public function __construct(ICache $cache, $contact) {
if (!$contact instanceof ContactObject) {
throw new \Exception(
__METHOD__
@ -45,7 +46,7 @@ class Contact extends BaseTemporaryPhoto {
);
}
parent::__construct($server);
parent::__construct($cache);
$this->contact = $contact;
$this->processImage();
}

View File

@ -24,7 +24,8 @@ namespace OCA\Contacts\Utils\TemporaryPhoto;
use OCA\Contacts\Contact as ContactObject,
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
OCP\AppFramework\Http;
OCP\AppFramework\Http,
OCP\ICache;
/**
* This class loads an image from the virtual file system.
@ -38,7 +39,7 @@ class FileSystem extends BaseTemporaryPhoto {
*/
protected $path;
public function __construct(\OCP\IServerContainer $server, $path) {
public function __construct(ICache $cache, $path) {
\OCP\Util::writeLog('contacts', __METHOD__.' path: ' . $path, \OCP\Util::DEBUG);
if (!is_string($path)) {
throw new \Exception(
@ -46,7 +47,7 @@ class FileSystem extends BaseTemporaryPhoto {
);
}
parent::__construct($server);
parent::__construct($cache);
$this->path = $path;
$this->processImage();
}

View File

@ -26,7 +26,8 @@ use OCA\Contacts\Contact as ContactObject,
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
OCP\IRequest,
OCP\AppFramework\Http,
OCP\Image;
OCP\Image,
OCP\ICache;
/**
* This class loads an image from the virtual file system.
@ -40,7 +41,7 @@ class Uploaded extends BaseTemporaryPhoto {
*/
protected $input;
public function __construct(\OCP\IServerContainer $server, IRequest $request) {
public function __construct(ICache $cache, IRequest $request) {
\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
if (!$request instanceOf IRequest) {
throw new \Exception(
@ -48,7 +49,7 @@ class Uploaded extends BaseTemporaryPhoto {
);
}
parent::__construct($server);
parent::__construct($cache);
$this->request = $request;
$this->processImage();
}