c
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\AdminController;
|
||||
|
||||
use Hura8\Components\Media\Controller\bItemMediaController;
|
||||
use Hura8\Interfaces\iEntityAdminController;
|
||||
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
class AItemMediaController extends bItemMediaController implements iEntityAdminController
|
||||
{
|
||||
|
||||
use AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// delete thumb files
|
||||
$item_info = $this->getInfo($item_id);
|
||||
if(!$item_info['file_url']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$file_name = $item_info['file_url'];
|
||||
|
||||
foreach (static::$resized_sizes as $size => $value) {
|
||||
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||
@unlink($file_local_path);
|
||||
}
|
||||
|
||||
// remove original file
|
||||
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $file_name;
|
||||
@unlink($file_local_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\AdminController;
|
||||
|
||||
use Hura8\Components\Media\Controller\bMediaCategoryController;
|
||||
use Hura8\Interfaces\iEntityAdminCategoryController;
|
||||
use Hura8\Traits\AdminEntityCategoryControllerTraits;
|
||||
|
||||
|
||||
class AMediaCategoryController extends bMediaCategoryController implements iEntityAdminCategoryController
|
||||
{
|
||||
use AdminEntityCategoryControllerTraits;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\AdminController;
|
||||
|
||||
use Hura8\Components\Media\Controller\bMediaController;
|
||||
use Hura8\Interfaces\iEntityAdminController;
|
||||
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
class AMediaController extends bMediaController implements iEntityAdminController
|
||||
{
|
||||
|
||||
use AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
public static function createUploadSubFolder() {
|
||||
return date("Y-m-d");
|
||||
}
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// delete thumb files
|
||||
$item_info = $this->getInfo($item_id);
|
||||
if(!$item_info['file_url']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
list($sub_folder, $file_name) = explode("/", $item_info['file_url']); // format: Y-m-d/file_name
|
||||
|
||||
foreach (static::$resized_sizes as $size => $value) {
|
||||
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/" . $sub_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||
@unlink($file_local_path);
|
||||
}
|
||||
|
||||
// remove original file
|
||||
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/" . $sub_folder . "/". $file_name;
|
||||
@unlink($file_local_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Controller;
|
||||
|
||||
use Hura8\Components\Media\Model\ItemMediaModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
|
||||
class bItemMediaController extends aEntityBaseController
|
||||
{
|
||||
static $image_folder = "media/item";
|
||||
|
||||
static $resized_sizes = array(
|
||||
's' => ['width' => 300,]
|
||||
);
|
||||
|
||||
/* @var ItemMediaModel $objItemMediaModel */
|
||||
protected $objItemMediaModel;
|
||||
|
||||
protected $item_type;
|
||||
protected $item_id;
|
||||
|
||||
public function __construct(string $item_type = '', $item_id = 0)
|
||||
{
|
||||
$this->objItemMediaModel = new ItemMediaModel($item_type, $item_id);
|
||||
parent::__construct($this->objItemMediaModel);
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInList(array $item_info) : array
|
||||
{
|
||||
return $this->formatItemInfo($item_info);
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInfo(array $item_info) : ?array
|
||||
{
|
||||
if(!$item_info) return null;
|
||||
|
||||
$item_info['display_file'] = STATIC_DOMAIN . "/". static::$image_folder. "/". $item_info['file_url'];
|
||||
$item_info['image'] = self::getResizedImageCollection($item_info['file_url']);
|
||||
|
||||
return $item_info;
|
||||
}
|
||||
|
||||
|
||||
public static function getResizedImageCollection($image_name) {
|
||||
$image = [];
|
||||
|
||||
$size_in_full = [
|
||||
's' => 'small' ,
|
||||
];
|
||||
|
||||
foreach (static::$resized_sizes as $size => $value) {
|
||||
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Controller;
|
||||
|
||||
use Hura8\System\Controller\aCategoryBaseController;
|
||||
use Hura8\Components\Media\Model\MediaCategoryModel;
|
||||
|
||||
|
||||
class bMediaCategoryController extends aCategoryBaseController
|
||||
{
|
||||
|
||||
protected $objMediaCategoryModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objMediaCategoryModel = new MediaCategoryModel();
|
||||
parent::__construct($this->objMediaCategoryModel);
|
||||
}
|
||||
|
||||
}
|
||||
59
inc/Hura8/Components/Media/Controller/bMediaController.php
Normal file
59
inc/Hura8/Components/Media/Controller/bMediaController.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Controller;
|
||||
|
||||
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||
use Hura8\Components\Media\Model\MediaModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
|
||||
class bMediaController extends aEntityBaseController
|
||||
{
|
||||
static $image_folder = "media/lib";
|
||||
|
||||
static $resized_sizes = array(
|
||||
's' => ['width' => 300,]
|
||||
);
|
||||
|
||||
protected $objMediaModel;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objMediaModel = new MediaModel();
|
||||
parent::__construct($this->objMediaModel);
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInList(array $item_info) : array
|
||||
{
|
||||
return $this->formatItemInfo($item_info);
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInfo(array $item_info) : ?array
|
||||
{
|
||||
if(!$item_info) return null;
|
||||
|
||||
$item_info['display_file'] = STATIC_DOMAIN . "/". static::$image_folder. "/". $item_info['file_url'];
|
||||
$item_info['image'] = ($item_info['file_type'] == 'image') ? self::getResizedImageCollection($item_info['file_url']) : null;
|
||||
|
||||
return $item_info;
|
||||
}
|
||||
|
||||
|
||||
public static function getResizedImageCollection($image_name) {
|
||||
$image = [];
|
||||
|
||||
$size_in_full = [
|
||||
's' => 'small' ,
|
||||
];
|
||||
|
||||
foreach (static::$resized_sizes as $size => $value) {
|
||||
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
}
|
||||
76
inc/Hura8/Components/Media/Model/ItemMediaModel.php
Normal file
76
inc/Hura8/Components/Media/Model/ItemMediaModel.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\System\Url;
|
||||
|
||||
|
||||
class ItemMediaModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $item_type;
|
||||
protected $item_id;
|
||||
|
||||
public function __construct(string $item_type = '', $item_id = 0) {
|
||||
parent::__construct('item-media');
|
||||
|
||||
$this->item_type = $item_type;
|
||||
$this->item_id = $item_id;
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
if($this->item_type) {
|
||||
$catCondition[] = " AND `item_type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $this->item_type;
|
||||
}
|
||||
|
||||
if($this->item_id) {
|
||||
$catCondition[] = " AND `item_id` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = $this->item_id;
|
||||
}
|
||||
|
||||
if(isset($filter_condition["item_type"]) && $filter_condition["item_type"]){
|
||||
$catCondition[] = " AND `item_type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["item_type"];
|
||||
}
|
||||
|
||||
if(isset($filter_condition["item_id"]) && $filter_condition["item_id"]){
|
||||
$catCondition[] = " AND `item_id` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["item_id"];
|
||||
}
|
||||
|
||||
if(isset($filter_condition["file_type"]) && $filter_condition["file_type"]){
|
||||
$catCondition[] = " AND `file_type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["file_type"];
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
34
inc/Hura8/Components/Media/Model/ItemMediaSearchModel.php
Normal file
34
inc/Hura8/Components/Media/Model/ItemMediaSearchModel.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Model;
|
||||
|
||||
use Hura8\Interfaces\iSearch;
|
||||
use Hura8\System\Model\aSearchBaseModel;
|
||||
|
||||
|
||||
class ItemMediaSearchModel extends aSearchBaseModel implements iSearch
|
||||
{
|
||||
|
||||
private $filter_fields = [
|
||||
'item_type' => "tb_item_media.item_type",
|
||||
'item_id' => "tb_item_media.item_id",
|
||||
'file_type' => "tb_item_media.file_type",
|
||||
];
|
||||
|
||||
private $fulltext_fields = [
|
||||
"keywords" => ["tb_item_media.title",],
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
"tb_item_media",
|
||||
$this->fulltext_fields,
|
||||
$this->filter_fields
|
||||
);
|
||||
|
||||
//$this->createTableSearch();
|
||||
}
|
||||
|
||||
}
|
||||
20
inc/Hura8/Components/Media/Model/MediaCategoryModel.php
Normal file
20
inc/Hura8/Components/Media/Model/MediaCategoryModel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aCategoryBaseModel;
|
||||
use Hura8\Interfaces\iEntityCategoryModel;
|
||||
|
||||
|
||||
class MediaCategoryModel extends aCategoryBaseModel implements iEntityCategoryModel
|
||||
{
|
||||
protected $tb_media_per_category = "tb_media_per_category";
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('media-category');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
61
inc/Hura8/Components/Media/Model/MediaModel.php
Normal file
61
inc/Hura8/Components/Media/Model/MediaModel.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
use Hura8\System\Url;
|
||||
|
||||
|
||||
class MediaModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $tb_media_per_category = "tb_media_per_category";
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::MEDIA, '', new MediaSearchModel());
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"category" => getRequestInt("category"),
|
||||
"file_type" => '',
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
|
||||
//Tim danh muc
|
||||
if(isset($filter_condition["category"]) && $filter_condition["category"]){
|
||||
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_media_per_category."` WHERE `category_id` = ?) ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = $filter_condition["category"];
|
||||
}
|
||||
|
||||
if(isset($filter_condition["file_type"]) && $filter_condition["file_type"]){
|
||||
$catCondition[] = " AND `file_type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["file_type"];
|
||||
}
|
||||
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
32
inc/Hura8/Components/Media/Model/MediaSearchModel.php
Normal file
32
inc/Hura8/Components/Media/Model/MediaSearchModel.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Media\Model;
|
||||
|
||||
use Hura8\Interfaces\iSearch;
|
||||
use Hura8\System\Model\aSearchBaseModel;
|
||||
|
||||
|
||||
class MediaSearchModel extends aSearchBaseModel implements iSearch
|
||||
{
|
||||
|
||||
private $filter_fields = [
|
||||
'file_type' => "tb_media.file_type",
|
||||
];
|
||||
|
||||
private $fulltext_fields = [
|
||||
"keywords" => ["tb_media.title",],
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
"tb_media",
|
||||
$this->fulltext_fields,
|
||||
$this->filter_fields
|
||||
);
|
||||
|
||||
//$this->createTableSearch();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user