* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminStEasyVideoListController extends ModuleAdminController
{
protected $spacer_size = '5';
protected $contr = '';
public function __construct()
{
$this->bootstrap = true;
$this->table = 'st_easy_video';
$this->className = 'StEasyVideoClass';
$this->lang = false;
$this->addRowAction('edit');
$this->addRowAction('delete');
if (Shop::isFeatureActive()) {
Shop::addTableAssociation($this->table, array('type' => 'shop'));
}
parent::__construct();
$this->bulk_actions = array(
'delete' => array(
'text' => $this->trans('Delete selected', array(), 'Modules.StEasyVideo.Admin'),
'icon' => 'icon-trash',
'confirm' => $this->trans('Delete selected items?', array(), 'Modules.StEasyVideo.Admin'),
)
);
if (!file_exists(_PS_IMG_DIR_.'/steasyvideo')) {
@mkdir(_PS_IMG_DIR_.'/steasyvideo', 0775, true)
|| @chmod(_PS_IMG_DIR_.'/steasyvideo', 0775);
}
$this->fieldImageSettings = [
'name' => 'thumbnail',
'dir' => 'steasyvideo',
];
$this->fields_list = array(
'id_st_easy_video' => array(
'title' => $this->trans('ID', array(), 'Modules.StEasyVideo.Admin'),
'class' => 'fixed-width-xs'
),
'url' => array(
'title' => $this->l('Url'),
'type' => 'text',
'search' => false,
'orderby' => false,
'class' => 'fixed-width-xl',
),
'name' => array(
'title' => $this->l('Name'),
'width' => 140,
'type' => 'text',
'search' => false,
'orderby' => false,
),
'id_product' => array(
'title' => $this->l('Add to'),
'width' => 140,
'type' => 'text',
'callback' => 'displayAddTo',
'search' => false,
'orderby' => false,
'class' => 'fixed-width-xl',
),
'id_category' => array(
'title' => $this->l('Language'),
'width' => 140,
'type' => 'text',
'callback' => 'displayYuyan',
'search' => false,
'orderby' => false,
'class' => 'fixed-width-xs',
),
'autoplay' => array(
'title' => $this->trans('Autoplay', array(), 'Modules.StEasyVideo.Admin'),
'type' => 'text',
'callback' => 'displayState',
'orderby' => false,
'class' => 'fixed-width-md',
),
'muted' => array(
'title' => $this->trans('Muted', array(), 'Modules.StEasyVideo.Admin'),
'type' => 'text',
'callback' => 'displayState',
'orderby' => false,
'class' => 'fixed-width-md',
),
'loop' => array(
'title' => $this->trans('Loop', array(), 'Modules.StEasyVideo.Admin'),
'type' => 'text',
'callback' => 'displayState',
'orderby' => false,
'class' => 'fixed-width-md',
),
'active' => array(
'title' => $this->trans('Status', array(), 'Modules.StEasyVideo.Admin'),
'active' => 'status',
'type' => 'bool',
'orderby' => false,
'class' => 'fixed-width-md',
),
);
$this->_where = $this->addWhere();
$this->_orderBy = 'id_st_easy_video';
$this->_orderWay = 'DESC';
if (Tools::isSubmit('ajax_product_list')) {
$this->getAjaxProductsList();
}
Media::addJsDefL('stsb_comfirmation_msg', $this->trans('Are you sure?', array(), 'Modules.StEasyVideo.Admin'));
}
public function postProcess()
{
if (Tools::getValue('deletethumbnail')) {
if (file_exists(_PS_IMG_DIR_.'/steasyvideo/'.(int)Tools::getValue('id_st_easy_video').'.jpg')
&& !unlink(_PS_IMG_DIR_.'/steasyvideo/'.(int)Tools::getValue('id_st_easy_video').'.jpg')) {
$this->context->controller->errors[] = $this->trans('Error while delete', array(), 'Admin.Notifications.Error');
}
Tools::redirectAdmin(self::$currentIndex.'&conf=7&' . $this->identifier . '='.(int)Tools::getValue('id_st_easy_video').'&update' . $this->table . '&token=' . $this->token);
}
return parent::postProcess();
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addJqueryPlugin(array('autocomplete'));
$this->addJs(_MODULE_DIR_.$this->module->name.'/views/js/admin.js?108');
}
public function displayState($value, $tr)
{
$arr = array(
'0' => $this->l('No'),
'1' => $this->l('Yes'),
'2' => $this->l('Default'),
);
return array_key_exists($value, $arr) ? $arr[$value] : '';
}
public function displayYuyan($value, $tr)
{
$res = '';
$yuyuan = StEasyVideoYuyanClass::getByVideo($tr['id_st_easy_video']);
if ($yuyuan && is_array($yuyuan)) {
$all_languages = Language::getLanguages(false);
foreach ($yuyuan as $y) {
foreach ($all_languages as $language) {
if ($y['id_lang'] == $language['id_lang']) {
$res .= $language['name'];
break;
}
}
}
} else {
$res = $this->l('All');
}
return $res;
}
public function displayAddTo($value, $tr)
{
$name = '';
if ($tr['id_category'] > 0) {
$category = new Category($tr['id_category'], Context::getContext()->language->id);
if (Validate::isLoadedObject($category)) {
$name .= $category->name;
}
} elseif ($tr['id_product'] != '') {
$products = Db::getInstance()->executeS('SELECT id_product,name from `'._DB_PREFIX_.'product_lang` WHERE id_product IN ('.trim($tr['id_product'], ',').') AND id_lang='.Context::getContext()->language->id.' AND id_shop='.Context::getContext()->shop->id);
if ($products && is_array($products)) {
foreach ($products as $key => $val) {
if ($key == 0) {
$name .= ''.$val['name'];
} else {
$name .= '
'.$val['name'];
}
}
}
} elseif ($tr['id_manufacturer'] > 0) {
$manufacturer = new Manufacturer($tr['id_manufacturer'], Context::getContext()->language->id);
if (Validate::isLoadedObject($manufacturer)) {
$name .= $manufacturer->name;
}
}
return $name;
}
public function renderForm()
{
if (!($obj = $this->loadObject(true))) {
return;
}
$image = _PS_IMG_DIR_ . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg';
$image_size = false;
$image_tag = '';
if (file_exists($image)) {
$image_size = filesize($image) / 1000;
$image_url = _PS_IMG_ . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg';
$image_tag = '';
}
Media::addJsDef(array(
'_currentIndex' => $this->context->link->getAdminLink('AdminModules'),
'_token' => Tools::getAdminTokenLite('AdminModules')
));
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Add a video'),
'icon' => 'icon-tags',
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Video url:'),
'name' => 'url',
'default_value' => '',
'class' => 'fixed-width-xxl',
'required' => true,
'desc' => array(
$this->l('Url of a .mp4 file or a youtube url or a vimeo url.'),
$this->l('You can upload mp4 files to your site via FTP, another way is using the text editor at the bottom of this page to upload videos to your site to get urls.'),
'