Location: PHPKode > projects > Hotseat Corner > lib/HSUtils/UIDCachingProxy.class.php
<?php
/*
    This file is part of Hotseat Corner.

    Hotseat Corner is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Hotseat Corner is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Hotseat Corner.  If not, see <http://www.gnu.org/licenses/>.
*/
	class HSUtils_UIDCachingProxy {
		private static $uid_types = array('EO_Story','EO_Object');
		
		public static function loadByUIDs ($uids, $dbr_assoc = false)
		{
			if ($dbr_assoc === true) {
				foreach ($uids as $r) {
					$raw_uids[] = $r['targetuid'];
				}
			}
			else {
				$raw_uids = $uids;
			}
			$lost_uids = $raw_uids;
			$found_set = array();
			foreach (self::$uid_types as $uid_type) {
				if (COUNT($lost_uids) == 0) {
					break;
				}
				eval('$set = '.$uid_type.'::loadByUIDs($raw_uids);');
				foreach ($set as $s) {
					$pos = array_search($s->uid, $lost_uids, true);
					unset($lost_uids[$pos]);
					$found_set[$s->uid] = $s;
				}
			}
			ksort($found_set);
			$found_set = array_values($found_set);
			return $found_set;
		}
		
		public static function loadByUID ($uid) 
		{
			return self::loadByUIDs(array($uid));
		}
		
		
		public static function search ($paramString = null, $stackname, $limit = 10) 
		{
			if (trim($paramString) == null) {
				return array();
			}
			$tmpParamString = htmlspecialchars($paramString);
			$tmpParamString = preg_replace("(\s+)", " ", $tmpParamString);
			$params = explode(" ", $tmpParamString);
			foreach ($params as $key=>$param) {
				$params[$key] = mysql_escape_string($param);
			}
			$params = array_unique($params);
			$paramsql = "'".implode("','", $params)."'";
			$offset = EOUtils_Stack::get($stackname);
			$dbq = "SELECT SQL_CALC_FOUND_ROWS ts.uid, SUM(ts.freq) as freq 
				FROM tokenons ts, tokens t 
				WHERE t.token IN ($paramsql) 
				AND t.id = ts.tokenid 
				GROUP BY ts.uid 
				ORDER BY freq DESC LIMIT $offset, $limit";
			$dbr = EOUtils_DBFactory::get()->prepare($dbq)->execute()->fetchAllAssoc();
			list($total) = EOUtils_DBFactory::get()->prepare("SELECT FOUND_ROWS()")->execute()->fetchRow();
			if ($total > 0) {
				foreach ($dbr as $r) {
					$uids[] = $r['uid'];
				}
				$stack = EOUtils_Stack::fresh();
				$stack->stack = EOUtils_UIDCachingProxy::loadByUIDs($uids, false);
				$stack->offset = $offset;
				$stack->total = $total;
				$stack->limit = $limit;
				$stack->name = $stackname;
				return $stack;
			}
			else {
				return array();
			}
		}
		
		public static function index ($subject) {
			$tmp = $subject->getIndexString();
			$uid = $subject->uid();
			// loop decode
			// tokenise
			// calculate
			// insert
		}
	}
?>
Return current item: Hotseat Corner