public function loadOnSectionID($section_id, $type) { $select = new Select(); $select->from(self::$table, "*")->where("`type` = " . self::$db->getSQ(), array($type))->where("`latest` = " . self::$db->getSQ(), array(1))->rand(); $data_1 = self::$db->select($select); $select = new Select(); $select->from(self::$table, "*")->where("`type` = " . self::$db->getSQ(), array($type)); if ($section_id) { $select->whereFIS("section_ids", $section_id); } $select->rand(); $data_2 = self::$db->select($select); $data = array_merge($data_1, $data_2); if (count($data) == 0) { $select = new Select(); $select->from(self::$table, "*")->where("`type` = " . self::$db->getSQ(), array($type))->rand(); $data = self::$db->select($select); } $data = ObjectDB::buildMultiple(__CLASS__, $data); uasort($data, array(__CLASS__, "compare")); $first = array_shift($data); $this->load($first->id); }