Quick Search:

View

Revision:

Diff

Diff from 896 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/frank/Alpha4_TinyMCE/includes/classes/recently_visited.php

Annotated File View

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