Ajout d'une extension

This commit is contained in:
Gauvain Boiché
2020-04-04 18:27:27 +02:00
parent c3ed8cc1c1
commit 3a964fe237
387 changed files with 58921 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
<?php
/**
*
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbstudio\ass\items;
use phpbbstudio\ass\items\type\item_type;
/**
* phpBB Studio - Advanced Shop System: Item type manager
*/
class manager
{
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\di\service_collection */
protected $types;
/**
* Constructor.
*
* @param \phpbb\language\language $language Language object
* @param \phpbb\template\template $template Template object
* @param \phpbb\di\service_collection $types Item types collection
* @return void
* @access public
*/
public function __construct(
\phpbb\language\language $language,
\phpbb\template\template $template,
\phpbb\di\service_collection $types
)
{
$this->language = $language;
$this->template = $template;
$this->types = $types;
}
/**
* Get an item type.
*
* @param string $type The item type
* @return item_type|null
* @access public
*/
public function get_type($type)
{
return isset($this->types[$type]) ? $this->types[$type] : null;
}
/**
* Set and assign the item types for a <select> element.
*
* @param string $type The selected item type
* @return void
* @access public
*/
public function set_types_for_select($type)
{
/** @var item_type $service */
foreach ($this->types as $id => $service)
{
if ($service->is_admin_authed())
{
$this->template->assign_block_vars('item_types', [
'ID' => $id,
'TITLE' => $this->language->lang($service->get_language('title')),
'S_SELECTED' => $id === $type,
]);
}
}
}
}

View File

@@ -0,0 +1,180 @@
<?php
/**
*
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbstudio\ass\items\type;
use phpbbstudio\ass\entity\category;
use phpbbstudio\ass\entity\item;
/**
* phpBB Studio - Advanced Shop System: Item type "Base"
*/
abstract class base implements item_type
{
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\controller\helper */
protected $helper;
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\log\log */
protected $log;
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\user */
protected $user;
/** @var string Table prefix */
protected $table_prefix;
/** @var category */
protected $category;
/** @var item */
protected $item;
/**
* Constructor.
*
* @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\config\config $config Config object
* @param \phpbb\db\driver\driver_interface $db Database object
* @param \phpbb\controller\helper $helper Controller helper object
* @param \phpbb\language\language $language Language object
* @param \phpbb\log\log $log Log object
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
* @param \phpbb\user $user User object
* @param string $table_prefix Table prefix
* @return void
* @access public
*/
public function __construct(
\phpbb\auth\auth $auth,
\phpbb\config\config $config,
\phpbb\db\driver\driver_interface $db,
\phpbb\controller\helper $helper,
\phpbb\language\language $language,
\phpbb\log\log $log,
\phpbb\request\request $request,
\phpbb\template\template $template,
\phpbb\user $user,
$table_prefix
)
{
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->helper = $helper;
$this->language = $language;
$this->log = $log;
$this->request = $request;
$this->template = $template;
$this->user = $user;
$this->table_prefix = $table_prefix;
}
/**
* {@inheritDoc}
*/
public function set_category(category $category)
{
$this->category = $category;
}
/**
* {@inheritDoc}
*/
public function set_item(item $item)
{
$this->item = $item;
}
/**
* {@inheritDoc}
*/
public function is_admin_authed()
{
return true;
}
/**
* {@inheritDoc}
*/
public function get_language($mode = '')
{
$key = $this->get_language_key();
switch ($mode)
{
case 'success':
case 'title':
case 'log':
return $key . '_' . utf8_strtoupper($mode);
default:
case 'action':
return $key;
}
}
/**
* {@inheritDoc}
*/
abstract public function get_language_key();
/**
* {@inheritDoc}
*/
abstract public function activate(array $data);
/**
* {@inheritDoc}
*/
abstract public function get_acp_template(array $data);
/**
* {@inheritDoc}
*/
public function validate_acp_data(array $data)
{
return [];
}
/**
* {@inheritDoc}
*/
static public function get_confirm_ajax()
{
return 'shop_inventory_use';
}
/**
* {@inheritDoc}
*/
public function get_confirm_template(array $data)
{
return $this->request->is_ajax() ? '@phpbbstudio_ass/ass_confirm_body.html' : 'confirm_body.html';
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
*
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbstudio\ass\items\type;
use phpbbstudio\ass\exceptions\shop_item_exception;
/**
* phpBB Studio - Advanced Shop System: Item type "File"
*/
class file extends base
{
/** @var \phpbbstudio\ass\helper\files */
protected $files;
/**
* Set the files helper object.
*
* @param \phpbbstudio\ass\helper\files $files Files helper object
* @return void
* @access public
*/
public function set_files(\phpbbstudio\ass\helper\files $files)
{
$this->files = $files;
}
/**
* {@inheritDoc}
*/
public function get_language_key()
{
return 'ASS_TYPE_FILE';
}
/**
* {@inheritDoc}
*/
public function activate(array $data)
{
$this->files->set_mode('files');
if (!$this->files->exists($data['file']))
{
throw new shop_item_exception(404, 'ASS_TYPE_FILE_NOT_EXIST');
}
return [
'file' => $this->files->get_path($data['file']),
];
}
/**
* {@inheritDoc}
*/
public function get_acp_template(array $data)
{
$this->template->assign_vars([
'TYPE_FILE' => !empty($data['file']) ? $data['file'] : '',
'U_FILE' => '&amp;m=files&amp;action=select_file&amp;file=',
]);
return '@phpbbstudio_ass/items/file.html';
}
/**
* {@inheritDoc}
*/
public function validate_acp_data(array $data)
{
$errors = [];
$this->files->set_mode('files');
if (empty($data['file']) || !$this->files->exists($data['file']))
{
$errors[] = 'ASS_TYPE_FILE_NOT_EXIST';
}
return $errors;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
*
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbstudio\ass\items\type;
use phpbbstudio\ass\entity\category;
use phpbbstudio\ass\entity\item;
use phpbbstudio\ass\exceptions\shop_exception;
use phpbbstudio\ass\exceptions\shop_item_exception;
/**
* phpBB Studio - Advanced Shop System: Item type interface
*/
interface item_type
{
/**
* Set the category entity.
*
* @param category $category Category entity
* @return void
* @access public
*/
public function set_category(category $category);
/**
* Set the item entity.
*
* @param item $item Item entity
* @return void
* @access public
*/
public function set_item(item $item);
/**
* Whether or not the administrator is authorised to handle this item type.
*
* @return bool
* @access public
*/
public function is_admin_authed();
/**
* Get the language key for a specific mode.
*
* @param string $mode The mode
* @return string The language key
* @access public
*/
public function get_language($mode = '');
/**
* Get the base language key for this item type.
*
* @return string The language key
* @access public
* @abstract
*/
public function get_language_key();
/**
* Activate this item.
*
* @param array $data The item type data
* @return mixed Something that can be casted to (bool) to indicate success
* @throws shop_exception When there is an error with the user's request
* @throws shop_item_exception When there is an error with the item's data
* @access public
* @abstract
*/
public function activate(array $data);
/**
* Get the ACP template and assign any variables for this item type.
*
* @param array $data The item type data
* @return string The path to the ACP template: "@vendor_extension/the_file.html"
* @access public
* @abstract
*/
public function get_acp_template(array $data);
/**
* Validate the ACP data.
*
* @param array $data The item type data
* @return array An array with errors
* @access public
*/
public function validate_acp_data(array $data);
/**
* Get the AJAX callback for the activate confirm action.
*
* @return string The name of the AJAX callback
* @access public
* @static
*/
static public function get_confirm_ajax();
/**
* Get the confirm template and assign any variables for this item type.
*
* @param array $data The item type data
* @return string The path to the template: "@vendor_extension/the_file.html"
* @access public
*/
public function get_confirm_template(array $data);
}

View File

@@ -0,0 +1,120 @@
<?php
/**
*
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbstudio\ass\items\type;
/**
* phpBB Studio - Advanced Shop System: Item type "Points"
*/
class points extends base
{
/** @var \phpbbstudio\aps\points\distributor */
protected $aps_distributor;
/** @var \phpbbstudio\aps\core\functions */
protected $aps_functions;
/**
* Set the APS Distributor object.
*
* @param \phpbbstudio\aps\points\distributor $aps_distributor APS Distributor object
* @return void
* @access public
*/
public function set_aps_distributor(\phpbbstudio\aps\points\distributor $aps_distributor)
{
$this->aps_distributor = $aps_distributor;
}
/**
* Set the APS Functions object.
*
* @param \phpbbstudio\aps\core\functions $aps_functions APS Functions object
* @return void
* @access public
*/
public function set_aps_functions(\phpbbstudio\aps\core\functions $aps_functions)
{
$this->aps_functions = $aps_functions;
}
/**
* {@inheritDoc}
*/
public function get_language_key()
{
return 'ASS_TYPE_POINTS';
}
/**
* {@inheritDoc}
*/
public function get_language($mode = '')
{
$key = $this->get_language_key();
switch ($mode)
{
case 'success':
case 'title':
case 'log':
$key .= '_' . utf8_strtoupper($mode);
break;
case 'action':
// do nothing
break;
default:
$key .= '_CONFIRM';
}
return $this->language->lang($key, $this->aps_functions->get_name());
}
/**
* {@inheritDoc}
*/
public function activate(array $data)
{
$points = $this->aps_functions->equate_points($this->user->data['user_points'], $data['points']);
$points = $this->aps_functions->boundaries($points);
$points = $this->aps_functions->format_points($points);
return $this->aps_distributor->update_points($points);
}
/**
* {@inheritDoc}
*/
public function get_acp_template(array $data)
{
$points = !empty($data['points']) ? $data['points'] : 0.00;
$this->template->assign_var('TYPE_POINTS', $this->aps_functions->format_points($points));
return '@phpbbstudio_ass/items/points.html';
}
/**
* {@inheritDoc}
*/
public function validate_acp_data(array $data)
{
$errors = [];
if (empty($data['points']))
{
$errors[] = $this->language->lang('ASS_TYPE_POINTS_NOT_EMPTY', $this->aps_functions->get_name());
}
return $errors;
}
}