c
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Page\AdminController;
|
||||
|
||||
use Hura8\Components\Page\Controller\bPageController;
|
||||
use Hura8\Interfaces\iEntityAdminController;
|
||||
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
class APageController extends bPageController implements iEntityAdminController
|
||||
{
|
||||
|
||||
use AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
public function updateTableInfo($item_id, array $new_item_info) {
|
||||
return $this->objPageModel->updateTableInfo($item_id, $new_item_info);
|
||||
}
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// delete thumb files
|
||||
$item_info = $this->getInfo($item_id);
|
||||
$this->deleteThumbnailFile($item_info['thumbnail']);
|
||||
|
||||
//delete media files?
|
||||
// todo:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function deleteThumbnailFile($file_name): bool
|
||||
{
|
||||
if(!$file_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::$resized_sizes as $size => $value) {
|
||||
$file_local_path = PUBLIC_DIR . "/". self::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||
unlink($file_local_path);
|
||||
}
|
||||
|
||||
// remove original file
|
||||
$file_local_path = PUBLIC_DIR . "/". self::$image_folder . "/". $file_name;
|
||||
return unlink($file_local_path);
|
||||
}
|
||||
|
||||
}
|
||||
92
inc/Hura8/Components/Page/Controller/bPageController.php
Normal file
92
inc/Hura8/Components/Page/Controller/bPageController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Page\Controller;
|
||||
|
||||
|
||||
use Hura8\Components\Page\Model\PageLanguageModel;
|
||||
use Hura8\Components\Page\Model\PageModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
class bPageController extends aEntityBaseController
|
||||
{
|
||||
|
||||
static $image_folder = "media/static";
|
||||
|
||||
static $resized_sizes = array(
|
||||
't' => ['width' => 200,] ,
|
||||
'l' => ['width' => 600,] ,
|
||||
);
|
||||
|
||||
|
||||
protected $objPageModel;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objPageModel = new PageModel();
|
||||
|
||||
if(!$this->isDefaultLanguage()) {
|
||||
//$this->objPageLanguageModel->createTableLang();
|
||||
parent::__construct($this->objPageModel, new PageLanguageModel());
|
||||
}else{
|
||||
parent::__construct($this->objPageModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get full info- basic with description
|
||||
public function getFullInfo($id) : ?array
|
||||
{
|
||||
if(!$id) return null;
|
||||
|
||||
return self::getCache("getFullInfo-".$id."-".$this->view_language, function () use ($id){
|
||||
|
||||
$info = $this->objPageModel->getFullInfo($id);
|
||||
|
||||
if($this->iEntityLanguageModel && $info ) {
|
||||
$item_language_info = $this->iEntityLanguageModel->getInfo($id);
|
||||
if($item_language_info) {
|
||||
return $this->formatItemInfo(array_merge($info, $item_language_info));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->formatItemInfo($info);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInfo(array $item_info)
|
||||
{
|
||||
if(!$item_info) return null;
|
||||
|
||||
$info = $item_info;
|
||||
$info['image'] = self::getResizedImageCollection($info['thumbnail']);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInList(array $item_info)
|
||||
{
|
||||
return $this->formatItemInfo($item_info);
|
||||
}
|
||||
|
||||
|
||||
public static function getResizedImageCollection($image_name) {
|
||||
$image = [];
|
||||
|
||||
$size_in_full = [
|
||||
't' => 'thumb' ,
|
||||
's' => 'small' ,
|
||||
'l' => 'large' ,
|
||||
];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
21
inc/Hura8/Components/Page/Model/PageLanguageModel.php
Normal file
21
inc/Hura8/Components/Page/Model/PageLanguageModel.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Page\Model;
|
||||
|
||||
use Hura8\System\Model\EntityLanguageModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
class PageLanguageModel extends EntityLanguageModel
|
||||
{
|
||||
|
||||
protected $richtext_fields = [
|
||||
'content',
|
||||
'content_html',
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::PAGE, '', $this->richtext_fields);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
inc/Hura8/Components/Page/Model/PageModel.php
Normal file
76
inc/Hura8/Components/Page/Model/PageModel.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Page\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
use Hura8\System\Controller\UrlManagerController;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\System\ModuleManager;
|
||||
|
||||
class PageModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $richtext_fields = [
|
||||
'content',
|
||||
'content_html',
|
||||
];
|
||||
|
||||
protected $tb_page_info = "tb_page_info";
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::PAGE, '', null, $this->richtext_fields);
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getFullInfo($id) : ?array
|
||||
{
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT * FROM `".$this->tb_entity."` basic, `".$this->tb_page_info."` info
|
||||
WHERE basic.`id` = info.`page_id` AND basic.id = ?
|
||||
LIMIT 1 ",
|
||||
['d'], [$id]
|
||||
);
|
||||
|
||||
if( $item_info = $this->db->fetchAssoc($query)){
|
||||
return $item_info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
);*/
|
||||
|
||||
/*$condition = array(
|
||||
"letter" => "",
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
/*if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
|
||||
$catCondition[] = " AND `letter` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["letter"];
|
||||
}*/
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user