first commit
This commit is contained in:
116
modules/ps_mbo/src/RecommendedModule/RecommendedModule.php
Normal file
116
modules/ps_mbo/src/RecommendedModule/RecommendedModule.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
class RecommendedModule implements RecommendedModuleInterface
|
||||
{
|
||||
/**
|
||||
* @var string technical name of the recommended module
|
||||
*/
|
||||
private $moduleName;
|
||||
|
||||
/**
|
||||
* @var int position of the recommended module
|
||||
*/
|
||||
private $position;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isInstalled;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $moduleData;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return $this->moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setModuleName($moduleName)
|
||||
{
|
||||
$this->moduleName = $moduleName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPosition($position)
|
||||
{
|
||||
$this->position = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isInstalled()
|
||||
{
|
||||
return $this->isInstalled;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setInstalled($isInstalled)
|
||||
{
|
||||
$this->isInstalled = $isInstalled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getModuleData()
|
||||
{
|
||||
return $this->moduleData;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setModuleData($moduleData)
|
||||
{
|
||||
$this->moduleData = $moduleData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
use ArrayIterator;
|
||||
use Closure;
|
||||
|
||||
class RecommendedModuleCollection implements RecommendedModuleCollectionInterface
|
||||
{
|
||||
/**
|
||||
* @var RecommendedModuleInterface[]
|
||||
*/
|
||||
private $recommendedModules = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addRecommendedModule(RecommendedModuleInterface $recommendedModule)
|
||||
{
|
||||
$this->recommendedModules[] = $recommendedModule;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRecommendedModule($moduleName)
|
||||
{
|
||||
foreach ($this->recommendedModules as $recommendedModule) {
|
||||
if ($moduleName === $recommendedModule->getModuleName()) {
|
||||
return $recommendedModule;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRecommendedModuleNames()
|
||||
{
|
||||
$recommendedModuleNames = [];
|
||||
|
||||
foreach ($this->recommendedModules as $recommendedModule) {
|
||||
$recommendedModuleNames[] = $recommendedModule->getModuleName();
|
||||
}
|
||||
|
||||
return $recommendedModuleNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->recommendedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->recommendedModules[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->recommendedModules[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->recommendedModules[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->recommendedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->recommendedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->recommendedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sortByPosition()
|
||||
{
|
||||
$this->sort(function (
|
||||
RecommendedModuleInterface $recommendedModuleA,
|
||||
RecommendedModuleInterface $recommendedModuleB
|
||||
) {
|
||||
if ($recommendedModuleA->getPosition() === $recommendedModuleB->getPosition()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($recommendedModuleA->getPosition() < $recommendedModuleB->getPosition()) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstalled()
|
||||
{
|
||||
return $this->filter(function (RecommendedModuleInterface $recommendedModule) {
|
||||
return $recommendedModule->isInstalled();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNotInstalled()
|
||||
{
|
||||
return $this->filter(function (RecommendedModuleInterface $recommendedModule) {
|
||||
return !$recommendedModule->isInstalled();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Closure $closure
|
||||
*
|
||||
* @return RecommendedModuleCollection
|
||||
*/
|
||||
private function filter(Closure $closure)
|
||||
{
|
||||
$recommendedModules = new static();
|
||||
$recommendedModules->recommendedModules = array_filter(
|
||||
$this->recommendedModules,
|
||||
$closure,
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
$recommendedModules->sortByPosition();
|
||||
|
||||
return $recommendedModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Closure $closure
|
||||
*/
|
||||
private function sort(Closure $closure)
|
||||
{
|
||||
uasort(
|
||||
$this->recommendedModules,
|
||||
$closure
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
use ArrayAccess;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
|
||||
interface RecommendedModuleCollectionInterface extends ArrayAccess, IteratorAggregate, Countable
|
||||
{
|
||||
/**
|
||||
* Add a recommended module to this collection.
|
||||
*
|
||||
* @param RecommendedModuleInterface $recommendedModule
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addRecommendedModule(RecommendedModuleInterface $recommendedModule);
|
||||
|
||||
/**
|
||||
* Get a recommended module by name
|
||||
*
|
||||
* @param string $moduleName
|
||||
*
|
||||
* @return RecommendedModuleInterface|false
|
||||
*/
|
||||
public function getRecommendedModule($moduleName);
|
||||
|
||||
/**
|
||||
* Get names of recommended modules
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getRecommendedModuleNames();
|
||||
|
||||
/**
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return RecommendedModuleInterface
|
||||
*/
|
||||
public function offsetGet($offset);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty();
|
||||
|
||||
/**
|
||||
* Sort recommended modules by position
|
||||
*/
|
||||
public function sortByPosition();
|
||||
|
||||
/**
|
||||
* Get recommended modules installed.
|
||||
*
|
||||
* @return RecommendedModuleCollectionInterface
|
||||
*/
|
||||
public function getInstalled();
|
||||
|
||||
/**
|
||||
* Get recommended modules not installed.
|
||||
*
|
||||
* @return RecommendedModuleCollectionInterface
|
||||
*/
|
||||
public function getNotInstalled();
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
interface RecommendedModuleInterface
|
||||
{
|
||||
/**
|
||||
* Get the technical name of the recommended module.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleName();
|
||||
|
||||
/**
|
||||
* @param string $moduleName
|
||||
*
|
||||
* @return RecommendedModuleInterface
|
||||
*/
|
||||
public function setModuleName($moduleName);
|
||||
|
||||
/**
|
||||
* Get the position of the recommended module.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition();
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
*
|
||||
* @return RecommendedModuleInterface
|
||||
*/
|
||||
public function setPosition($position);
|
||||
|
||||
/**
|
||||
* Check if the recommended modules is installed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInstalled();
|
||||
|
||||
/**
|
||||
* @param bool $isInstalled
|
||||
*
|
||||
* @return RecommendedModuleInterface
|
||||
*/
|
||||
public function setInstalled($isInstalled);
|
||||
|
||||
/**
|
||||
* Get the recommended module data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleData();
|
||||
|
||||
/**
|
||||
* @param array $moduleData
|
||||
*
|
||||
* @return RecommendedModuleInterface
|
||||
*/
|
||||
public function setModuleData($moduleData);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
class RecommendedModulePresenter implements RecommendedModulePresenterInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function present(RecommendedModuleInterface $recommendedModule)
|
||||
{
|
||||
return $recommendedModule->getModuleData();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function presentCollection(RecommendedModuleCollectionInterface $recommendedModules)
|
||||
{
|
||||
$recommendedModulesPresented = [];
|
||||
|
||||
foreach ($recommendedModules as $recommendedModule) {
|
||||
$recommendedModulesPresented[] = $this->present($recommendedModule);
|
||||
}
|
||||
|
||||
return $recommendedModulesPresented;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Mbo\RecommendedModule;
|
||||
|
||||
interface RecommendedModulePresenterInterface
|
||||
{
|
||||
/**
|
||||
* Transform a RecommendedModuleInterface as a simple array of data.
|
||||
*
|
||||
* @param RecommendedModuleInterface $recommendedModule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function present(RecommendedModuleInterface $recommendedModule);
|
||||
|
||||
/**
|
||||
* Transform a collection of RecommendedModulesInterface as a simple array of data.
|
||||
*
|
||||
* @param RecommendedModuleCollectionInterface $recommendedModules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function presentCollection(RecommendedModuleCollectionInterface $recommendedModules);
|
||||
}
|
||||
28
modules/ps_mbo/src/RecommendedModule/index.php
Normal file
28
modules/ps_mbo/src/RecommendedModule/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user