/** * Returns the cached keys and values associated to the given tags if available. * * @inheritDoc * * @param string[] $tags List of tag strings associated to the requested cache entries * @return array Associative list of key/value pairs for the requested cache * entries. If a tag isn't associated to any cache entry, nothing is returned * for that tag * @throws MW_Cache_Exception If the cache server doesn't respond */ public function getListByTags(array $tags) { $list = array(); $conn = $this->_dbm->acquire($this->_dbname); try { $search = new MW_Common_Criteria_SQL($conn); $expires = array($search->compare('>', 'cache.expire', date('Y-m-d H:i:00')), $search->compare('==', 'cache.expire', null)); $expr = array($search->compare('==', 'cache.tag.name', $tags), $search->combine('||', $expires)); $search->setConditions($search->combine('&&', $expr)); $types = $this->_getSearchTypes($this->_searchConfig); $translations = $this->_getSearchTranslations($this->_searchConfig); $conditions = $search->getConditionString($types, $translations); $stmt = $conn->create(str_replace(':cond', $conditions, $this->_sql['getbytag'])); $stmt->bind(1, $this->_siteid, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(2, $this->_siteid, MW_DB_Statement_Abstract::PARAM_INT); $result = $stmt->execute(); while (($row = $result->fetch()) !== false) { $list[$row['id']] = $row['value']; } $this->_dbm->release($conn, $this->_dbname); } catch (Exception $e) { $this->_dbm->release($conn, $this->_dbname); throw $e; } return $list; }
/** * creates a search object and sets base criteria * * @param boolean $default * @return MW_Common_Criteria_Interface */ public function createSearch($default = false) { $dbm = $this->_getContext()->getDatabaseManager(); $dbname = $this->_getResourceName(); $conn = $dbm->acquire($dbname); $object = new MW_Common_Criteria_SQL($conn); $dbm->release($conn, $dbname); if ($default === true) { $curDate = date('Y-m-d H:i:00', time()); $expr = array(); $temp = array(); $temp[] = $object->compare('==', 'coupon.code.datestart', null); $temp[] = $object->compare('<=', 'coupon.code.datestart', $curDate); $expr[] = $object->combine('||', $temp); $temp = array(); $temp[] = $object->compare('==', 'coupon.code.dateend', null); $temp[] = $object->compare('>=', 'coupon.code.dateend', $curDate); $expr[] = $object->combine('||', $temp); $object->setConditions($object->combine('&&', $expr)); } return $object; }