public function doRating($pid)
 {
     $qForm = new erpPROQueryFormater();
     // Make sure relData is populated, this can happen when do rating
     // is called outside of $this->getRelated
     if ($this->relData == null) {
         $this->relData = new erpPRORelData($pid, erpPRODefaults::$criticalOpts);
     }
     $ratingSystem = erpPRORatingSystem::get_instance($this->relData);
     // Check if a query limit is set.
     $qLimit = isset($queryLimit) && is_numeric($queryLimit) ? $queryLimit : $this->queryLimit;
     $qForm->setMainArgs($pid);
     $postCats = get_the_category($pid);
     $postTags = get_the_tags($pid);
     $relTable = array();
     if (!empty($postCats)) {
         $qForm->clearTags()->clearPostInParam()->clearPostTypes()->setCategories($postCats);
         $qForm->exPostTypes($this->options->getValue('postTypes'))->exCategories($this->options->getValue('categories'))->exTags($this->options->getValue('tags'));
         $wpq = $this->relData->setQueryLimit($qLimit, 0)->setWP_Query($qForm->getArgsArray(), $qLimit, 0)->getResult();
         $postsArray = $wpq->posts;
         if (!empty($postsArray)) {
             foreach ($postsArray as $key => $value) {
                 $relTable[$value->ID]['score2_cats'] = $ratingSystem->rateBasedOnCats($pid, $value->ID);
                 $relTable[$value->ID]['score1_cats'] = $ratingSystem->rateBasedOnCats($value->ID, $pid);
                 $relTable[$value->ID]['score2_tags'] = $ratingSystem->rateBasedOnTags($pid, $value->ID);
                 $relTable[$value->ID]['score1_tags'] = $ratingSystem->rateBasedOnTags($value->ID, $pid);
                 $relTable[$value->ID]['post_date1'] = get_the_time('Y-m-d', $pid);
                 $relTable[$value->ID]['post_date2'] = get_the_time('Y-m-d', $value->ID);
                 $this->dbActions->insertRecToRel($pid, $value->ID, $relTable[$value->ID]);
                 $relTable[$value->ID]['pid1'] = $pid;
                 $relTable[$value->ID]['pid2'] = $value->ID;
             }
         }
     }
     if (!empty($postTags)) {
         $qForm->clearCategories()->clearPostInParam()->clearPostTypes()->setTags($postTags);
         $qForm->exPostTypes($this->options->getValue('postTypes'))->exCategories($this->options->getValue('categories'))->exTags($this->options->getValue('tags'));
         $wpq = $this->relData->setQueryLimit($qLimit, 0)->setWP_Query($qForm->getArgsArray(), $qLimit, 0)->getResult();
         $postsArray = $wpq->posts;
         if (!empty($postsArray)) {
             $inserted = array_keys($relTable);
             foreach ($postsArray as $key => $value) {
                 if (!in_array($value->ID, $inserted)) {
                     $relTable[$value->ID]['score2_cats'] = $ratingSystem->rateBasedOnCats($pid, $value->ID);
                     $relTable[$value->ID]['score1_cats'] = $ratingSystem->rateBasedOnCats($value->ID, $pid);
                     $relTable[$value->ID]['score2_tags'] = $ratingSystem->rateBasedOnTags($pid, $value->ID);
                     $relTable[$value->ID]['score1_tags'] = $ratingSystem->rateBasedOnTags($value->ID, $pid);
                     $relTable[$value->ID]['post_date1'] = get_the_time('Y-m-d H:i:s', $pid);
                     $relTable[$value->ID]['post_date2'] = get_the_time('Y-m-d H:i:s', $value->ID);
                     $this->dbActions->insertRecToRel($pid, $value->ID, $relTable[$value->ID]);
                     $relTable[$value->ID]['pid1'] = $pid;
                     $relTable[$value->ID]['pid2'] = $value->ID;
                 }
             }
         }
     }
     /**
      * As things are right now in 90% of cases this
      * returns all posts, so no actual interest in using
      * this. Just leaving it here for future reference
      */
     //        $best = $this->chooseTheBest($pid, $relTable);
     //
     //        foreach ($relTable as $key => $value) {
     //            if (in_array($value['pid2'], $best)) {
     //                $this->dbActions->insertRecToRel($pid, $value['pid2'], $relTable[$value['pid2']]);
     //            } else {
     //                unset($relTable[$value['pid2']]);
     //            }
     //        }
     wp_reset_postdata();
     return $relTable;
 }
 public function formPostData(WP_Query $wpq, erpPROOptions $optionsObj, $ratings = array())
 {
     erpPROPaths::requireOnce(erpPROPaths::$erpPROPostData);
     $from = get_the_ID();
     $data = array('title' => $optionsObj->getValue('title'), 'options' => $this->options, 'uniqueID' => $this->uniqueID, 'optionsObj' => $optionsObj, 'posts' => array());
     while ($wpq->have_posts()) {
         $wpq->the_post();
         $rating = isset($ratings[get_the_ID()]) ? $ratings[get_the_ID()] : null;
         $postData = new erpPROPostData($wpq->post, $optionsObj, $rating, $from);
         if ($optionsObj->haveToShowExcerpt()) {
             $postData->setExcerpt($optionsObj->getValue('excLength'), $optionsObj->getValue('moreTxt'));
         }
         if ($optionsObj->haveToShowThumbnail()) {
             $postData->setThumbnail($optionsObj->getDefaultThumbnail());
         }
         array_push($data['posts'], $postData);
     }
     wp_reset_postdata();
     $this->setAdditionalViewData(array_merge($data, $this->options));
     return $this;
 }