public function __construct($custom_block_id)
 {
     parent::__construct($custom_block_id);
     if (!IS_ADMIN) {
         // forbid for non admin calls
         throw new AException(AC_ERR_LOAD, 'Error: permission denied to access class AListingManager');
     }
 }
Esempio n. 2
0
 public function getListing()
 {
     if (!$this->data['custom_block_id'] || !$this->data['descriptions']) {
         return false;
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $listing = new AListing($this->data['custom_block_id']);
     $content = unserialize($this->data['descriptions'][$this->config->get('storefront_language_id')]['content']);
     if (!$content && $this->data['descriptions']) {
         $content = current($this->data['descriptions']);
         $content = unserialize($content['content']);
     }
     $this->data['controller'] = $content['block_appearance'];
     $this->data['listing_datasource'] = $content['listing_datasource'];
     $data_sources = $listing->getListingDataSources();
     $data_source = $data_sources[$content['listing_datasource']];
     if (strpos($content['listing_datasource'], 'custom_') === FALSE) {
         // for auto listings
         $route = $content['listing_datasource'];
         $limit = $content['limit'];
         // for resource library
         if ($route == 'media') {
             $rl = new AResource($content['resource_type']);
             if (isset($this->request->get['product_id'])) {
                 $object_name = 'products';
                 $object_id = $this->request->get['product_id'];
             } elseif (isset($this->request->get['category_id']) || isset($this->request->get['path'])) {
                 $object_name = 'categories';
                 if (isset($this->request->get['category_id'])) {
                     $object_id = $this->request->get['product_id'];
                 } else {
                     $temp = explode("_", $this->request->get['path']);
                     end($temp);
                     $object_id = current($temp);
                 }
             } elseif (isset($this->request->get['manufacturer_id'])) {
                 $object_name = 'manufacturers';
                 $object_id = $this->request->get['manufacturer_id'];
             }
             $resources = $rl->getResourceAllObjects($object_name, $object_id, array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_product_width'), 'height' => $this->config->get('config_image_product_height'))), $limit, false);
             if (!$resources) {
                 return null;
             }
             if ($limit == 1) {
                 $resources = array($resources);
             }
             foreach ($resources as $k => $resource) {
                 if ($resource['origin'] == 'external') {
                     $result[$k]['resource_code'] = $resource['thumb_html'];
                 } else {
                     if ($content['resource_type'] != 'image') {
                         $title = $resource['title'] ? $resource['title'] : 'dowload';
                     } else {
                         $title = $resource['title'];
                     }
                     $result[$k]['image'] = array('main_url' => $resource['main_url'], 'main_html' => $resource['main_html'], 'thumb_url' => $resource['thumb_url'], 'thumb_html' => $resource['thumb_html'], 'title' => $title, 'resource_type' => $content['resource_type']);
                 }
             }
         } else {
             // otherwise -  select list from method
             if ($route) {
                 $this->loadModel($data_source['storefront_model']);
                 $result = call_user_func_array(array($this->{'model_' . str_replace('/', '_', $data_source['storefront_model'])}, $data_source['storefront_method']), $listing->getlistingArguments($data_source['storefront_model'], $data_source['storefront_method'], array('limit' => $limit)));
                 if ($result) {
                     $desc = $listing->getListingDataSources();
                     foreach ($desc as $d) {
                         if ($d['storefront_method'] == $data_source['storefront_method']) {
                             $data_source = $d;
                             break;
                         }
                     }
                     //add thumbnails to custom list of items. 1 thumbnail per item
                     $result = $this->_prepareCustomItems($data_source, $result);
                 }
             }
         }
     } else {
         // for custom listings
         $list = $listing->getCustomList();
         if (!$list) {
             return null;
         }
         $this->load->model($data_source['storefront_model']);
         foreach ($list as $item) {
             $result[] = call_user_func_array(array($this->{'model_' . str_replace('/', '_', $data_source['storefront_model'])}, $data_source['storefront_method']), array($item['id']));
         }
     }
     /*if($data_source['rl_object_name'] ){
     			$resource = new AResource('image');
     		}*/
     if ($result) {
         //add thumbnails to custom list of items. 1 thumbnail per item
         $result = $this->_prepareCustomItems($data_source, $result);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     return $result;
 }