From c3b49a1007b97e31ca34e012a9297e9546114206 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 18 Apr 2013 01:12:04 +0200 Subject: [PATCH] First attempt on port to app framework --- appinfo/app.php | 73 ++++++++++++++++------------ appinfo/routes.php | 9 +++- controller/addressbookcontroller.php | 40 +++++++++++++++ controller/basecontroller.php | 38 +++++++++++++++ dicontainer.php | 31 ++++++++++++ 5 files changed, 158 insertions(+), 33 deletions(-) create mode 100644 controller/addressbookcontroller.php create mode 100644 controller/basecontroller.php create mode 100644 dicontainer.php diff --git a/appinfo/app.php b/appinfo/app.php index 509a9b81..fdddc7b0 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -1,40 +1,51 @@ 'contacts_index', - 'order' => 10, - 'href' => \OC_Helper::linkToRoute('contacts_index'), - 'icon' => OCP\Util::imagePath( 'contacts', 'contacts.svg' ), - 'name' => OC_L10N::get('contacts')->t('Contacts') )); + $api->addNavigationEntry(array( + 'id' => 'contacts_index', + 'order' => 10, + 'href' => \OC_Helper::linkToRoute('contacts_index'), + 'icon' => \OCP\Util::imagePath( 'contacts', 'contacts.svg' ), + '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\Share::registerBackend('addressbook', 'OCA\Contacts\Share_Backend_Addressbook', 'contact'); +} +\OCP\Util::addscript('contacts', 'loader'); + +\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()) { diff --git a/appinfo/routes.php b/appinfo/routes.php index bdb4a18a..f2c9dec8 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -8,6 +8,10 @@ */ namespace OCA\Contacts; +use \OCA\AppFramework\App as Main; + +use \OCA\Contacts\DIContainer; + require_once __DIR__.'/../ajax/loghandler.php'; //define the routes @@ -34,7 +38,8 @@ $this->create('contacts_address_books_for_user', 'addressbooks/{user}/') ->action( function($params) { session_write_close(); - $app = new App($params['user']); + Main::main('AddressBookController', 'userAddressBooks', $params, new DIContainer()); + /*$app = new App($params['user']); $addressBooks = $app->getAddressBooksForUser(); $response = array(); foreach($addressBooks as $addressBook) { @@ -44,7 +49,7 @@ $this->create('contacts_address_books_for_user', 'addressbooks/{user}/') 'data' => array( 'addressbooks' => $response, ) - )); + ));*/ } ) ->requirements(array('user')) diff --git a/controller/addressbookcontroller.php b/controller/addressbookcontroller.php new file mode 100644 index 00000000..3f5b7cb3 --- /dev/null +++ b/controller/addressbookcontroller.php @@ -0,0 +1,40 @@ +getAddressBooksForUser(); + $response = array(); + foreach($addressBooks as $addressBook) { + $response[] = $addressBook->getMetaData(); + } + \OCP\JSON::success(array( + 'data' => array( + 'addressbooks' => $response, + ) + )); + } +} diff --git a/controller/basecontroller.php b/controller/basecontroller.php new file mode 100644 index 00000000..4a95051b --- /dev/null +++ b/controller/basecontroller.php @@ -0,0 +1,38 @@ +api = $api; + $this->request = $request; + } + +} diff --git a/dicontainer.php b/dicontainer.php new file mode 100644 index 00000000..7431926c --- /dev/null +++ b/dicontainer.php @@ -0,0 +1,31 @@ +share(function($c){ + return new AddressBookController($c['API'], $c['Request']); + }); + } +} \ No newline at end of file