From 70ae337604d70ae995ffdb33578a9b5d22eb5887 Mon Sep 17 00:00:00 2001 From: Mathias Gelhausen Date: Mon, 7 Dec 2020 11:49:02 +0100 Subject: [PATCH] feat: add top company selection --- module/Organizations/config/module.config.php | 23 ++++- module/Organizations/config/router.config.php | 14 +++ .../FeaturedCompaniesController.php | 37 ++++++++ .../FeaturedCompaniesControllerFactory.php | 34 +++++++ .../src/Controller/ProfileController.php | 4 +- .../src/Entity/FeaturedCompanySettings.php | 38 ++++++++ .../Organizations/src/Entity/Organization.php | 27 ++++++ .../src/Entity/ProfileSettings.php | 30 ++++++ .../Element/FeaturedCompaniesFilterRadio.php | 44 +++++++++ .../src/Form/FeaturedCompaniesSearchForm.php | 49 ++++++++++ .../src/Repository/Filter/PaginationQuery.php | 5 + .../featured-companies-filter-radio.phtml | 28 ++++++ .../featured-companies/index.ajax.phtml | 93 +++++++++++++++++++ .../featured-companies/index.phtml | 31 +++++++ .../organizations/profile/index.ajax.phtml | 3 + 15 files changed, 457 insertions(+), 3 deletions(-) create mode 100644 module/Organizations/src/Controller/FeaturedCompaniesController.php create mode 100644 module/Organizations/src/Controller/FeaturedCompaniesControllerFactory.php create mode 100644 module/Organizations/src/Entity/FeaturedCompanySettings.php create mode 100644 module/Organizations/src/Entity/ProfileSettings.php create mode 100644 module/Organizations/src/Form/Element/FeaturedCompaniesFilterRadio.php create mode 100644 module/Organizations/src/Form/FeaturedCompaniesSearchForm.php create mode 100644 module/Organizations/view/form/featured-companies-filter-radio.phtml create mode 100644 module/Organizations/view/organizations/featured-companies/index.ajax.phtml create mode 100644 module/Organizations/view/organizations/featured-companies/index.phtml diff --git a/module/Organizations/config/module.config.php b/module/Organizations/config/module.config.php index fa1cd78cc..cf75adc08 100644 --- a/module/Organizations/config/module.config.php +++ b/module/Organizations/config/module.config.php @@ -1,9 +1,16 @@ * @author Mathias Gelhausen */ + declare(strict_types=1); + + namespace Organizations; + +use Laminas\ServiceManager\Factory\InvokableFactory; + return [ 'doctrine' => [ 'driver' => [ @@ -51,7 +58,8 @@ 'factories' => [ 'Organizations/InviteEmployee' => \Organizations\Factory\Controller\InviteEmployeeControllerFactory::class, 'Organizations/Index' => 'Organizations\Factory\Controller\IndexControllerFactory', - 'Organizations/Profile' => 'Organizations\Factory\Controller\ProfileControllerFactory' + 'Organizations/Profile' => 'Organizations\Factory\Controller\ProfileControllerFactory', + Controller\FeaturedCompaniesController::class => Controller\FeaturedCompaniesControllerFactory::class, ] ], @@ -74,6 +82,7 @@ 'organizations/error/invite' => __DIR__ . '/../view/error/invite.phtml', 'organizations/mail/invite-employee' => __DIR__ . '/../view/mail/invite-employee.phtml', 'organizations/form/workflow-fieldset' => __DIR__ . '/../view/form/workflow-fieldset.phtml', + 'organizations/form/featured-companies-filter-radio' => __DIR__ . '/../view/form/featured-companies-filter-radio.phtml', 'organizations/profile/disabled' => __DIR__ . '/../view/organizations/profile/disabled.phtml', ], // Where to look for view templates not mapped above @@ -104,6 +113,7 @@ 'Organizations/Image' => \Organizations\Form\LogoImageFactory::class, 'Organizations/EmployeesFieldset' => 'Organizations\Factory\Form\EmployeesFieldsetFactory', 'Organizations/EmployeeFieldset' => 'Organizations\Factory\Form\EmployeeFieldsetFactory', + Form\Element\FeaturedCompaniesFilterRadio::class => InvokableFactory::class, ] ], @@ -175,6 +185,11 @@ 'route/lang/organizations/profileDetail' ], ], + 'admin' => [ + 'allow' => [ + 'route/lang/organizations/featured', + ], + ], ], 'assertions' => [ 'invokables' => [ @@ -204,9 +219,13 @@ 'label' => /*@translate*/ 'Insert', 'route' => 'lang/organizations/edit', ], + 'featured' => [ + 'label' => /*@translate*/ 'Featured Companies', + 'route' => 'lang/organizations/featured', + 'resource' => 'route/lang/organizations/featured', + ], ], ], - ], ], diff --git a/module/Organizations/config/router.config.php b/module/Organizations/config/router.config.php index dc452e278..af694c3b7 100644 --- a/module/Organizations/config/router.config.php +++ b/module/Organizations/config/router.config.php @@ -7,6 +7,11 @@ * @copyright https://yawik.org/COPYRIGHT.php * @license MIT */ + + declare(strict_types=1); + + namespace Organizations; + return array( 'router' => array( 'routes' => array( @@ -112,6 +117,15 @@ ), ), ), + 'featured' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/featured', + 'defaults' => [ + 'controller' => Controller\FeaturedCompaniesController::class + ] + ], + ], ), ), 'my-organization' => array( diff --git a/module/Organizations/src/Controller/FeaturedCompaniesController.php b/module/Organizations/src/Controller/FeaturedCompaniesController.php new file mode 100644 index 000000000..02cb8dc36 --- /dev/null +++ b/module/Organizations/src/Controller/FeaturedCompaniesController.php @@ -0,0 +1,37 @@ +repository = $repository; + } + + public function indexAction() + { + + } +} diff --git a/module/Organizations/src/Controller/FeaturedCompaniesControllerFactory.php b/module/Organizations/src/Controller/FeaturedCompaniesControllerFactory.php new file mode 100644 index 000000000..6d891d8f3 --- /dev/null +++ b/module/Organizations/src/Controller/FeaturedCompaniesControllerFactory.php @@ -0,0 +1,34 @@ +get('repositories')->get('Organizations') + ); + } +} diff --git a/module/Organizations/src/Controller/ProfileController.php b/module/Organizations/src/Controller/ProfileController.php index 213b1c9ef..fe703b802 100644 --- a/module/Organizations/src/Controller/ProfileController.php +++ b/module/Organizations/src/Controller/ProfileController.php @@ -19,6 +19,7 @@ use Laminas\I18n\Translator\TranslatorInterface; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\ViewModel; +use Organizations\Form\FeaturedCompaniesSearchForm; use Organizations\ImageFileCache\Manager as ImageFileCacheManager; /** @@ -90,10 +91,11 @@ public function indexAction() 'as' => 'organizations', 'params' => [ 'type' => 'profile', + 'featured' => $this->auth()->isAdmin() && (bool) $this->params('featured'), ] ], 'form' => [ - 'Core/Search', + $this->auth()->isAdmin() ? FeaturedCompaniesSearchForm::class : 'Core/Search', 'as' => 'form', ] ]); diff --git a/module/Organizations/src/Entity/FeaturedCompanySettings.php b/module/Organizations/src/Entity/FeaturedCompanySettings.php new file mode 100644 index 000000000..e09239681 --- /dev/null +++ b/module/Organizations/src/Entity/FeaturedCompanySettings.php @@ -0,0 +1,38 @@ +isFeaturedCompany; + } + + /** + * Set isFeaturedCompany + * + * @param bool $isFeaturedCompany + */ + public function setIsFeaturedCompany(bool $isFeaturedCompany): void + { + $this->isFeaturedCompany = $isFeaturedCompany; + } } diff --git a/module/Organizations/src/Entity/ProfileSettings.php b/module/Organizations/src/Entity/ProfileSettings.php new file mode 100644 index 000000000..9b5e345d7 --- /dev/null +++ b/module/Organizations/src/Entity/ProfileSettings.php @@ -0,0 +1,30 @@ +setName('featured'); + $this->setValueOptions([ + 'none' => /*@translate*/ 'All', + 'on' => /*@translate*/ 'Featured', + 'off' => /*@translate*/ 'Not Featured', + ]); + $this->setAttributes([ + 'value' => 'none', + 'data-submit-on-change' => 'true' + ]); + } +} diff --git a/module/Organizations/src/Form/FeaturedCompaniesSearchForm.php b/module/Organizations/src/Form/FeaturedCompaniesSearchForm.php new file mode 100644 index 000000000..8fba03dbe --- /dev/null +++ b/module/Organizations/src/Form/FeaturedCompaniesSearchForm.php @@ -0,0 +1,49 @@ +setName($this->getOption('name') ?: 'searchform'); + + $this->addTextElement( + $this->getOption('text_name') ?: 'q', + $this->getOption('text_label') ?: /*@translate*/ 'Search', + $this->getOption('text_placeholder') ?: /*@translate*/ 'Search query', + $this->getOption('text_span') ?: 12, + 50, + true + ); + + $this->add([ + 'type' => FeaturedCompaniesFilterRadio::class + ]); + + $this->addButton(/*@translate*/ 'Search', -1000, 'submit'); + $this->addButton(/*@translate*/ 'Clear', -1001, 'reset'); + + $this->addElements(); + } +} diff --git a/module/Organizations/src/Repository/Filter/PaginationQuery.php b/module/Organizations/src/Repository/Filter/PaginationQuery.php index b019c301b..71283cb6e 100644 --- a/module/Organizations/src/Repository/Filter/PaginationQuery.php +++ b/module/Organizations/src/Repository/Filter/PaginationQuery.php @@ -115,6 +115,11 @@ public function createQuery($params, $queryBuilder) if (count($filters) > 0) { $queryBuilder->field('id')->notIn($filters); } + if (isset($params['featured']) && $params['featured'] !== 'none') { + $flag = $params['featured'] === 'on'; + + $queryBuilder->field('isFeaturedCompany')->equals($flag); + } } return $queryBuilder; diff --git a/module/Organizations/view/form/featured-companies-filter-radio.phtml b/module/Organizations/view/form/featured-companies-filter-radio.phtml new file mode 100644 index 000000000..5a4a4671e --- /dev/null +++ b/module/Organizations/view/form/featured-companies-filter-radio.phtml @@ -0,0 +1,28 @@ + +
+ getValueOptions() as $value => $label) : + $checked = $value == $element->getValue();?> + + + + + + +
diff --git a/module/Organizations/view/organizations/featured-companies/index.ajax.phtml b/module/Organizations/view/organizations/featured-companies/index.ajax.phtml new file mode 100644 index 000000000..c9471cb23 --- /dev/null +++ b/module/Organizations/view/organizations/featured-companies/index.ajax.phtml @@ -0,0 +1,93 @@ + + $this->translate('Organization'), + 'sort' => '_organizationName', + ], + [ + 'label' => $this->translate('City'), + 'sort' => 'contact.city', + ], + [ + 'label' => $this->translate('Street'), + 'sort' => 'contact.street', + ], +]; + +$sort = $this->params()->fromQuery('sort', 'name'); +if ('-' == $sort{0}) { + $sortBy = substr($sort, 1); + $sortDir = false; +} else { + $sortBy = $sort; + $sortDir = true; +} +?> + + + + + > + '; + $dir = !$sortDir; + else: + $dir = true; + $icon = ''; + endif; + $sortParam = array('sort' => ($dir ? '' : '-') . $spec['sort']); + $url = $this->url( + 'lang/organizations', array(), + array('query' => array_merge($this->params()->fromQuery(), $sortParam)), + true + ); + ?> + + + + + + +organizations as $organization): /* @var $organization \Organizations\Entity\Organization */?> + + + + + + +
+ + getOrganizationName(); + echo isset($nameEntity)?$nameEntity->getName():'**** DRAFT ****'; + ?> + + isHiringOrganization()): $parent = $organization->getParent(); ?> +
translate('Hiring organization of %s'), + '' . $parent->getOrganizationName()->getName() . '' + );?> + + +
+ getContact()->getPostalcode();?> + getContact()->getCity();?> + + getContact()->getStreet();?> + getContact()->getHouseNumber();?> +
+paginationControl($this->organizations, 'Sliding', 'pagination-control', array('lang' => $this->params('lang'), 'route' => 'lang/organizations'));?> \ No newline at end of file diff --git a/module/Organizations/view/organizations/featured-companies/index.phtml b/module/Organizations/view/organizations/featured-companies/index.phtml new file mode 100644 index 000000000..e709bef9f --- /dev/null +++ b/module/Organizations/view/organizations/featured-companies/index.phtml @@ -0,0 +1,31 @@ +headScript()->appendFile($this->basepath('modules/Core/js/core.pagination-container.js')); +?> +

translate('Organizations')?>

+ + +
+ +
+ translate('No organization found matching your criteria.') ?> +
+ +
+ render('organizations/index/index.ajax.phtml')?> +
+ +
\ No newline at end of file diff --git a/module/Organizations/view/organizations/profile/index.ajax.phtml b/module/Organizations/view/organizations/profile/index.ajax.phtml index 9fe121014..bcabee3a2 100644 --- a/module/Organizations/view/organizations/profile/index.ajax.phtml +++ b/module/Organizations/view/organizations/profile/index.ajax.phtml @@ -65,6 +65,9 @@ if ('-' == $sort{0}) { organizations as $organization): /* @var $organization \Organizations\Entity\Organization */?> + auth()->isAdmin()) : ?> + isFeaturedCompany() ? ' checked' : '' ?>> + getImage() && $organization->getOrganizationName()): ?>