public function displayList() { $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; $limit_per_page = intval($this->conf['list_limit_page']); $current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? intval($_GET['p']) : 1; $start = ($current_page - 1) * $limit_per_page; $list = PhotosCategory::getCategories(); $listCategories = array(); if (isset($list) && is_array($list) && count($list)) { /** pagination * */ // $nb_pages = ceil($nb_articles / $limit_per_page); // $next = $current_page > 1 ? true : false; //articles plus recents // $back = $current_page >= 1 && ($current_page < $nb_pages) ? true : false; //articles precedents $i = 0; foreach ($list as $cat) { $photos = Photos::getPhotosByCategory($cat['id_photo_cat']); $list_photo = array(); foreach ($photos as $key => $val) { $photo = $val; $photo['average'] = PhotosRatting::getAverage($val['id_photo']); $list_photo[] = $photo; } $cat['photos'] = $list_photo; $listCategories[] = $cat; } // echo '<pre>'; // print_r($listCategories); // echo '</pre>'; $this->context->smarty->assign(array('list_categories' => $listCategories, 'img_photo_dir' => _THEME_PHOTO_DIR_, 'customer' => $this->context->customer->id)); } $this->setTemplate('list.tpl'); }
public function renderForm() { $this->toolbar_btn['save-and-stay'] = array('href' => '#', 'desc' => $this->l('Save and stay')); $defaultLanguage = $this->default_form_language; $this->initToolbar(); $this->fields_form = array('tinymce' => true, 'legend' => array('title' => $this->l('Photo'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Title:'), 'name' => 'title', 'required' => true, 'lang' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'textarea', 'label' => $this->l('Description :'), 'name' => 'description', 'autoload_rte' => true, 'rows' => 10, 'cols' => 100, 'lang' => true, 'desc' => $this->l('Will be displayed in top of category page')), array('type' => 'file', 'label' => $this->l('Image :'), 'name' => 'image', 'required' => true, 'display_image' => true)), 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); $this->fields_form['input'][] = array('type' => 'text', 'label' => $this->l('Position :'), 'size' => 3, 'name' => 'position'); $categories = PhotosCategory::listCategories($defaultLanguage); $this->fields_form['input'][] = array('type' => 'select', 'label' => $this->l('Category'), 'desc' => $this->l('Choose a category'), 'name' => 'id_photo_cat', 'required' => true, 'options' => array('query' => $categories, 'id' => 'id_option', 'name' => 'name')); $this->fields_form['input'][] = array('type' => 'radio', 'label' => $this->l('Status :'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))); if (!($photo = $this->loadObject(true))) { return; } // $image = ImageManager::thumbnail(_PS_MYPHOTO_IMG_DIR_.'/'.$photo->id.'.jpg', $this->table.'_'.(int)$photo->id.'.'.$this->imageType, 350, $this->imageType, true); // $this->fields_value = array( // 'image' => $image ? $image : false, // 'size' => $image ? filesize(_PS_MYPHOTO_IMG_DIR_.'/'.$photo->id.'.jpg') / 1000 : false // ); return parent::renderForm(); }
public function renderForm() { $form_output = ''; $defaultLanguage = $this->default_form_language; if (!$this->loadObject(true)) { return; } $obj = $this->object; $lang_value = $this->default_form_language; $activeLanguages = Language::getLanguages(true); $form_output .= '<form class="defaultForm adminposts" id="' . $this->table . '_form" action="' . self::$currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" enctype="multipart/form-data"> ' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : ''); $form_output .= '</fieldset><div class="clear space"> </div> <fieldset> <legend><img src="../img/admin/translation.gif"> ' . $this->l('Content') . '</legend>'; if (count($activeLanguages) > 1) { $lang_options = array(); foreach ($activeLanguages as $l) { $lang_options[] = array('value' => $l['id_lang'], 'title' => $l['name']); } $lang_options[] = array('value' => 0, 'title' => $this->l('All languages')); $form_output .= HelperFieldFormNew::displaySelectField('id_lang', $lang_options, $lang_value, $this->l('Language :')); } else { $form_output .= '<input type="hidden" name="id_lang" value="0" />'; } $form_output .= HelperFieldFormNew::displayTextField('title', $this->getFieldValue($obj, 'title'), 'text', $this->l('Title :'), NULL, array('required' => true, 'class' => 'copy2friendlyBlogUrl', 'id' => 'title_' . $lang_value)); $form_output .= HelperFieldFormNew::displayTextField('description', $this->getFieldValue($obj, 'description'), 'textarea', $this->l('Description :'), NULL, array('tinymce' => true)); $form_output .= '</fieldset><div class="clear space"> </div>'; // MEDIAS $form_output .= '<fieldset> <legend><img src="../img/admin/picture.gif"> ' . $this->l('Medias') . '</legend> <label>' . $this->l('Images :') . ' </label> <div class="margin-form"> <input type="file" accept="gif|jpg|png" maxlength="' . $this->conf['nb_max_img'] . '" id="img" name="img" /> .jpg, .png, .gif </div> <div class="margin-form" id="blog-img-list"></div> <div class="margin-form">'; $relative = rtrim($this->conf['img_save_path'], '/') . "/"; $images = $this->getFieldValue($obj, 'img'); if ($images) { $form_output .= ' <img src="' . __PS_BASE_URI__ . $relative . 'thumb/' . $images . '" alt="' . $images . '" style="max-height:200px;" />'; } $form_output .= '</fieldset>'; $form_output .= '<div class="clear space"> </div>'; // CATEGORIES $form_output .= '<fieldset><legend><img src="../img/admin/tab-categories.gif"> ' . $this->l('Categories') . '</legend>'; $form_output .= '<label> </label> <div class="margin-form"> '; $post_categories = Tools::getValue('groupBox', $obj->getCategories()); $categories = PhotosCategory::listCategories(false, false); if (is_array($categories) && count($categories)) { $form_output .= '<table cellspacing="0" cellpadding="0" class="table" style="min-width:500px;"> <tr> <th style="width:40px;"><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'groupBox[]\', this.checked)" /></th> <th style="width:30px;">' . $this->l('ID') . '</th> <th>' . $this->l('Category name') . '</th> </tr>'; $irow = 0; foreach ($categories as $cat) { $form_output .= ' <tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td><input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_' . $cat['id_photo_cat'] . '" value="' . $cat['id_photo_cat'] . '" ' . (in_array($cat['id_photo_cat'], $post_categories) ? 'checked="checked" ' : '') . '/></td> <td>' . $cat['id_photo_cat'] . '</td> <td><label for="groupBox_' . $cat['id_photo_cat'] . '" class="t">' . $cat['name'] . ' ' . (count($activeLanguages) > 1 && $cat['iso_code'] != '' ? '(' . $cat['iso_code'] . ')' : '') . ' </label></td> </tr>'; } $form_output .= ' </table> <p style="padding:0px; margin:10px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of categories to which the photo is to be in') . '</p>'; } else { $form_output .= '<p>' . $this->l('No category created') . '</p>'; } $form_output .= '</div>'; $form_output .= '</fieldset><div class="clear space"> </div>'; $helper = new HelperCore(); $helper->module = new MyPhotos(); $template = $helper->createTemplate('form_photo.tpl'); $iso_code = $this->context->language->iso_code; $iso = file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso_code . '.js') ? $iso_code : 'en'; $iso_tiny_mce = file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_code . '.js') ? $iso_code : 'en'; $this->addjQueryPlugin(array('autocomplete', 'ajaxfileupload', 'date')); $this->addJS(array(_MODULE_DIR_ . $this->module->name . '/js/photo.js', _MODULE_DIR_ . $this->module->name . '/js/jquery.MultiFile.pack.js', _PS_JS_DIR_ . 'tiny_mce/tiny_mce.js', _PS_JS_DIR_ . 'tinymce.inc.js', _PS_JS_DIR_ . 'fileuploader.js')); $this->addJqueryUI(array('ui.core', 'ui.datepicker')); $this->toolbar_btn['save-and-stay'] = array('href' => '#', 'desc' => $this->l('Save and stay')); $title = array($this->l('Photo'), $obj->id ? $this->l('Edit') : $this->l('Add new')); $template->assign(array('show_toolbar' => true, 'path_css' => _THEME_CSS_DIR_, 'toolbar_btn' => $this->toolbar_btn, 'currentIndex' => self::$currentIndex, 'toolbar_scroll' => true, 'title' => $title, 'ad' => dirname($_SERVER['PHP_SELF']), 'form_content' => $form_output, 'iso_tiny_mce' => $iso_tiny_mce, 'iso' => $iso, 'tinymce' => true, 'vat_number' => file_exists(_PS_MODULE_DIR_ . 'vatnumber/ajax.php'), 'languages' => $this->_languages, 'id_lang_default' => $defaultLanguage, 'defaultFormLanguage' => $defaultLanguage, 'allowEmployeeFormLang' => $this->allow_employee_form_lang)); $form_content = $template->fetch(); return $form_content; }