update
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\AdminController;
|
||||
|
||||
use Hura8\Components\User\Model\NewsletterModel;
|
||||
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||
|
||||
class ANewsletterController extends aAdminEntityBaseController
|
||||
{
|
||||
/* @var NewsletterModel $objNewsletterModel */
|
||||
protected $objNewsletterModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objNewsletterModel = new NewsletterModel();
|
||||
parent::__construct($this->objNewsletterModel);
|
||||
}
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\AdminController;
|
||||
|
||||
use Hura8\Components\User\Model\UserCommentModel;
|
||||
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||
|
||||
|
||||
class AUserCommentController extends aAdminEntityBaseController
|
||||
{
|
||||
/* @var UserCommentModel $objUserCommentModel */
|
||||
protected $objUserCommentModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objUserCommentModel = new UserCommentModel();
|
||||
parent::__construct($this->objUserCommentModel);
|
||||
}
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\AdminController;
|
||||
|
||||
use Hura8\Components\User\Model\UserContactModel;
|
||||
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||
|
||||
|
||||
class AUserContactController extends aAdminEntityBaseController
|
||||
{
|
||||
/* @var UserContactModel $objUserContactModel */
|
||||
protected $objUserContactModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objUserContactModel = new UserContactModel();
|
||||
parent::__construct($this->objUserContactModel);
|
||||
}
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\AdminController;
|
||||
|
||||
use Hura8\Components\User\Controller\bUserController;
|
||||
use Hura8\Interfaces\iEntityAdminController;
|
||||
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||
|
||||
class AUserController extends bUserController implements iEntityAdminController
|
||||
{
|
||||
use AdminEntityBaseControllerTraits;
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\AdminController;
|
||||
|
||||
use Hura8\Components\User\Model\UserReviewModel;
|
||||
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||
|
||||
|
||||
class AUserReviewController extends aAdminEntityBaseController
|
||||
{
|
||||
/* @var UserReviewModel $objUserReviewModel */
|
||||
protected $objUserReviewModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objUserReviewModel = new UserReviewModel();
|
||||
parent::__construct($this->objUserReviewModel);
|
||||
}
|
||||
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
35
inc/Hura8/Components/User/Controller/bUserController.php
Normal file
35
inc/Hura8/Components/User/Controller/bUserController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Controller;
|
||||
|
||||
|
||||
use Hura8\Components\User\Model\UserModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
use Hura8\System\Security\Cookie;
|
||||
|
||||
|
||||
class bUserController extends aEntityBaseController
|
||||
{
|
||||
|
||||
protected $web_user_id = '';
|
||||
|
||||
protected $objUserModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->web_user_id = self::getWebUserId();
|
||||
$this->objUserModel = new UserModel($this->web_user_id );
|
||||
parent::__construct($this->objUserModel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description this value is set by hura.js for anonymous web users
|
||||
* @return string
|
||||
*/
|
||||
public static function getWebUserId() {
|
||||
return Cookie::get("uID", '');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Controller;
|
||||
|
||||
use Hura8\Components\User\Model\UserReviewModel;
|
||||
use Hura8\Components\User\PublicController\UUserController;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
|
||||
class bUserReviewController extends aEntityBaseController
|
||||
{
|
||||
protected $web_user_id = '';
|
||||
|
||||
protected $objUserReviewModel;
|
||||
|
||||
public function __construct($item_type, $item_id = 0) {
|
||||
|
||||
$this->web_user_id = UUserController::getWebUserId();
|
||||
|
||||
$this->objUserReviewModel = new UserReviewModel($item_type, $item_id);
|
||||
|
||||
parent::__construct($this->objUserReviewModel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Controller;
|
||||
|
||||
use Hura8\Components\Customer\PublicController\UCustomerLoginController;
|
||||
use Hura8\Components\User\AdminController\AUserController;
|
||||
use Hura8\Components\User\Model\UserUploadModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
class bUserUploadController extends aEntityBaseController
|
||||
{
|
||||
protected $web_user_id = '';
|
||||
protected $customer_id = 0;
|
||||
protected $item_type = '';
|
||||
protected $item_id = '';
|
||||
|
||||
public function __construct($item_type='', $item_id=0) {
|
||||
$this->web_user_id = AUserController::getWebUserId();
|
||||
$this->customer_id = UCustomerLoginController::getLoggedInCustomerId();
|
||||
|
||||
$this->item_type = $item_type;
|
||||
$this->item_id = $item_id;
|
||||
|
||||
parent::__construct(new UserUploadModel($this->web_user_id, $this->customer_id, $item_type, $item_id));
|
||||
}
|
||||
|
||||
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||
{
|
||||
// delete thumb files
|
||||
$item_info = $this->getInfo($item_id);
|
||||
|
||||
if($item_info['file_path']) {
|
||||
$file_local_path = PUBLIC_DIR . "/". $item_info['file_path'];
|
||||
@unlink($file_local_path);
|
||||
}
|
||||
|
||||
// ok
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
73
inc/Hura8/Components/User/Model/NewsletterModel.php
Normal file
73
inc/Hura8/Components/User/Model/NewsletterModel.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
class NewsletterModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('newsletter');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||
{
|
||||
$info = $input_info;
|
||||
|
||||
$info['create_time'] = CURRENT_TIME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||
{
|
||||
// TODO: Implement afterCreateItem() method.
|
||||
}
|
||||
|
||||
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||
{
|
||||
return new AppResponse('ok', null, $new_input_info);
|
||||
}
|
||||
|
||||
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||
{
|
||||
// TODO: Implement afterUpdateItem() method.
|
||||
}
|
||||
|
||||
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||
{
|
||||
return new AppResponse('ok');
|
||||
}
|
||||
|
||||
protected function afterDeleteItem($item_id, $item_info)
|
||||
{
|
||||
// TODO: Implement afterDeleteItem() method.
|
||||
}
|
||||
}
|
||||
90
inc/Hura8/Components/User/Model/UserCommentModel.php
Normal file
90
inc/Hura8/Components/User/Model/UserCommentModel.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class UserCommentModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::USER_COMMENT);
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
'read' => 1,-1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
|
||||
if(isset($condition["read"]) && $condition["read"]){
|
||||
$catCondition[] = " AND `is_read` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($condition["read"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||
{
|
||||
$info = $input_info;
|
||||
|
||||
$info['create_time'] = CURRENT_TIME;
|
||||
$info['create_by'] = ADMIN_NAME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||
{
|
||||
$info = $new_input_info;
|
||||
|
||||
$info['last_update'] = CURRENT_TIME;
|
||||
$info['last_update_by'] = ADMIN_NAME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||
{
|
||||
return new AppResponse('ok');
|
||||
}
|
||||
|
||||
protected function afterDeleteItem($item_id, $item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
96
inc/Hura8/Components/User/Model/UserCommentReplyModel.php
Normal file
96
inc/Hura8/Components/User/Model/UserCommentReplyModel.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class UserCommentReplyModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::USER_COMMENT_REPLY);
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
'read' => 1,-1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
|
||||
if(isset($condition["read"]) && $condition["read"]){
|
||||
$catCondition[] = " AND `is_read` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($condition["read"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
protected function _buildQueryOrderBy($sort_by = "new")
|
||||
{
|
||||
return parent::_buildQueryOrderBy($sort_by);
|
||||
}
|
||||
|
||||
|
||||
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||
{
|
||||
$info = $input_info;
|
||||
|
||||
$info['create_time'] = CURRENT_TIME;
|
||||
$info['create_by'] = ADMIN_NAME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||
{
|
||||
$info = $new_input_info;
|
||||
|
||||
$info['last_update'] = CURRENT_TIME;
|
||||
$info['last_update_by'] = ADMIN_NAME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||
{
|
||||
return new AppResponse('ok');
|
||||
}
|
||||
|
||||
protected function afterDeleteItem($item_id, $item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
54
inc/Hura8/Components/User/Model/UserContactModel.php
Normal file
54
inc/Hura8/Components/User/Model/UserContactModel.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class UserContactModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::USER_CONTACT);
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
'read' => 1,-1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
if(isset($condition["read"]) && $condition["read"]){
|
||||
$catCondition[] = " AND `is_read` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($condition["read"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
protected function _buildQueryOrderBy($sort_by = "new")
|
||||
{
|
||||
return parent::_buildQueryOrderBy($sort_by);
|
||||
}
|
||||
|
||||
}
|
||||
58
inc/Hura8/Components/User/Model/UserModel.php
Normal file
58
inc/Hura8/Components/User/Model/UserModel.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
|
||||
|
||||
class UserModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $web_user_id = '';
|
||||
protected $user_db_id = 0;
|
||||
|
||||
public function __construct($web_user_id, $user_db_id = 0) {
|
||||
$this->web_user_id = $web_user_id;
|
||||
$this->user_db_id = $user_db_id;
|
||||
|
||||
parent::__construct('web_user_info');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
218
inc/Hura8/Components/User/Model/UserReviewModel.php
Normal file
218
inc/Hura8/Components/User/Model/UserReviewModel.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
use Hura8\Components\Customer\PublicController\UCustomerLoginController;
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Interfaces\iEntityStatistic;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\System\Security\DataClean;
|
||||
use Hura8\System\Security\DataType;
|
||||
|
||||
|
||||
class UserReviewModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $rules = [
|
||||
'require-user-login' => true,
|
||||
'auto-approve-message' => false,
|
||||
'detect-spam-before-create' => true,
|
||||
];
|
||||
|
||||
protected $item_type = '';
|
||||
protected $item_id = 0;
|
||||
|
||||
/* @var ?iEntityStatistic $iEntityStatisticModel */
|
||||
protected $iEntityStatisticModel;
|
||||
|
||||
public function __construct($item_type, $item_id = 0) {
|
||||
|
||||
$this->item_type = $item_type;
|
||||
$this->item_id = $item_id;
|
||||
|
||||
$this->iEntityStatisticModel = get_statistic_model_instance($this->item_type);
|
||||
|
||||
// todo: overwrite default rules by client
|
||||
|
||||
parent::__construct("user-review");
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getSummary(array $conditions = [])
|
||||
{
|
||||
$where_conditions = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
//item_type
|
||||
$where_conditions[] = " AND `item_type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $this->item_type;
|
||||
|
||||
|
||||
//item_id
|
||||
$where_conditions[] = " AND `item_id` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $this->item_id;
|
||||
|
||||
|
||||
//approved
|
||||
if(isset($conditions["approved"]) ){
|
||||
$where_conditions[] = " AND `approved` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($conditions["approved"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT AVG(`rate`) AS avgRate, COUNT(*) AS total FROM `". $this->tb_entity ."` WHERE 1 ".join(" ", $where_conditions),
|
||||
$bind_types, $bind_values
|
||||
);
|
||||
|
||||
if ( $info = $this->db->fetchAssoc($query) ) {
|
||||
return [
|
||||
"avgRate" => $info['avgRate'],
|
||||
"total" => $info['total'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"avgRate" => 0,
|
||||
"total" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
'read' => 1,-1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
if(isset($condition["read"]) && $condition["read"]){
|
||||
$catCondition[] = " AND `is_read` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($condition["read"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||
{
|
||||
//todo: check user's authentication and authorization
|
||||
if($this->rules['require-user-login'] && !UCustomerLoginController::getLoggedInCustomerId()) {
|
||||
return new AppResponse('error', "Login required");
|
||||
}
|
||||
|
||||
$info = $input_info;
|
||||
|
||||
$info['item_type'] = $this->item_type;
|
||||
$info['item_id'] = $this->item_id;
|
||||
|
||||
$info['item_title'] = DataClean::limitLengthFullWords($input_info['item_title'], 50);
|
||||
$info['title'] = DataClean::limitLengthFullWords($input_info['title'], 50);
|
||||
$info['content'] = DataClean::limitLengthFullWords($input_info['content'], 500);
|
||||
|
||||
$info['user_id'] = '';
|
||||
$info['user_email'] = DataClean::makeInputSafe($input_info['user_email'], DataType::EMAIL);
|
||||
$info['user_name'] = DataClean::limitLengthFullWords($input_info['user_name'], 50);
|
||||
|
||||
// todo: check files actually exists and belong to this user
|
||||
$info['files'] = (is_array($input_info['files'])) ? DataClean::makeListOfInputSafe($input_info['files'], DataType::INTEGER) : null;
|
||||
|
||||
//$info['approved'] = (CONFIG_AUTO_APPROVE_REVIEW) ? 1 : 0;
|
||||
$info['rate'] = (in_array($info['rate'], [1,2,3,4,5])) ? $info['rate'] : 0;
|
||||
$info['ip_address'] = USER_IP;
|
||||
$info['user_agent'] = substr(USER_AGENT, 0, 200);
|
||||
|
||||
/*
|
||||
"item_type" => $post_info['item_type'],
|
||||
"item_id" => $post_info['item_id'],
|
||||
"item_title" => $post_info['item_title'],
|
||||
"is_user_admin" => $post_info['is_user_admin'],
|
||||
"user_id" => USER_ID,
|
||||
"user_email" => $post_info['user_email'],
|
||||
"user_name" => $post_info['user_name'],
|
||||
"user_avatar" => $post_info['user_avatar'],
|
||||
"user_note" => $post_info['user_note'],
|
||||
"rate" => (int) $post_info['rate'],
|
||||
"title" => $post_info['title'],
|
||||
"content" => $post_info['content'],
|
||||
"files" => $post_info['files'],
|
||||
"approved" => (CONFIG_AUTO_APPROVE_REVIEW) ? 1 : 0,
|
||||
"post_time" => CURRENT_TIME,
|
||||
"ip_address" => USER_IP,
|
||||
"user_agent" => substr(USER_AGENT, 0, 200),*/
|
||||
|
||||
$info['create_time'] = CURRENT_TIME;
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
|
||||
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||
{
|
||||
// update summary for item
|
||||
$this->updateItemReviewCount();
|
||||
}
|
||||
|
||||
|
||||
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||
{
|
||||
//todo: check user's authentication and authorization
|
||||
|
||||
$info = $new_input_info;
|
||||
|
||||
$info['last_update'] = CURRENT_TIME;
|
||||
$info['last_update_by'] = '';
|
||||
|
||||
return new AppResponse('ok', null, $info);
|
||||
}
|
||||
|
||||
|
||||
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||
{
|
||||
//todo: check user's authentication and authorization
|
||||
|
||||
return new AppResponse('ok');
|
||||
}
|
||||
|
||||
|
||||
protected function afterDeleteItem($item_id, $item_info)
|
||||
{
|
||||
// update summary for item
|
||||
$this->updateItemReviewCount();
|
||||
}
|
||||
|
||||
|
||||
protected function updateItemReviewCount()
|
||||
{
|
||||
// update summary for item
|
||||
if($this->iEntityStatisticModel) {
|
||||
$summary = $this->getSummary([]);
|
||||
$this->iEntityStatisticModel->updateReviewCount($this->item_id, $summary['total'], $summary['avgRate']);
|
||||
}
|
||||
}
|
||||
}
|
||||
63
inc/Hura8/Components/User/Model/UserUploadModel.php
Normal file
63
inc/Hura8/Components/User/Model/UserUploadModel.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\User\Model;
|
||||
|
||||
use Hura8\Components\Customer\PublicController\UCustomerLoginController;
|
||||
use Hura8\Components\Staff\PublicController\StaffLoginController;
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
class UserUploadModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $web_user_id = '';
|
||||
protected $customer_id = 0;
|
||||
protected $item_type = '';
|
||||
protected $item_id = '';
|
||||
|
||||
|
||||
public function __construct($web_user_id, $customer_id, $item_type='', $item_id=0) {
|
||||
parent::__construct('user_upload');
|
||||
|
||||
$this->web_user_id = $web_user_id;
|
||||
$this->customer_id = $customer_id;
|
||||
$this->item_id = $item_id;
|
||||
$this->item_type = $item_type;
|
||||
}
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"q" => "",
|
||||
"status" => 0,
|
||||
'read' => 1,-1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
if(isset($condition["type"]) && $condition["type"]){
|
||||
$catCondition[] = " AND `type` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $condition["type"];
|
||||
}
|
||||
|
||||
if(isset($condition["approved"]) && $condition["approved"]){
|
||||
$catCondition[] = " AND `approved` = ? ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = ($condition["approved"] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user