Quick Search:

View

Revision:

Diff

Diff from 1674 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/recently_visited.php

Annotated File View

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