public function getRelated($pid) { $relTable = null; /** * Check if we have a reldata obj with same query and if yes return it */ foreach ($this->relDataPool as $key => $value) { $missMatch = $value->criticalOptionsMismatch($this->options->getOptions()); if (empty($missMatch)) { $this->relData = $value; return $this->relData->getResult(); } } // Check if we have relTable in pool foreach ($this->relDataPool as $key => $value) { if ($value->pid == $pid) { $relTable = $value->relTable; break; } } $criticalOptions = array_intersect_key($this->options->getOptions(), array_flip(erpDefaults::$criticalOpts)); $this->relData = new erpRelData($pid, $criticalOptions, $relTable); /** * If no cached ratings or not the required number of posts */ if (empty($relTable) || count($relTable) < $this->options->getNumberOfPostsToDiplay()) { $relTable = $this->doRating($pid, true); if (count($relTable) - $this->options->getOffset() < $this->options->getNumberOfPostsToDiplay()) { $relTable = $this->doRating($pid, false); } } /** * If reltable is still empty or not enough posts in it * return an empty wp_query obj */ if (empty($relTable) || count($relTable) - $this->options->getOffset() < 1) { // Normally this should return an empty wp_query return $this->relData->getResult(); } $this->relData->setRelTable($relTable); $ratingSystem = erpRatingSystem::get_instance($this->relData); $weights = $this->calcWeights(); $ratingSystem->setWeights($weights); $ratingSystem->formRatingsArrays(); $ratingSystem->sortRatingsArrays($this->options->getSortRelatedBy(true)); $slicedArray = $ratingSystem->getSlicedRatingsArrayFlat($this->options->getOffset(), $this->options->getNumberOfPostsToDiplay()); $qForm = new erpQueryFormater(); $qForm->setMainArgs($pid); $qForm->exPostTypes($this->options->getValue('postTypes')); $qForm->exCategories($this->options->getValue('categories')); $qForm->exTags($this->options->getValue('tags')); $qForm->setPostInArg(array_keys($slicedArray)); $this->relData->setWP_Query($qForm->getArgsArray(), $this->options->getNumberOfPostsToDiplay(), $this->options->getOffset()); $this->relData->getResult(); $this->relData->setRatings($slicedArray); $this->relData->sortWPQuery(array_keys($slicedArray)); array_push($this->relDataPool, $this->relData); return $this->relData->getResult(); }