Php PrestaShop:如何删除';新';我的backoffice控制器中的按钮
我想从prestashop中的bo列表视图工具栏中删除添加按钮(仅针对我作为单独模块创建的页面) 或者,至少当我单击“添加”按钮时,它不能执行任何操作。Php PrestaShop:如何删除';新';我的backoffice控制器中的按钮,php,overriding,prestashop,prestashop-1.6,Php,Overriding,Prestashop,Prestashop 1.6,我想从prestashop中的bo列表视图工具栏中删除添加按钮(仅针对我作为单独模块创建的页面) 或者,至少当我单击“添加”按钮时,它不能执行任何操作。 require_once(_PS_MODULE_DIR_.'addsocialmedia/addsocialmedia.php'); 需要一次(_PS_MODULE_DIR_'addsocialmedia/classes/SocialMedia.php'); 类AdminAddSocialMediaController扩展ModuleAdmi
require_once(_PS_MODULE_DIR_.'addsocialmedia/addsocialmedia.php');
需要一次(_PS_MODULE_DIR_'addsocialmedia/classes/SocialMedia.php');
类AdminAddSocialMediaController扩展ModuleAdminController
{
公费模块;
公众$html;
public$tabName='renderForm';
公共函数构造()
{
$this->tab='socialmedia';
$this->module=newaddsocialmedia();
$this->addRowAction('edit');
$this->explicitSelect=false;
$this->context=context::getContext();
$this->id\u lang=$this->context->language->id;
$this->lang=false;
$this->ajax=1;
$this->path=_MODULE_DIR_'addsocialmedia';
$this->default\u form\u language=$this->context->language->id;
$this->table=\u DB\u KITS\u PREFIX\u“社交媒体”;
$this->className='SocialMedia';
$this->identifier='id\u social\u media';
$this->allow_export=true;
$this->\u选择
社交媒体,
姓名(社交)(媒体),,
社交媒体网址,
地位
';
$this->name='SocialMedia';
$this->bootstrap=true;
$this->initList();
父项::_构造();
}
私有函数initList()
{
$this->fields\u list=
排列(
“id\u社交媒体”=>数组(
'title'=>this->l('socialmedia ID'),
“宽度”=>25,
'类型'=>'文本',
),
'name\u social\u media'=>数组(
'title'=>this->l('社交媒体名称'),
“宽度”=>140,
'类型'=>'文本',
),
“社交媒体url”=>数组(
'title'=>this->l('社交媒体Url'),
“宽度”=>140,
'类型'=>'文本',
),
“状态”=>数组(
'title'=>$this->l('Enabled'),
“对齐”=>“文本中心”,
“状态”=>“状态”,
'type'=>'bool',
'orderby'=>false,
“回调”=>“更改状态”,
),
);
$helper=newhelperlist();
$helper->shopLinkType='';
$helper->simple_header=true;
//要在“操作”列中显示的操作
$helper->actions=array('edit');
$helper->identifier='code';
$helper->show_toolbar=true;
$helper->title='HelperList';
$helper->table=$this->name.'check';
$helper->token=Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex=AdminController::$currentIndex.&configure=。$this->name;
返回$helper;
}
公共函数initPageHeaderToolbar()
{
$this->page\u header\u toolbar\u title=$this->l('Edit Social Media Image and url/link');
父级::initPageHeaderToolbar();
}
公共函数initToolbar()
{
父::initToolbar();
$this->context->smarty->assign('toolbar_scroll',1);
$this->context->smarty->assign('show_toolbar',1);
$this->context->smarty->assign('toolbar\u btn',$this->toolbar\u btn);
}
公共函数后处理()
{
父::后处理();
$id=(int)Tools::getValue('id_社交媒体');
$file=Tools::fileAttachment('social_media_image_name');
如果(!empty($file['name'])&&$id>0)
{
if(ImageManager::validateUpload($file,Tools::convertBytes(ini\u get('upload\u max\u filesize')))
die('图像大小超出Bigticket后台设置的限制');
如果(!is_dir('../modules/addsocialmedia/social_media_img'))
@mkdir('../modules/addsocialmedia/social_media_img',0777,真);
如果(!is_dir('../modules/addsocialmedia/social_media\u img/'.$id))
@mkdir(“../modules/addsocialmedia/social_media_img/”.$id,0777,true);
$path='../modules/addsocialmedia/social_media_img/'。$id./';
$absolute_path=$path.$file['name'];
移动上传的文件($file['tmp\u name',$absolute\u path);
$imgPath='social_media_img/'.$id./'.$file['name'];
//如果需要,以DB为单位保存
Db::getInstance()->execute('UPDATE`.'U Db\'U PREFIX'.'.'U Db\'U KITS\'U PREFIX'.'social\'U media`
设置“社交媒体图像名称”`=“.pSQL($imgPath)。”
其中`id\u社交媒体`='(int)$id);
}
if(工具::isSubmit('changeStatusVal')&&$this->id\u对象){
如果($this->tabAccess['edit']='1'){
$this->action='change_status_val';
d(“chnage”);
}否则{
$this->errors[]=Tools::displayError('您没有更改此项的权限');
}
}
}
//回拨更改状态
公共功能更改状态($value,$socialMedia)
require_once(_PS_MODULE_DIR_.'addsocialmedia/addsocialmedia.php');
require_once(_PS_MODULE_DIR_.'addsocialmedia/classes/SocialMedia.php');
class AdminAddSocialMediaController extends ModuleAdminController
{
public $module;
public $html;
public $tabName = 'renderForm';
public function __construct()
{
$this->tab = 'socialmedia';
$this->module = new addsocialmedia();
$this->addRowAction('edit');
$this->explicitSelect = false;
$this->context = Context::getContext();
$this->id_lang = $this->context->language->id;
$this->lang = false;
$this->ajax = 1;
$this->path = _MODULE_DIR_.'addsocialmedia';
$this->default_form_language = $this->context->language->id;
$this->table = _DB_KITS_PREFIX_.'social_media';
$this->className = 'SocialMedia';
$this->identifier = 'id_social_media';
$this->allow_export = true;
$this->_select = '
id_social_media,
name_social_media,
social_media_url,
status
';
$this->name = 'SocialMedia';
$this->bootstrap = true;
$this->initList();
parent::__construct();
}
private function initList()
{
$this->fields_list =
array(
'id_social_media' => array(
'title' => $this->l('Social Media ID'),
'width' => 25,
'type' => 'text',
),
'name_social_media' => array(
'title' => $this->l('Social Media Name'),
'width' => 140,
'type' => 'text',
),
'social_media_url' => array(
'title' => $this->l('Social Media Url'),
'width' => 140,
'type' => 'text',
),
'status' => array(
'title' => $this->l('Enabled'),
'align' => 'text-center',
'status' => 'status',
'type' => 'bool',
'orderby' => false,
'callback' => 'changeStatus',
),
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
// Actions to be displayed in the "Actions" column
$helper->actions = array('edit');
$helper->identifier = 'code';
$helper->show_toolbar = true;
$helper->title = 'HelperList';
$helper->table = $this->name.'check';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
return $helper;
}
public function initPageHeaderToolbar()
{
$this->page_header_toolbar_title = $this->l('Edit Social Media Image and url/link');
parent::initPageHeaderToolbar();
}
public function initToolbar()
{
parent::initToolbar();
$this->context->smarty->assign('toolbar_scroll', 1);
$this->context->smarty->assign('show_toolbar', 1);
$this->context->smarty->assign('toolbar_btn', $this->toolbar_btn);
}
public function postProcess()
{
parent::postProcess();
$id = (int)Tools::getValue('id_social_media');
$file = Tools::fileAttachment('social_media_image_name');
if (!empty($file['name']) && $id > 0)
{
if (ImageManager::validateUpload($file, Tools::convertBytes(ini_get('upload_max_filesize'))))
die('Image size exceeds limit in your Bigticket Back Office settings');
if (!is_dir('../modules/addsocialmedia/social_media_img'))
@mkdir('../modules/addsocialmedia/social_media_img', 0777, true);
if (!is_dir('../modules/addsocialmedia/social_media_img/'.$id))
@mkdir('../modules/addsocialmedia/social_media_img/'.$id, 0777, true);
$path = '../modules/addsocialmedia/social_media_img/'.$id.'/';
$absolute_path = $path.$file['name'];
move_uploaded_file($file['tmp_name'], $absolute_path);
$imgPath = 'social_media_img/'.$id.'/'.$file['name'];
//Save in DB if needed
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.''._DB_KITS_PREFIX_.'social_media`
SET `social_media_image_name` = "'.pSQL($imgPath).'"
WHERE `id_social_media` = '.(int)$id);
}
if (Tools::isSubmit('changeStatusVal') && $this->id_object) {
if ($this->tabAccess['edit'] === '1') {
$this->action = 'change_status_val';
d("chnage");
} else {
$this->errors[] = Tools::displayError('You do not have permission to change this.');
}
}
}
//Call back for change status
public function changeStatus($value, $socialMedia)
{
return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminAddSocialMedia&id_social_media='
.(int)$socialMedia['id_social_media'].'&changeStatusVal&token='.Tools::getAdminTokenLite('AdminAddSocialMedia')).'">
'.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>').
'</a>';
}
/**
* Toggle the Social media to Enabled or Disabled flag- Here the update action occurs
*/
public function processChangeStatusVal()
{
d("hii");
$socialMedia = new SocialMedia($this->id_object);
if (!Validate::isLoadedObject($socialMedia)) {
$this->errors[] = Tools::displayError('An error occurred while updating the Status .');
}
d("going to change");
$socialMedia->status = $socialMedia->status ? 0 : 1;
if (!$socialMedia->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating Social Media Status .');
}
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
}
//When a winner is deleted , delete the image
public function processDelete()
{
$ob=parent::processDelete();
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
if ($ob->deleted==1){
$id = (int)Tools::getValue('id_social_media');
$unlink_path = '../modules/addsocialmedia/social_media_img/'.$id.'/';
unlink($unlink_path); // this must delete the img folder from the winners module dir
//log the delete
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
}
}
//If the user updates the image delete the old image from server
public function processUpdate(){
//d("updating..");
$id = (int)Tools::getValue('id_social_media');
$file = Tools::fileAttachment('social_media_image_name');
if (!empty($file['name']) && $id > 0)
{
$get_previous_image_sql = 'SELECT social_media_image_name FROM `'._DB_PREFIX_._DB_KITS_PREFIX_.'social_media`
where id_social_media='.$id.'';
$get_previous_image_path = Db::getInstance()->getValue($get_previous_image_sql) ;
//d($get_previous_image_path);
$unlink_path = '../modules/addsocialmedia/'.$get_previous_image_path.'';
unlink($unlink_path); // this must delete the img folder from the winners module dir
//log the delete when deleting
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE while updating new image', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
}
}
// This form is populated when add or edit is clicked
public function renderForm()
{
$firstArray =
array(array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name_social_media',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Social Media URL'),
'name' => 'social_media_url',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'file',
'label' => $this->l('Social Media Image'),
'name' => 'social_media_image_name',
'display_image' => true,
'required' => false,
'desc' => $this->l('Add .JPG or .PNG File Format.Prefered Width:381 pixels and Height 285 pixels.Prefered File size -50KB .'),
'hint' => array(
$this->l('Add .JPG or .PNG File Format.Prefered Width:381 pixels and Height 285 pixels.Prefered File size -50KB .')
)
),
array(
'type' => 'switch',
'label' => $this->l('Enable Or Disable this Social Media'),
'name' => 'status',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'status_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'status_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'hint' => $this->l('Enable or disable this Social Media From front END.')
),
);
if (Tools::getIsset('addkits_social_media') ){
$secondArray = array(
array(
'type' => 'hidden',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'values'=>date("Y-m-d H:i:s"),
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'hidden',
'label' => $this->l('Winner Image Name'),
'name' => 'social_media_image_name',
'col' => '4',
'values'=>"default_value"
)
);
$mainArray = array_merge($firstArray,$secondArray);
}
if (Tools::getIsset('updatekits_social_media') ){
$thirdArray = array(
array(
'type' => 'hidden',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'values'=>date("Y-m-d H:i:s"),
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'hidden',
'label' => $this->l('Winner Image Name'),
'name' => 'social_media_image_name',
'col' => '4',
'values'=>"default_value"
));
$mainArray = array_merge($firstArray,$thirdArray);
}
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Configure your Social Media Image and URL'),
'icon' => 'icon-user'
),
'input' => $mainArray
);
//Assign value to hidden
$this->fields_value['date_add'] = $date = date("Y-m-d H:i:s");
$this->fields_value['social_media_image_name'] ="default_image.jpg";
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$date = date("Y-m-d H:i:s");
$this->addJqueryUI('ui.datepicker');
return parent::renderForm();
}
public function initToolbar() {
parent::initToolbar();
unset( $this->toolbar_btn['new'] );
}