/** * Get distincted values of a field in the table * * @param string $field Field's name * @param object $criteria {@link CriteriaElement} conditions to be met * @param string $format Format in wich we want the datas * @return array containing the distinct values */ function getDistincts($field, $criteria = null, $format = 's') { require_once 'lite.php'; $limit = $start = 0; $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' ' . $criteria->renderWhere(); $limit = $criteria->getLimit(); $start = $criteria->getStart(); } $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; $Cache_Lite = new oledrion_Cache_Lite($this->cacheOptions); $id = $this->_getIdForCache($sql, $start, $limit); $cacheData = $Cache_Lite->get($id); if ($cacheData === false) { $result = $this->db->query($sql, $limit, $start); $ret = array(); $obj = new $this->className(); while ($myrow = $this->db->fetchArray($result)) { $obj->setVar($field, $myrow[$field]); $ret[$myrow[$this->keyName]] = $obj->getVar($field, $format); } $Cache_Lite->save($ret); return $ret; } else { return $cacheData; } }
/** * Retourne la liste des ID de produits vendus récemment * * @param integer $start * @param integer $limit * @return array * @since 2.3.2009.04.08 */ function getRecentlySoldProducts($start = 0, $limit = 0) { require_once 'lite.php'; $ret = array(); $sql = 'SELECT c.caddy_product_id FROM ' . $this->table . ' c, ' . $this->db->prefix('oledrion_commands') . ' o WHERE (c.caddy_cmd_id = o.cmd_id) AND (o.cmd_state = ' . OLEDRION_STATE_VALIDATED . ') ORDER BY cmd_date DESC'; $Cache_Lite = new oledrion_Cache_Lite($this->cacheOptions); $id = $this->_getIdForCache($sql, $start, $limit); $cacheData = $Cache_Lite->get($id); if ($cacheData === false) { $result = $this->db->query($sql, $limit, $start); if ($result) { while ($row = $this->db->fetchArray($result)) { $ret[$row['caddy_product_id']] = $row['caddy_product_id']; } } $Cache_Lite->save($ret); return $ret; } else { return $cacheData; } }
/** * Retourne les x dernières listes qui contiennent des produits dans une certaine catégorie * * @param integer $cateGoryId L'identifiant de la catégorie * @param integer $list_type Le type de liste * @param integer $limit Le nombre maximum de listes à retourner * @return array Objets de type oledrion_lists, [clé] = id liste */ function listsFromCurrentCategory($categoryId, $list_type, $limit) { require_once 'lite.php'; $ret = array(); $start = 0; $categoryId = intval($categoryId); $list_type = intval($list_type); $limit = intval($limit); $sql = 'SELECT distinct(z.productlist_list_id) FROM ' . $this->db->prefix('oledrion_products_list') . ' z, ' . $this->db->prefix('oledrion_products') . ' p, ' . $this->db->prefix('oledrion_lists') . ' l WHERE (l.list_type = ' . $list_type . ') AND (p.product_cid = ' . $categoryId . ') AND (l.list_id = z.productlist_list_id) AND (z.productlist_product_id = p.product_id) AND (p.product_online = 1) ORDER BY l.list_date DESC'; $Cache_Lite = new oledrion_Cache_Lite($this->cacheOptions); $id = $this->_getIdForCache($sql, $start, $limit); $cacheData = $Cache_Lite->get($id); if ($cacheData === false) { $result = $this->db->query($sql, $limit, $start); if ($result) { while ($row = $this->db->fetchArray($result)) { $ret[] = $row['productlist_list_id']; } $ret = $this->getItemsFromIds($ret); } $Cache_Lite->save($ret); return $ret; } else { return $cacheData; } }