diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..5c43a74 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,27 @@ +Copyright (c) 2019-2020, Verein onePlace +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +- Neither the name of Verein onePlace nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..10d98a5 --- /dev/null +++ b/composer.json @@ -0,0 +1,53 @@ +{ + "name": "oneplace/oneplace-contact-address", + "description": "onePlace Contact Address Plugin. Multiple Addresses for Contacts", + "type": "oneplace-plugin", + "version": "1.0.0", + "license": "BSD-3-Clause", + "keywords": [ + "laminas", + "mvc", + "oneplace-module", + "oneplace", + "skeleton", + "framework" + ], + "require-dev": { + "phpunit/phpunit": "^8", + "laminas/laminas-test": "^3.3.0", + "php-coveralls/php-coveralls": "^2.2" + }, + "require": { + "php": "^7.1", + "oneplace/oneplace-contact": "^1.0.6" + }, + "autoload": { + "psr-4": { + "OnePlace\\Contact\\Address\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + + } + }, + "scripts": { + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "development-disable": "laminas-development-mode disable", + "development-enable": "laminas-development-mode enable", + "development-status": "laminas-development-mode status", + "post-create-project-cmd": [ + "@development-enable", + "php -r '$file = file_get_contents(\".gitignore\"); $file = str_replace(\"composer.lock\", \"\", $file); file_put_contents(\".gitignore\", $file);'" + ], + "serve": "php -S 0.0.0.0:8080 -t public", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml" + }, + "extra": { + "zf": { + "module": "OnePlace\\Contact\\Address" + } + } +} diff --git a/config/module.config.php b/config/module.config.php new file mode 100644 index 0000000..017690c --- /dev/null +++ b/config/module.config.php @@ -0,0 +1,23 @@ + + * @license https://opensource.org/licenses/BSD-3-Clause + * @version 1.0.0 + * @since 1.0.0 + */ + +namespace OnePlace\Contact\Address; + +use Laminas\Router\Http\Literal; +use Laminas\Router\Http\Segment; +use Laminas\ServiceManager\Factory\InvokableFactory; + +return [ +]; diff --git a/data/install.sql b/data/install.sql new file mode 100644 index 0000000..5c64701 --- /dev/null +++ b/data/install.sql @@ -0,0 +1,11 @@ +-- +-- Add new tab +-- +INSERT INTO `core_form_tab` (`Tab_ID`, `form`, `title`, `subtitle`, `icon`, `counter`, `sort_id`, `filter_check`, `filter_value`) VALUES +('contact-address', 'contact-single', 'Address', 'Delivery & Billing', 'fas fa-home', '', '1', '', ''); + +-- +-- Add new partial +-- +INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `form`, `class`, `url_view`, `url_list`, `show_widget_left`, `allow_clear`, `readonly`, `tbl_cached_name`, `tbl_class`, `tbl_permission`) VALUES +(NULL, 'partial', 'Address', 'contact_address', 'contact-address', 'contact-single', 'col-md-12', '', '', '0', '1', '0', '', '', ''); \ No newline at end of file diff --git a/src/Controller/AddressController.php b/src/Controller/AddressController.php new file mode 100644 index 0000000..58688d5 --- /dev/null +++ b/src/Controller/AddressController.php @@ -0,0 +1,67 @@ + + * @license https://opensource.org/licenses/BSD-3-Clause + * @version 1.0.0 + * @since 1.0.0 + */ + +declare(strict_types=1); + +namespace OnePlace\Contact\Address\Controller; + +use Application\Controller\CoreEntityController; +use Application\Model\CoreEntityModel; +use OnePlace\Contact\Model\Contact; +use OnePlace\Contact\Model\ContactTable; +use Laminas\View\Model\ViewModel; +use Laminas\Db\Adapter\AdapterInterface; + +class AddressController extends CoreEntityController { + /** + * Contact Table Object + * + * @since 1.0.0 + */ + protected $oTableGateway; + + /** + * ContactController constructor. + * + * @param AdapterInterface $oDbAdapter + * @param ContactTable $oTableGateway + * @since 1.0.0 + */ + public function __construct(AdapterInterface $oDbAdapter,ContactTable $oTableGateway,$oServiceManager) { + $this->oTableGateway = $oTableGateway; + $this->sSingleForm = 'contact-single'; + parent::__construct($oDbAdapter,$oTableGateway,$oServiceManager); + + if($oTableGateway) { + # Attach TableGateway to Entity Models + if(!isset(CoreEntityModel::$aEntityTables[$this->sSingleForm])) { + CoreEntityModel::$aEntityTables[$this->sSingleForm] = $oTableGateway; + } + } + } + + /** + * Save Address and attach it to contact + * + * @param $oContact saved Contact + * @param $aFormData raw Form Data + * @param $sState state of saving + * @return bool true or false + * @since 1.0.0 + */ + public function attachAddressToContact($oContact,$aFormData,$sState) { + return false; + } +} diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 0000000..6f279a3 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,78 @@ + + * @license https://opensource.org/licenses/BSD-3-Clause + * @version 1.0.0 + * @since 1.0.0 + */ + +namespace OnePlace\Contact\Address; + +use Application\Controller\CoreEntityController; +use Laminas\Mvc\MvcEvent; +use Laminas\EventManager\EventInterface as Event; +use Laminas\ModuleManager\ModuleManager; +use Laminas\Db\Adapter\AdapterInterface; +use OnePlace\Contact\Address\Controller\AddressController; +use OnePlace\Contact\Model\ContactTable; + +class Module { + /** + * Module Version + * + * @since 1.0.0 + */ + const VERSION = '1.0.0'; + + /** + * Load module config file + * + * @since 1.0.0 + * @return array + */ + public function getConfig() : array { + return include __DIR__ . '/../config/module.config.php'; + } + + public function onBootstrap(Event $e) + { + // This method is called once the MVC bootstrapping is complete + $application = $e->getApplication(); + $container = $application->getServiceManager(); + $oDbAdapter = $container->get(AdapterInterface::class); + $tableGateway = $container->get(ContactTable::class); + + # Register Filter Plugin Hook + CoreEntityController::addHook('contact-add-after-save',(object)['sFunction'=>'attachAddressToContact','oItem'=>new AddressController($oDbAdapter,$tableGateway,$container)]); + } + + /** + * Load Controllers + */ + public function getControllerConfig() : array { + return [ + 'factories' => [ + # Plugin Example Controller + Controller\AddressController::class => function($container) { + $oDbAdapter = $container->get(AdapterInterface::class); + $tableGateway = $container->get(ContactTable::class); + + # hook start + # hook end + return new Controller\AddressController( + $oDbAdapter, + $tableGateway, + $container + ); + }, + ], + ]; + } +} diff --git a/view/partial/contact_address-add.phtml b/view/partial/contact_address-add.phtml new file mode 100644 index 0000000..46fcf04 --- /dev/null +++ b/view/partial/contact_address-add.phtml @@ -0,0 +1,3 @@ + +