Quick Search:

View

Revision:

Diff

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