예제 #1
0
 public function doRating($pid, $best = false)
 {
     $taxoOperator = $best ? 'and' : 'in';
     $qForm = new erpQueryFormater();
     // Make sure relData is populated, this can happen when do rating
     // is called outside of $this->getRelated
     if ($this->relData == null) {
         $this->relData = new erpRelData($pid, erpDefaults::$criticalOpts);
     }
     $ratingSystem = erpRatingSystem::get_instance($this->relData);
     $qForm->setMainArgs($pid);
     $postCats = get_the_category($pid);
     $postTags = get_the_tags($pid);
     $relTable = array();
     if (!empty($postCats)) {
         $qForm->clearTags()->clearPostInParam()->clearPostTypes()->setCategories($postCats, $taxoOperator);
         $qForm->exPostTypes($this->options->getValue('postTypes'))->exCategories($this->options->getValue('categories'))->exTags($this->options->getValue('tags'));
         $wpq = $this->relData->setQueryLimit($this->queryLimit, 0)->setWP_Query($qForm->getArgsArray(), $this->queryLimit, 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);
                 $relTable[$value->ID]['pid1'] = $pid;
                 $relTable[$value->ID]['pid2'] = $value->ID;
             }
         }
     }
     if (!empty($postTags)) {
         $qForm->clearCategories()->clearPostInParam()->clearPostTypes()->setTags($postTags, $taxoOperator);
         $qForm->exPostTypes($this->options->getValue('postTypes'))->exCategories($this->options->getValue('categories'))->exTags($this->options->getValue('tags'));
         $wpq = $this->relData->setQueryLimit($this->queryLimit, 0)->setWP_Query($qForm->getArgsArray(), $this->queryLimit, 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);
                     $relTable[$value->ID]['pid1'] = $pid;
                     $relTable[$value->ID]['pid2'] = $value->ID;
                 }
             }
         }
     }
     wp_reset_postdata();
     return $relTable;
 }
예제 #2
0
 public function formPostData(WP_Query $wpq, erpOptions $optionsObj, $ratings = array())
 {
     erpPaths::requireOnce(erpPaths::$erpPostData);
     $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 erpPostData($wpq->post, $optionsObj, $rating);
         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;
 }