  |
11 | 11 | | */ |
| |
12 | 12 | | |
| |
13 | 13 | | class osC_Image { |
  |
14 | | - | var $_data; |
| |
| 14 | + | var $_groups; |
|
15 | 15 | | |
| |
16 | 16 | | function osC_Image() { |
  |
17 | | - | global $osC_Database; |
| |
| 17 | + | global $osC_Database, $osC_Language; |
|
18 | 18 | | |
  |
19 | | - | $Qgroups = $osC_Database->query('select distinct id, code, size_height as height, size_width as width from :table_products_images_groups'); |
| |
| 19 | + | $this->_groups = array(); |
| |
| 20 | + | |
| |
| 21 | + | $Qgroups = $osC_Database->query('select * from :table_products_images_groups where language_id = :language_id'); |
|
20 | 22 | | $Qgroups->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS); |
  |
21 | | - | $Qgroups->setCache('images_groups'); |
| |
| 23 | + | $Qgroups->bindInt(':language_id', $osC_Language->getID()); |
| |
| 24 | + | $Qgroups->setCache('images_groups-' . $osC_Language->getID()); |
|
22 | 25 | | $Qgroups->execute(); |
| |
23 | 26 | | |
| |
24 | 27 | | while ($Qgroups->next()) { |
  |
25 | | - | $this->_data[$Qgroups->value('code')] = $Qgroups->toArray(); |
| |
| 28 | + | $this->_groups[$Qgroups->valueInt('id')] = $Qgroups->toArray(); |
|
26 | 29 | | } |
| |
27 | 30 | | |
| |
28 | 31 | | $Qgroups->freeResult(); |
| |
29 | 32 | | } |
| |
30 | 33 | | |
| |
31 | 34 | | function getID($code) { |
  |
32 | | - | return $this->_data[$code]['id']; |
| |
| 35 | + | foreach ($this->_groups as $group) { |
| |
| 36 | + | if ($group['code'] == $code) { |
| |
| 37 | + | return $group['id']; |
| |
| 38 | + | } |
| |
| 39 | + | } |
| |
| 40 | + | |
| |
| 41 | + | return 0; |
|
33 | 42 | | } |
| |
34 | 43 | | |
  |
| 44 | + | function getCode($id) { |
| |
| 45 | + | return $this->_groups[$id]['code']; |
| |
| 46 | + | } |
| |
| 47 | + | |
|
35 | 48 | | function getWidth($code) { |
  |
36 | | - | return $this->_data[$code]['width']; |
| |
| 49 | + | return $this->_groups[$this->getID($code)]['size_width']; |
|
37 | 50 | | } |
| |
38 | 51 | | |
| |
39 | 52 | | function getHeight($code) { |
  |
40 | | - | return $this->_data[$code]['height']; |
| |
| 53 | + | return $this->_groups[$this->getID($code)]['size_height']; |
|
41 | 54 | | } |
| |
42 | 55 | | |
  |
43 | | - | function show(&$image, &$title = '', $parameters = '', $group = 'default') { |
| |
44 | | - | if (isset($this->_data[$group]) === false) { |
| |
45 | | - | $group = 'default'; |
| |
| 56 | + | function exists($code) { |
| |
| 57 | + | return isset($this->_groups[$this->getID($code)]); |
| |
| 58 | + | } |
| |
| 59 | + | |
| |
| 60 | + | function show(&$image, &$title, $parameters = '', $group = '') { |
| |
| 61 | + | if (empty($group) || !$this->exists($group)) { |
| |
| 62 | + | $group = $this->getCode(DEFAULT_IMAGE_GROUP_ID); |
|
46 | 63 | | } |
| |
47 | 64 | | |
  |
48 | | - | return tep_image(DIR_WS_IMAGES . $image, $title, $this->_data[$group]['width'], $this->_data[$group]['height'], $parameters); |
| |
| 65 | + | $group_id = $this->getID($group); |
| |
| 66 | + | |
| |
| 67 | + | $width = $height = ''; |
| |
| 68 | + | |
| |
| 69 | + | if ( ($this->_groups[$group_id]['force_size'] == '1') || empty($image) ) { |
| |
| 70 | + | $width = $this->_groups[$group_id]['size_width']; |
| |
| 71 | + | $height = $this->_groups[$group_id]['size_height']; |
| |
| 72 | + | } |
| |
| 73 | + | |
| |
| 74 | + | if (empty($image)) { |
| |
| 75 | + | $image = 'pixel_trans.gif'; |
| |
| 76 | + | } else { |
| |
| 77 | + | $image = 'products/' . $this->_groups[$group_id]['code'] . '/' . $image; |
| |
| 78 | + | } |
| |
| 79 | + | |
| |
| 80 | + | return tep_image(DIR_WS_HTTP_CATALOG . DIR_WS_IMAGES . $image, $title, $width, $height, $parameters); |
|
49 | 81 | | } |
  |
| 82 | + | |
| |
| 83 | + | function getAddress(&$image, $group = 'default') { |
| |
| 84 | + | $group_id = $this->getID($group); |
| |
| 85 | + | |
| |
| 86 | + | return DIR_WS_IMAGES . 'products/' . $this->_groups[$group_id]['code'] . '/' . $image; |
| |
| 87 | + | } |
  |
50 | 88 | | } |
| |
51 | 89 | | ?> |