/** * TODO * Returns the best rated posts for all options defined * in erpPRODefaults::$fetchByOptionsWeights, * erpPRODefaults::$sortRelatedByOption * * @param int $pid * @param int $relTable * @return array Array with post ids of the best * @author Panagiotis Vagenas <*****@*****.**> * @since 1.0.0 */ private function chooseTheBest($pid, $relTable) { /** * CHECK How we should set the best count? * Maybe search for the biggest value in all * options... */ $bestCount = 15; $relData = new erpPRORelData($pid, erpPRODefaults::$criticalOpts, $relTable); $ratingSystem = erpPRORatingSystem::get_instance($relData); $ratingsFlatenedPool = array(); /** * Get the best for all sorting options */ foreach (erpPRODefaults::$fetchByOptionsWeights as $option => $weights) { $ratingSystem->setWeights($weights); $ratingSystem->formRatingsArrays(); foreach (erpPRODefaults::$sortRelatedByOption as $key => $value) { $ratingSystem->sortRatingsArrays($value); foreach (array_keys($ratingSystem->getSlicedRatingsArrayFlatLoose($bestCount)) as $k => $v) { if (!in_array($v, $ratingsFlatenedPool)) { array_push($ratingsFlatenedPool, $v); } } } } /** * return the result */ return $ratingsFlatenedPool; }
/** * Return an instance of this class. * * @since 1.0.0 * @return erpPRORatingSystem */ public static function get_instance(erpPRORelData $relData) { // If the single instance hasn't been set, set it now. if (null == self::$instance) { self::$instance = new self($relData); } if (!(isset(self::$instance->relData->relTable) && isset($relData->relTable) && self::$instance->relData->relTable == $relData->relTable)) { self::$instance->relData = $relData; } return self::$instance; }