mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-19 08:52:22 +01:00
First attempt on port to app framework
This commit is contained in:
parent
1be1467257
commit
c3b49a1007
@ -1,40 +1,51 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Contacts;
|
||||||
|
use \OCA\AppFramework\Core\API;
|
||||||
|
|
||||||
//require_once __DIR__ . '/../lib/contact.php';
|
//require_once __DIR__ . '/../lib/contact.php';
|
||||||
Sabre\VObject\Component::$classMap['VCARD'] = 'OCA\Contacts\Contact';
|
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\Contact';
|
||||||
Sabre\VObject\Property::$classMap['FN'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['FN'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['TITLE'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['TITLE'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['ROLE'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['ROLE'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['NOTE'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['NOTE'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['NICKNAME'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['NICKNAME'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['EMAIL'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['EMAIL'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['TEL'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['TEL'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['IMPP'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['IMPP'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['URL'] = 'OC\VObject\StringProperty';
|
\Sabre\VObject\Property::$classMap['URL'] = '\OC\VObject\StringProperty';
|
||||||
Sabre\VObject\Property::$classMap['GEO'] = 'Sabre\VObject\Property\Compound';
|
\Sabre\VObject\Property::$classMap['GEO'] = '\Sabre\VObject\Property\Compound';
|
||||||
|
|
||||||
OCP\Util::connectHook('OC_User', 'post_createUser', 'OCA\Contacts\Hooks', 'userCreated');
|
// dont break owncloud when the appframework is not enabled
|
||||||
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OCA\Contacts\Hooks', 'userDeleted');
|
if(\OCP\App::isEnabled('appframework')) {
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'pre_deleteAddressBook', 'OCA\Contacts\Hooks', 'addressBookDeletion');
|
$api = new API('contacts');
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'pre_deleteContact', 'OCA\Contacts\Hooks', 'contactDeletion');
|
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'post_createContact', 'OCA\Contacts\Hooks', 'contactUpdated');
|
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'post_updateContact', 'OCA\Contacts\Hooks', 'contactUpdated');
|
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'scanCategories', 'OCA\Contacts\Hooks', 'scanCategories');
|
|
||||||
OCP\Util::connectHook('OCA\Contacts', 'indexProperties', 'OCA\Contacts\Hooks', 'indexProperties');
|
|
||||||
OCP\Util::connectHook('OC_Calendar', 'getEvents', 'OCA\Contacts\Hooks', 'getBirthdayEvents');
|
|
||||||
OCP\Util::connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalenderSources');
|
|
||||||
|
|
||||||
OCP\App::addNavigationEntry( array(
|
$api->addNavigationEntry(array(
|
||||||
'id' => 'contacts_index',
|
'id' => 'contacts_index',
|
||||||
'order' => 10,
|
'order' => 10,
|
||||||
'href' => \OC_Helper::linkToRoute('contacts_index'),
|
'href' => \OC_Helper::linkToRoute('contacts_index'),
|
||||||
'icon' => OCP\Util::imagePath( 'contacts', 'contacts.svg' ),
|
'icon' => \OCP\Util::imagePath( 'contacts', 'contacts.svg' ),
|
||||||
'name' => OC_L10N::get('contacts')->t('Contacts') ));
|
'name' => \OC_L10N::get('contacts')->t('Contacts')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
OCP\Util::addscript('contacts', 'loader');
|
$api->connectHook('\OC_User', 'post_createUser', '\OCA\Contacts\Hooks', 'userCreated');
|
||||||
|
$api->connectHook('\OC_User', 'post_deleteUser', '\OCA\Contacts\Hooks', 'userDeleted');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'pre_deleteAddressBook', '\OCA\Contacts\Hooks', 'addressBookDeletion');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'post_createContact', '\OCA\Contacts\Hooks', 'contactUpdated');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'post_updateContact', '\OCA\Contacts\Hooks', 'contactUpdated');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'scanCategories', '\OCA\Contacts\Hooks', 'scanCategories');
|
||||||
|
$api->connectHook('\OCA\Contacts', 'indexProperties', '\OCA\Contacts\Hooks', 'indexProperties');
|
||||||
|
$api->connectHook('\OC_Calendar', 'getEvents', '\OCA\Contacts\Hooks', 'getBirthdayEvents');
|
||||||
|
$api->connectHook('\OC_Calendar', 'getSources', '\OCA\Contacts\Hooks', 'getCalenderSources');
|
||||||
|
|
||||||
OC_Search::registerProvider('OCA\Contacts\SearchProvider');
|
}
|
||||||
OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
|
\OCP\Util::addscript('contacts', 'loader');
|
||||||
OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share_Backend_Addressbook', 'contact');
|
|
||||||
|
\OC_Search::registerProvider('\OCA\Contacts\SearchProvider');
|
||||||
|
\OCP\Share::registerBackend('contact', '\OCA\Contacts\Share_Backend_Contact');
|
||||||
|
//OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share_Backend_Addressbook', 'contact');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(OCP\User::isLoggedIn()) {
|
if(OCP\User::isLoggedIn()) {
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
*/
|
*/
|
||||||
namespace OCA\Contacts;
|
namespace OCA\Contacts;
|
||||||
|
|
||||||
|
use \OCA\AppFramework\App as Main;
|
||||||
|
|
||||||
|
use \OCA\Contacts\DIContainer;
|
||||||
|
|
||||||
require_once __DIR__.'/../ajax/loghandler.php';
|
require_once __DIR__.'/../ajax/loghandler.php';
|
||||||
|
|
||||||
//define the routes
|
//define the routes
|
||||||
@ -34,7 +38,8 @@ $this->create('contacts_address_books_for_user', 'addressbooks/{user}/')
|
|||||||
->action(
|
->action(
|
||||||
function($params) {
|
function($params) {
|
||||||
session_write_close();
|
session_write_close();
|
||||||
$app = new App($params['user']);
|
Main::main('AddressBookController', 'userAddressBooks', $params, new DIContainer());
|
||||||
|
/*$app = new App($params['user']);
|
||||||
$addressBooks = $app->getAddressBooksForUser();
|
$addressBooks = $app->getAddressBooksForUser();
|
||||||
$response = array();
|
$response = array();
|
||||||
foreach($addressBooks as $addressBook) {
|
foreach($addressBooks as $addressBook) {
|
||||||
@ -44,7 +49,7 @@ $this->create('contacts_address_books_for_user', 'addressbooks/{user}/')
|
|||||||
'data' => array(
|
'data' => array(
|
||||||
'addressbooks' => $response,
|
'addressbooks' => $response,
|
||||||
)
|
)
|
||||||
));
|
));*/
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->requirements(array('user'))
|
->requirements(array('user'))
|
||||||
|
40
controller/addressbookcontroller.php
Normal file
40
controller/addressbookcontroller.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Thomas Tanghus
|
||||||
|
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Contacts\Controller;
|
||||||
|
|
||||||
|
use OCA\Contacts\Request;
|
||||||
|
//use OCA\AppFramework\Http\Request;
|
||||||
|
use OCA\AppFramework\Core\API;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Baseclass to inherit your controllers from
|
||||||
|
*/
|
||||||
|
class AddressBookController extends BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsAdminExemption
|
||||||
|
* @IsSubAdminExemption
|
||||||
|
* @Ajax
|
||||||
|
*/
|
||||||
|
public function userAddressBooks() {
|
||||||
|
$app = new App($params['user']);
|
||||||
|
$addressBooks = $app->getAddressBooksForUser();
|
||||||
|
$response = array();
|
||||||
|
foreach($addressBooks as $addressBook) {
|
||||||
|
$response[] = $addressBook->getMetaData();
|
||||||
|
}
|
||||||
|
\OCP\JSON::success(array(
|
||||||
|
'data' => array(
|
||||||
|
'addressbooks' => $response,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
38
controller/basecontroller.php
Normal file
38
controller/basecontroller.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Thomas Tanghus
|
||||||
|
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Contacts\Controller;
|
||||||
|
|
||||||
|
//use OCA\Contacts\Request;
|
||||||
|
use OCA\AppFramework\Http\Request;
|
||||||
|
use OCA\AppFramework\Core\API;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Baseclass to inherit your controllers from
|
||||||
|
*/
|
||||||
|
abstract class BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var API instance of the api layer
|
||||||
|
*/
|
||||||
|
protected $api;
|
||||||
|
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param API $api an api wrapper instance
|
||||||
|
* @param Request $request an instance of the request
|
||||||
|
*/
|
||||||
|
public function __construct(API $api, Request $request) {
|
||||||
|
$this->api = $api;
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
dicontainer.php
Normal file
31
dicontainer.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Thomas Tanghus
|
||||||
|
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Contacts;
|
||||||
|
use OCA\AppFramework\DependencyInjection\DIContainer as BaseContainer;
|
||||||
|
use OCA\Contacts\Controller\AddressBookController;
|
||||||
|
|
||||||
|
class DIContainer extends BaseContainer {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define your dependencies in here
|
||||||
|
*/
|
||||||
|
public function __construct(){
|
||||||
|
// tell parent container about the app name
|
||||||
|
parent::__construct('contacts');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CONTROLLERS
|
||||||
|
*/
|
||||||
|
$this['AddressBookController'] = $this->share(function($c){
|
||||||
|
return new AddressBookController($c['API'], $c['Request']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user