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,345 @@
<?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\entity;
use phpbb\exception\runtime_exception;
/**
* phpBB Studio - Advanced Shop System: Category entity
*/
class category implements category_interface
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\textformatter\s9e\parser */
protected $parser;
/** @var \phpbb\textformatter\s9e\renderer */
protected $renderer;
/** @var \phpbb\textformatter\s9e\utils */
protected $utils;
/** @var string Categories table */
protected $categories_table;
/** @var array Category data */
protected $data;
/**
* Constructor.
*
* @param \phpbb\db\driver\driver_interface $db Database object
* @param \phpbb\textformatter\s9e\parser $parser Text formatter parser object
* @param \phpbb\textformatter\s9e\renderer $renderer Text formatter renderer object
* @param \phpbb\textformatter\s9e\utils $utils Text formatter utilities object
* @param string $categories_table Categories table
* @return void
* @access public
*/
public function __construct(
\phpbb\db\driver\driver_interface $db,
\phpbb\textformatter\s9e\parser $parser,
\phpbb\textformatter\s9e\renderer $renderer,
\phpbb\textformatter\s9e\utils $utils,
$categories_table
)
{
$this->db = $db;
$this->parser = $parser;
$this->renderer = $renderer;
$this->utils = $utils;
$this->categories_table = $categories_table;
}
/**
* {@inheritDoc}
*/
public function load($id, $slug = '')
{
$where = $id <> 0 ? 'category_id = ' . (int) $id : "category_slug = '" . $this->db->sql_escape($slug) . "'";
$sql = 'SELECT * FROM ' . $this->categories_table . ' WHERE ' . $where;
$result = $this->db->sql_query($sql);
$this->data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($this->data === false)
{
throw new runtime_exception('ASS_ERROR_NOT_FOUND');
}
return $this;
}
/**
* {@inheritDoc}
*/
public function import(array $data)
{
$this->data = $data;
return $this;
}
/**
* {@inheritDoc}
*/
public function save()
{
if (empty($this->data['category_id']))
{
throw new runtime_exception('ASS_ERROR_NOT_EXISTS');
}
$data = array_diff_key($this->data, ['category_id' => null]);
$sql = 'UPDATE ' . $this->categories_table . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
WHERE category_id = ' . $this->get_id();
$this->db->sql_query($sql);
return $this;
}
/**
* {@inheritDoc}
*/
public function insert()
{
if (!empty($this->data['category_id']))
{
throw new runtime_exception('ASS_ERROR_ALREADY_EXISTS');
}
$sql = 'SELECT COALESCE(MAX(category_order), 0) as category_order FROM ' . $this->categories_table;
$result = $this->db->sql_query($sql);
$order = (int) $this->db->sql_fetchfield('category_order');
$this->db->sql_freeresult($result);
$this->data['category_order'] = ++$order;
$sql = 'INSERT INTO ' . $this->categories_table . ' ' . $this->db->sql_build_array('INSERT', $this->data);
$this->db->sql_query($sql);
$this->data['category_id'] = (int) $this->db->sql_nextid();
return $this;
}
/**
* {@inheritDoc}
*/
public function get_id()
{
return isset($this->data['category_id']) ? (int) $this->data['category_id'] : 0;
}
/**
* {@inheritDoc}
*/
public function get_title()
{
return isset($this->data['category_title']) ? (string) $this->data['category_title'] : '';
}
/**
* {@inheritDoc}
*/
public function set_title($title)
{
$title = (string) $title;
if ($title === '')
{
throw new runtime_exception('ASS_ERROR_TOO_SHORT', ['TITLE', 0, 0]);
}
if (($length = utf8_strlen($title)) > 255)
{
throw new runtime_exception('ASS_ERROR_TOO_LONG', ['TITLE', 255, $length]);
}
$this->data['category_title'] = $title;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_slug()
{
return isset($this->data['category_slug']) ? (string) $this->data['category_slug'] : '';
}
/**
* {@inheritDoc}
*/
public function set_slug($slug)
{
$slug = (string) $slug;
if ($slug === '')
{
throw new runtime_exception('ASS_ERROR_TOO_SHORT', ['SLUG', 0, 0]);
}
if (($length = utf8_strlen($slug)) > 255)
{
throw new runtime_exception('ASS_ERROR_TOO_LONG', ['SLUG', 255, $length]);
}
// Route should not contain any unexpected special characters
if (!preg_match('/^[^!"#$%&*\'()+,.\/\\\\:;<=>?@\\[\\]^`{|}~ ]*$/', $slug))
{
throw new runtime_exception('ASS_ERROR_ILLEGAL_CHARS', ['SLUG']);
}
// Routes must be unique
if (!$this->get_id() || ($this->get_id() && $this->get_slug() !== '' && $this->get_slug() !== $slug))
{
$sql = 'SELECT category_title
FROM ' . $this->categories_table . "
WHERE category_slug = '" . $this->db->sql_escape($slug) . "'
AND category_id <> " . $this->get_id();
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if ($row !== false)
{
throw new runtime_exception('ASS_ERROR_NOT_UNIQUE', ['SLUG', $row['category_title']]);
}
}
$this->data['category_slug'] = $slug;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_icon()
{
return isset($this->data['category_icon']) ? (string) $this->data['category_icon'] : '';
}
/**
* {@inheritDoc}
*/
public function set_icon($icon)
{
$icon = (string) $icon;
if ($icon === '')
{
throw new runtime_exception('ASS_ERROR_TOO_SHORT', ['ICON', 0, 0]);
}
$this->data['category_icon'] = $icon;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_desc_for_display()
{
return isset($this->data['category_desc']) ? (string) $this->renderer->render(htmlspecialchars_decode($this->data['category_desc'], ENT_COMPAT)) : '';
}
/**
* {@inheritDoc}
*/
public function get_desc()
{
return isset($this->data['category_desc']) ? (string) $this->utils->unparse($this->data['category_desc']) : '';
}
/**
* {@inheritDoc}
*/
public function set_desc($desc)
{
$desc = (string) $desc;
$desc = $this->parser->parse($desc);
$this->data['category_desc'] = $desc;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_active()
{
return isset($this->data['category_active']) ? (bool) $this->data['category_active'] : true;
}
/**
* {@inheritDoc}
*/
public function set_active($active)
{
$active = (bool) $active;
$this->data['category_active'] = $active;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_order()
{
return isset($this->data['category_order']) ? (int) $this->data['category_order'] : 0;
}
/**
* {@inheritDoc}
*/
public function set_order($order)
{
$order = (int) $order;
$this->data['category_order'] = $order;
return $this;
}
/**
* {@inheritDoc}
*/
public function get_conflicts()
{
return isset($this->data['item_conflicts']) ? (int) $this->data['item_conflicts'] : 0;
}
/**
* {@inheritDoc}
*/
public function set_conflicts($conflicts)
{
$conflicts = (int) $conflicts;
$this->data['item_conflicts'] = $conflicts;
return $this;
}
}

View File

@@ -0,0 +1,193 @@
<?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\entity;
use phpbb\exception\runtime_exception;
/**
* phpBB Studio - Advanced Shop System: Category entity interface
*/
interface category_interface
{
/**
* Load the category data.
*
* @param int $id The category identifier
* @param string $slug The category slug
* @return category $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function load($id, $slug = '');
/**
* Import the category data.
*
* @param array $data The category data
* @return category $this This object for chaining calls
* @access public
*/
public function import(array $data);
/**
* Save the category data.
*
* @return category $this This object for chaining calls
* @access public
*/
public function save();
/**
* Insert the category data.
*
* @return category $this This object for chaining calls
* @access public
*/
public function insert();
/**
* Get the category identifier.
*
* @return int The category identifier
* @access public
*/
public function get_id();
/**
* Get the category title.
*
* @return string The category title
* @access public
*/
public function get_title();
/**
* Set the category title.
*
* @param string $title The category title
* @return category $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_title($title);
/**
* Get the category slug.
*
* @return string The category slug
* @access public
*/
public function get_slug();
/**
* Set the category slug
*
* @param string $slug The category slug
* @return category $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_slug($slug);
/**
* Get the category icon.
*
* @return string The category icon
* @access public
*/
public function get_icon();
/**
* Set the category icon.
*
* @param string $icon The category icon.
* @return category $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_icon($icon);
/**
* Get the category description for display (HTML).
*
* @return string The category description
* @access public
*/
public function get_desc_for_display();
/**
* Get the category description for edit (BBCode).
*
* @return string The category description
* @access public
*/
public function get_desc();
/**
* Set the category description for storage (XML).
*
* @param string $desc The category description
* @return category $this This object for chaining calls
* @access public
*/
public function set_desc($desc);
/**
* Get the category active status.
*
* @return bool The category active status
* @access public
*/
public function get_active();
/**
* Set the category active status.
*
* @param bool $active The category active status
* @return category $this This object for chaining calls
* @access public
*/
public function set_active($active);
/**
* Get the category order.
*
* @return int The category order
* @access public
*/
public function get_order();
/**
* Set the category order.
*
* @param int $order The category order
* @return category $this This object for chaining calls
* @access public
*/
public function set_order($order);
/**
* Get the amount of items with conflicts.
*
* @return int The amount of items with conflicts
* @access public
*/
public function get_conflicts();
/**
* Set the amount of items with conflicts.
*
* @param int $conflicts The amount of items with conflicts
* @return category $this This object for chaining calls
* @access public
*/
public function set_conflicts($conflicts);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,785 @@
<?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\entity;
use phpbb\exception\runtime_exception;
/**
* phpBB Studio - Advanced Shop System: Item entity interface
*/
interface item_interface
{
/**
* Load the item data.
*
* @param int $id The item identifier
* @param string $slug The item slug
* @param int $category_id The category identifier
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function load($id, $slug = '', $category_id = 0);
/**
* Import the item data.
*
* @param array $data The item data
* @return item $this This object for chaining calls
* @access public
*/
public function import(array $data);
/**
* Save the item data.
*
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function save();
/**
* Insert the item data.
*
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function insert();
/**
* Get the item identifier.
*
* @return int The item identifier
* @access public
*/
public function get_id();
/**
* Get the category identifier.
*
* @return int The category identifier
* @access public
*/
public function get_category();
/**
* Set the category identifier.
*
* @param int $category_id The category identifier
* @return item $this This object for chaining calls
* @access public
*/
public function set_category($category_id);
/**
* Get the category slug.
*
* @return string The category slug
* @access public
*/
public function get_category_slug();
/**
* Set the category slug.
*
* @param string $slug The category slug
* @return item $this This object for chaining calls
* @access public
*/
public function set_category_slug($slug);
/**
* Set the item title.
*
* @return string The item title
* @access public
*/
public function get_title();
/**
* Set the item title.
*
* @param string $title The item title
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_title($title);
/**
* Get the item slug.
*
* @return string The item slug
* @access public
*/
public function get_slug();
/**
* Set the item slug.
*
* @param string $slug The item slug
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_slug($slug);
/**
* Get the item icon.
*
* @return string The item icon
* @access public
*/
public function get_icon();
/**
* Set the item icon.
*
* @param string $icon The item icon
* @return item $this This object for chaining calls
* @access public
*/
public function set_icon($icon);
/**
* Get the item description for display (HTML).
*
* @return string The item description
* @access public
*/
public function get_desc_for_display();
/**
* Get the item description for edit (BBCode).
*
* @return string The item description
* @access public
*/
public function get_desc();
/**
* Set the item description for storage (XML).
*
* @param string $desc The item description
* @return item $this This object for chaining calls
* @access public
*/
public function set_desc($desc);
/**
* Get the item active status
*
* @return bool The item active status
* @access public
*/
public function get_active();
/**
* Set the item active status
*
* @param bool $active The item active status
* @return item $this This object for chaining calls
* @access public
*/
public function set_active($active);
/**
* Get the item order.
*
* @return int The item order
* @access public
*/
public function get_order();
/**
* Set the item order.
*
* @param int $order The item order
* @return item $this This object for chaining calls
* @access public
*/
public function set_order($order);
/**
* Get the item type.
*
* @return string The item type
* @access public
*/
public function get_type();
/**
* Set the item type.
*
* @param string $type The item type
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_type($type);
/**
* Get the item type data.
*
* @return array The item type data
* @access public
*/
public function get_data();
/**
* Set the item type data.
*
* @param array $data The item type data
* @return item $this This object for chaining calls
* @access public
*/
public function set_data(array $data);
/**
* Get the item price.
*
* @return double The item price
* @access public
*/
public function get_price();
/**
* Set the item price.
*
* @param double $price The item price
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_price($price);
/**
* Get the item use count.
*
* @return int The item use count
* @access public
*/
public function get_count();
/**
* Set the item use count.
*
* @param int $count The item use count
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_count($count);
/**
* Get the item stack count.
*
* @return int The item stack count
* @access public
*/
public function get_stack();
/**
* Set the item stack count.
*
* @param int $stack The item stack count
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_stack($stack);
/**
* Get the item purchases.
*
* @return int The item purchases
* @access public
*/
public function get_purchases();
/**
* Set the item purchases.
*
* @param int $purchases The item purchases
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_purchases($purchases);
/**
* Get the item stock.
*
* @return int The item stock
* @access public
*/
public function get_stock();
/**
* Set the item stock.
*
* @param int $stock The item stock
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_stock($stock);
/**
* Get the item stock notification threshold.
*
* @return int The item stock notification threshold
* @access public
*/
public function get_stock_threshold();
/**
* Set the item stock notification threshold.
*
* @param int $threshold The item stock notification threshold
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_stock_threshold($threshold);
/**
* Get the item unlimited stock status.
*
* @return bool The item unlimited stock status
* @access public
*/
public function get_stock_unlimited();
/**
* Set the item unlimited stock status.
*
* @param int $unlimited The item unlimited stock status
* @return item $this This object for chaining calls
* @access public
*/
public function set_stock_unlimited($unlimited);
/**
* Get the item expire string.
*
* @return string The item expire string
* @access public
*/
public function get_expire_string();
/**
* Set the item expire string.
*
* @param string $string The item expire string
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_expire_string($string);
/**
* Get the item expire seconds.
*
* @return int The item expire seconds
* @access public
*/
public function get_expire_seconds();
/**
* Set the item expire seconds.
*
* @param int $seconds The item expire seconds
* @return $this
* @access public
*/
public function set_expire_seconds($seconds);
/**
* Get the item delete string.
*
* @return string The item delete string
* @access public
*/
public function get_delete_string();
/**
* Set the item delete string.
*
* @param string $string The item delete string
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_delete_string($string);
/**
* Get the item delete seconds.
*
* @return int The item delete seconds
* @access public
*/
public function get_delete_seconds();
/**
* Set the item delete seconds.
*
* @param int $seconds The item delete seconds
* @return $this
* @access public
*/
public function set_delete_seconds($seconds);
/**
* Get the item refund string.
*
* @return string The item refund string
* @access public
*/
public function get_refund_string();
/**
* Set the item refund string.
*
* @param string $string The item refund string
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_refund_string($string);
/**
* Get the item refund seconds.
*
* @return int The item refund seconds
* @access public
*/
public function get_refund_seconds();
/**
* Set the item refund seconds.
*
* @param int $seconds The item refund seconds
* @return $this
* @access public
*/
public function set_refund_seconds($seconds);
/**
* Get the item gift status.
*
* @return bool The item gift status
* @access public
*/
public function get_gift();
/**
* Set the item gift status.
*
* @param bool $gift The item gift status
* @return item $this This object for chaining calls
* @access public
*/
public function set_gift($gift);
/**
* Get the item gift only status.
*
* @return bool The item gift only status
* @access public
*/
public function get_gift_only();
/**
* Set the item gift only status.
*
* @param bool $gift_only The item gift only status
* @return item $this This object for chaining calls
* @access public
*/
public function set_gift_only($gift_only);
/**
* Get the item gift type.
*
* @return bool The item gift type
* @access public
*/
public function get_gift_type();
/**
* Set the item gift type.
*
* @param bool $type The item gift type
* @return item $this This object for chaining calls
* @access public
*/
public function set_gift_type($type);
/**
* Get the item gift price percentage.
*
* @return int The item gift price percentage
* @access public
*/
public function get_gift_percentage();
/**
* Set the item gift price percentage.
*
* @param int $percentage The item gift price percentage
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_gift_percentage($percentage);
/**
* Get the item gift price.
*
* @return double The item gift price
* @access public
*/
public function get_gift_price();
/**
* Set the item gift price.
*
* @param double $price The item gift price
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_gift_price($price);
/**
* Get the item sale price.
*
* @return double The item sale price
* @access public
*/
public function get_sale_price();
/**
* Set the item sale price.
*
* @param double $price The item sale price
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_sale_price($price);
/**
* Set the item sale start timestamp.
*
* @return int The item sale start timestamp
* @access public
*/
public function get_sale_start();
/**
* Set the item sale start timestamp.
*
* @param int $time The item sale start timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_sale_start($time);
/**
* Get the item sale until timestamp.
*
* @return int The item sale until timestamp
* @access public
*/
public function get_sale_until();
/**
* Set the item sale until timestamp.
*
* @param int $time The item sale until timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_sale_until($time);
/**
* Get the item featured start timestamp.
*
* @return int The item featured start timestamp
* @access public
*/
public function get_featured_start();
/**
* Set the item featured start timestamp.
*
* @param int $time The item featured start timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_featured_start($time);
/**
* Get the item featured until timestamp.
*
* @return int The item featured until timestamp
* @access public
*/
public function get_featured_until();
/**
* Set the item featured until timestamp.
*
* @param int $time The item featured until timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_featured_until($time);
/**
* Get the item available start timestamp.
*
* @return int The item available start timestamp
* @access public
*/
public function get_available_start();
/**
* Set the item available start timestamp.
*
* @param int $time The item available start timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_available_start($time);
/**
* Get the item available until timestamp.
*
* @return int The item available until timestamp
* @access public
*/
public function get_available_until();
/**
* Set the item available until timestamp.
*
* @param int $time The item available until timestamp
* @return item $this This object for chaining calls
* @access public
*/
public function set_available_until($time);
/**
* Get the item background image.
*
* @return string The item background image
* @access public
*/
public function get_background();
/**
* Set the item background image.
*
* @param string $background The item background image
* @return item $this This object for chaining calls
* @access public
*/
public function set_background($background);
/**
* Get the item images.
*
* @return array The item images.
* @access public
*/
public function get_images();
/**
* Set the item images.
*
* @param array $images The item images
* @return item $this This object for chaining calls
* @access public
*/
public function set_images(array $images);
/**
* Get the item related items status.
*
* @return bool The item related item status
* @access public
*/
public function get_related_enabled();
/**
* Set the item related items status.
*
* @param bool $related The item related item status
* @return item $this This object for chaining calls
* @throws runtime_exception
* @access public
*/
public function set_related_enabled($related);
/**
* Get the item related items.
*
* @return array The item related items.
* @access public
*/
public function get_related_items();
/**
* Set the item related items.
*
* @param array $items The item related items
* @return item $this This object for chaining calls
* @access public
*/
public function set_related_items(array $items);
/**
* Get the item creation timestamp.
*
* @return int The item creation timestamp
* @access public
*/
public function get_create_time();
/**
* Get the item last edited timestamp.
*
* @return int The item last edited timestamp
* @access public
*/
public function get_edit_time();
/**
* Get the item conflict state.
*
* @return bool The item conflict state
* @access public
*/
public function get_conflict();
/**
* Set the item conflict state.
*
* @param bool $state The item conflict state
* @return item $this This object for chaining calls
* @access public
*/
public function set_conflict($state);
}