/**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Handle drawing list of manufacturers tag
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ManufacturerList($tag_params, $children)
 {
     $manager = ShopManufacturerManager::getInstance();
     $conditions = array();
     $selected = -1;
     if (class_exists('gallery')) {
         $use_images = true;
         $gallery = gallery::getInstance();
         $gallery_manager = GalleryManager::getInstance();
     } else {
         $use_images = false;
     }
     if (isset($tag_params['selected'])) {
         $selected = fix_id($tag_params['selected']);
     }
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     $template = $this->_parent->loadTemplate($tag_params, 'manufacturer_list_item.xml');
     if (count($items) > 0) {
         foreach ($items as $item) {
             // get image
             $image = '';
             if ($use_images && !empty($item->logo)) {
                 $image_item = $gallery_manager->getSingleItem($gallery_manager->getFieldNames(), array('id' => $item->logo));
                 if (is_object($image_item)) {
                     $image = $gallery->getImageURL($image_item);
                 }
             }
             // prepare parameters
             $params = array('id' => $item->id, 'name' => $item->name, 'web_site' => $item->web_site, 'logo' => $image, 'selected' => $selected == $item->id ? 1 : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_manufacturer_change', 360, $this->_parent->getLanguageConstant('title_manufacturer_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_manufacturer_delete', 400, $this->_parent->getLanguageConstant('title_manufacturer_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'delete'), array('id', $item->id)))));
             // parse template
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
Beispiel #3
0
 /**
  * Handle drawing item list
  *
  * @param array $tag_params
  * @param array $chilren
  */
 public function tag_ItemList($tag_params, $children)
 {
     global $language;
     $manager = ShopItemManager::getInstance();
     $conditions = array();
     $page_switch = null;
     $order_by = array('id');
     $order_asc = true;
     $limit = null;
     // create conditions
     if (isset($tag_params['category'])) {
         if (is_numeric($tag_params['category'])) {
             $category_id = fix_id($tag_params['category']);
         } else {
             // specified id is actually text_id, get real one
             $category_manager = ShopCategoryManager::getInstance();
             $category = $category_manager->getSingleItem(array('id'), array('text_id' => fix_chars($tag_params['category'])));
             if (!is_object($category)) {
                 return;
             }
             $category_id = $category->id;
         }
         $membership_manager = ShopItemMembershipManager::getInstance();
         $membership_items = $membership_manager->getItems(array('item'), array('category' => $category_id));
         $item_ids = array();
         if (count($membership_items) > 0) {
             foreach ($membership_items as $membership) {
                 $item_ids[] = $membership->item;
             }
         }
         if (count($item_ids) > 0) {
             $conditions['id'] = $item_ids;
         } else {
             $conditions['id'] = -1;
         }
         // make sure nothing is returned if category is empty
     }
     if (isset($tag_params['related'])) {
         $relation_manager = ShopRelatedItemsManager::getInstance();
         $item_id = fix_id($tag_params['related']);
         $related_items = $relation_manager->getItems(array('related'), array('item' => $item_id));
         $related_item_ids = array();
         if (count($related_items) > 0) {
             foreach ($related_items as $relationship) {
                 $related_item_ids[] = $relationship->related;
             }
         }
         if (count($related_item_ids) > 0) {
             $conditions['id'] = $related_item_ids;
         } else {
             $conditions['id'] = -1;
         }
     }
     if (!(isset($tag_params['show_deleted']) && $tag_params['show_deleted'] == 1)) {
         // force hiding deleted items
         $conditions['deleted'] = 0;
     }
     if (isset($tag_params['filter']) && !empty($tag_params['filter'])) {
         // filter items with name matching
         $conditions['name_' . $language] = array('operator' => 'LIKE', 'value' => '%' . fix_chars($tag_params['filter']) . '%');
     }
     if (isset($tag_params['paginate'])) {
         $per_page = is_numeric($tag_params['paginate']) ? $tag_params['paginate'] : 10;
         $param = isset($tag_params['page_param']) ? fix_chars($tag_params['page_param']) : null;
         $item_count = $manager->getItemValue('COUNT(id)', $conditions);
         $page_switch = new PageSwitch($param);
         $page_switch->setCurrentAsBaseURL();
         $page_switch->setItemsPerPage($per_page);
         $page_switch->setTotalItems($item_count);
         // get filter params
         $limit = $page_switch->getFilterParams();
     }
     if (isset($tag_params['order_by'])) {
         $order_by = array(fix_chars($tag_params['order_by']));
     }
     // get items
     $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit);
     // create template
     $template = $this->_parent->loadTemplate($tag_params, 'item_list_item.xml');
     $template->registerTagHandler('_color_list', $this, 'tag_ColorList');
     if (count($items) > 0) {
         $gallery = null;
         if (class_exists('gallery')) {
             $gallery = gallery::getInstance();
         }
         $manufacturer_manager = ShopManufacturerManager::getInstance();
         foreach ($items as $item) {
             if (!is_null($gallery)) {
                 // get manufacturer logo
                 $manufacturer_logo_url = '';
                 if ($item->manufacturer != 0) {
                     $manufacturer = $manufacturer_manager->getSingleItem($manufacturer_manager->getFieldNames(), array('id' => $item->manufacturer));
                     if (is_object($manufacturer)) {
                         $manufacturer_logo_url = $gallery->getImageURL($manufacturer->logo);
                     }
                 }
                 // get urls for image and thumbnail
                 $image_url = $gallery->getGroupThumbnailURL($item->gallery, true);
                 $thumbnail_url = $gallery->getGroupThumbnailURL($item->gallery);
             } else {
                 // default values if gallery is not enabled
                 $image_url = '';
                 $thumbnail_url = '';
                 $manufacturer_logo_url = '';
             }
             $rating = 0;
             $params = array('id' => $item->id, 'uid' => $item->uid, 'name' => $item->name, 'description' => $item->description, 'gallery' => $item->gallery, 'size_definition' => $item->size_definition, 'colors' => $item->colors, 'image' => $image_url, 'thumbnail' => $thumbnail_url, 'manufacturer_logo_url' => $manufacturer_logo_url, 'author' => $item->author, 'views' => $item->views, 'price' => $item->price, 'tax' => $item->tax, 'currency' => $this->_parent->settings['default_currency'], 'weight' => $item->weight, 'votes_up' => $item->votes_up, 'votes_down' => $item->votes_down, 'rating' => $rating, 'priority' => $item->priority, 'timestamp' => $item->timestamp, 'visible' => $item->visible, 'deleted' => $item->deleted, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_item_change', 505, $this->_parent->getLanguageConstant('title_item_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'items'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_item_delete', 400, $this->_parent->getLanguageConstant('title_item_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'items'), array('sub_action', 'delete'), array('id', $item->id)))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
     // draw page switch if needed
     if (!is_null($page_switch)) {
         $params = array();
         $children = array();
         // pick up parameters from original array
         foreach ($tag_params as $key => $value) {
             if (substr($key, 0, 12) == 'page_switch_') {
                 $params[substr($key, 12)] = $value;
             }
         }
         $page_switch->tag_PageSwitch($params, $children);
     }
 }