public function __construct() { parent::__construct(); $this->context = Context::getContext(); $aResponse['error'] = false; $aResponse['message'] = ''; if (isset($_POST['action'])) { $id_photo = $_POST['idBox']; $ratting = $_POST['rate']; if (PhotosRatting::checkRatting($id_photo)) { $photosRatting = new PhotosRatting(); $photosRatting->add(array('id_photo' => $id_photo, 'ratting' => $ratting)); $aResponse['error'] = FALSE; $aResponse['message'] = 'Your rate has been successfuly recorded. Thanks for your rate'; } else { $aResponse['error'] = true; $aResponse['message'] = 'Your have rated for images'; } } else { $aResponse['error'] = true; $aResponse['message'] = 'An error occured during the request. Please retry'; } echo json_encode($aResponse); die; }
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'); }