Quick Search:

View

Revision:

Diff

Diff from 301 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/modules/content/recently_visited.php

Annotated File View

hpdl
228
1 <?php
2 /*
3
4   osCommerce, Open Source E-Commerce Solutions
5   http://www.oscommerce.com
6
hpdl
296
7   Copyright (c) 2005 osCommerce
hpdl
228
8
9   Released under the GNU General Public License
10 */
11
hpdl
297
12   class osC_RecentlyVisited {
hpdl
228
13
hpdl
290
14     var $visits = array();
hpdl
228
15
16 /* Class constructor */
17
hpdl
297
18     function osC_RecentlyVisited() {
hpdl
296
19       if (isset($_SESSION['osC_RecentlyVisited_data']) === false) {
20         $_SESSION['osC_RecentlyVisited_data'] = array();
21       }
22
23       $this->visits =& $_SESSION['osC_RecentlyVisited_data'];
hpdl
290
24     }
hpdl
228
25
hpdl
290
26     function contentModuleInitialize() {
hpdl
298
27       global $osC_Product, $osC_Category, $osC_Search;
hpdl
228
28
hpdl
301
29       if (SERVICE_RECENTLY_VISITED_SHOW_PRODUCTS == 'True') {
30         if (isset($osC_Product) && is_a($osC_Product, 'osC_Product')) {
31           $this->setProduct($osC_Product->getID());
32         }
hpdl
290
33       }
hpdl
297
34
35       if (SERVICE_RECENTLY_VISITED_SHOW_CATEGORIES == 'True') {
hpdl
298
36         if (isset($osC_Category) && is_a($osC_Category, 'osC_Category')) {
37           $this->setCategory($osC_Category->getID());
38         }
hpdl
297
39       }
40
41       if (SERVICE_RECENTLY_VISITED_SHOW_SEARCHES == 'True') {
hpdl
298
42         if (isset($osC_Search) && is_a($osC_Search, 'osC_Search')) {
43           if ($osC_Search->hasKeywords()) {
44             $this->setSearchQuery($osC_Search->getKeywords());
45           }
46         }
hpdl
297
47       }
hpdl
290
48     }
49
50     function getContentModule() {
51       return 'recently_visited.php';
52     }
53
hpdl
298
54     function setProduct($id) {
55       if (isset($this->visits['products'])) {
56         foreach ($this->visits['products'] as $key => $value) {
57           if ($value['id'] == $id) {
58             unset($this->visits['products'][$key]);
59             break;
60           }
61         }
62
hpdl
301
63         if (sizeof($this->visits['products']) > (SERVICE_RECENTLY_VISITED_MAX_PRODUCTS * 2)) {
hpdl
298
64           array_pop($this->visits['products']);
65         }
66       } else {
67         $this->visits['products'] = array();
hpdl
228
68       }
69
hpdl
298
70       array_unshift($this->visits['products'], array('id' => $id));
71     }
hpdl
228
72
hpdl
298
73     function setCategory($id) {
74       if (isset($this->visits['categories'])) {
75         foreach ($this->visits['categories'] as $key => $value) {
76           if ($value['id'] == $id) {
77             unset($this->visits['categories'][$key]);
78             break;
79           }
80         }
hpdl
228
81
hpdl
301
82         if (sizeof($this->visits['categories']) > (SERVICE_RECENTLY_VISITED_MAX_CATEGORIES * 2)) {
hpdl
298
83           array_pop($this->visits['categories']);
84         }
85       } else {
86         $this->visits['categories'] = array();
87       }
hpdl
228
88
hpdl
298
89       array_unshift($this->visits['categories'], array('id' => $id));
90     }
hpdl
228
91
hpdl
298
92     function setSearchQuery($keywords) {
93       global $osC_Search;
hpdl
228
94
hpdl
298
95       if (isset($this->visits['searches'])) {
96         foreach ($this->visits['searches'] as $key => $value) {
97           if ($value['keywords'] == $keywords) {
98             unset($this->visits['searches'][$key]);
99             break;
100           }
101         }
hpdl
228
102
hpdl
301
103         if (sizeof($this->visits['searches']) > (SERVICE_RECENTLY_VISITED_MAX_SEARCHES * 2)) {
hpdl
298
104           array_pop($this->visits['searches']);
105         }
106       } else {
107         $this->visits['searches'] = array();
108       }
hpdl
228
109
hpdl
298
110       array_unshift($this->visits['searches'], array('keywords' => $keywords,
111                                                      'results' => $osC_Search->getNumberOfResults()
112                                                     ));
hpdl
228
113     }
114
hpdl
298
115     function hasHistory() {
116       if ($this->hasProducts() || $this->hasCategories() || $this->hasSearches()) {
117         return true;
118       }
hpdl
228
119
hpdl
298
120       return false;
121     }
hpdl
228
122
hpdl
298
123     function hasProducts() {
124       if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
125         return true;
hpdl
228
126       }
127
hpdl
298
128       return false;
hpdl
228
129     }
130
hpdl
298
131     function getProducts() {
132       $history = array();
hpdl
297
133
hpdl
298
134       if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) {
135         $counter = 0;
hpdl
297
136
hpdl
298
137         foreach ($this->visits['products'] as $k => $v) {
138           $counter++;
hpdl
297
139
hpdl
300
140           $osC_Product = new osC_Product($v['id']);
141           $osC_Category = new osC_Category($osC_Product->getCategoryID());
hpdl
297
142
hpdl
300
143           $history[] = array('name' => $osC_Product->getTitle(),
144                              'id' => $osC_Product->getID(),
145                              'keyword' => $osC_Product->getKeyword(),
hpdl
301
146                              'price' => (SERVICE_RECENTLY_VISITED_SHOW_PRODUCT_PRICES == 'True') ? $osC_Product->getPriceFormated(true) : '',
hpdl
300
147                              'image' => $osC_Product->getImage(),
148                              'category_name' =>  $osC_Category->getTitle(),
149                              'category_path' => $osC_Category->getPath()
hpdl
297
150                             );
151
hpdl
301
152           if ($counter == SERVICE_RECENTLY_VISITED_MAX_PRODUCTS) {
hpdl
298
153             break;
154           }
155         }
156       }
hpdl
297
157
hpdl
298
158       return $history;
159     }
hpdl
297
160
hpdl
298
161     function hasCategories() {
162       if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
163         return true;
164       }
hpdl
297
165
hpdl
298
166       return false;
167     }
hpdl
297
168
hpdl
298
169     function getCategories() {
170       $history = array();
hpdl
297
171
hpdl
298
172       if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) {
173         $counter = 0;
hpdl
297
174
hpdl
298
175         foreach ($this->visits['categories'] as $k => $v) {
176           $counter++;
hpdl
297
177
hpdl
299
178           $osC_Category = new osC_Category($v['id']);
hpdl
297
179
hpdl
299
180           if ($osC_Category->hasParent()) {
181             $osC_CategoryParent = new osC_Category($osC_Category->getParent());
hpdl
298
182           }
hpdl
297
183
hpdl
300
184           $history[]  = array('id' => $osC_Category->getID(),
185                               'name' => $osC_Category->getTitle(),
186                               'path' => $osC_Category->getPath(),
187                               'image' => $osC_Category->getImage(),
188                               'parent_name' => ($osC_Category->hasParent()) ? $osC_CategoryParent->getTitle() : '',
189                               'parent_id' => ($osC_Category->hasParent()) ? $osC_CategoryParent->getID() : ''
hpdl
298
190                              );
hpdl
297
191
hpdl
301
192           if ($counter == SERVICE_RECENTLY_VISITED_MAX_CATEGORIES) {
hpdl
298
193             break;
194           }
195         }
196       }
hpdl
297
197
hpdl
298
198       return $history;
199     }
hpdl
297
200
hpdl
298
201     function hasSearches() {
202       if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
203         return true;
204       }
hpdl
297
205
hpdl
298
206       return false;
207     }
hpdl
297
208
hpdl
298
209     function getSearches() {
210       $history = array();
hpdl
297
211
hpdl
298
212       if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) {
213         $counter = 0;
214
215         foreach ($this->visits['searches'] as $k => $v) {
216           $counter++;
217
218           $history[]  = array('keywords' => $this->visits['searches'][$k]['keywords'],
219                               'results' => $this->visits['searches'][$k]['results']
220                              );
221
hpdl
301
222           if ($counter == SERVICE_RECENTLY_VISITED_MAX_SEARCHES) {
hpdl
298
223             break;
224           }
225         }
226       }
227
228       return $history;
229     }
230   }
hpdl
297
231 ?>