Esempio n. 1
0
 /**
  * Calculate the market value
  *
  * @param   integer  $id    Question ID
  * @param   string   $type  Transaction type
  * @return  mixed
  */
 public function calculate_marketvalue($id, $type = 'regular')
 {
     if ($id === NULL) {
         $id = $this->qid;
     }
     if ($id === NULL) {
         return false;
     }
     require_once dirname(__DIR__) . DS . 'models' . DS . 'question.php';
     // Get point values for actions
     $BC = new Config($this->_db);
     $p_Q = $BC->get('ask');
     $p_A = $BC->get('answer');
     $p_R = $BC->get('answervote');
     $p_RQ = $BC->get('questionvote');
     $p_A_accepted = $BC->get('accepted');
     $calc = 0;
     // Get actons and sum up
     $results = Response::all()->whereEquals('question_id', $id)->where('state', '!=', 2)->rows();
     if ($type != 'royalty') {
         $calc += $p_Q;
         // ! this is different from version before code migration !
         $calc += $results->count() * $p_A;
     }
     // Calculate as if there is at leat one answer
     if ($type == 'maxaward' && $results->count() == 0) {
         $calc += $p_A;
     }
     foreach ($results as $result) {
         $calc += $result->get('helpful') * $p_R;
         $calc += $result->get('nothelpful') * $p_R;
         if ($result->get('state') == 1 && $type != 'royalty') {
             $accepted = 1;
         }
     }
     if (isset($accepted) or $type == 'maxaward') {
         $calc += $p_A_accepted;
     }
     // Add question votes
     $aq = Question::oneOrNew($id);
     if ($aq->get('state') != 2) {
         $calc += $aq->get('helpful') * $p_RQ;
     }
     $calc = $calc ? $calc : '0';
     return $calc;
 }
Esempio n. 2
0
 /**
  * Calculate the market value for a review
  *
  * @param   object  $review  ResourcesReview
  * @param   string  $type    Point calculation type
  * @return  mixed   False if errors, integer on success
  */
 public function calculate_marketvalue($review, $type = 'royalty')
 {
     if (!is_object($review)) {
         return false;
     }
     // Get point values for actions
     $BC = new Config($this->_db);
     $p_R = $BC->get('reviewvote') ? $BC->get('reviewvote') : 2;
     $calc = 0;
     if (isset($review->helpful) && isset($review->nothelpful)) {
         $calc += $review->helpful * $p_R;
     }
     $calc = $calc ? $calc : 0;
     return $calc;
 }
Esempio n. 3
0
 /**
  * Calculate the market value
  *
  * @param   integer  $id    Question ID
  * @param   string   $type  Transaction type
  * @return  mixed
  */
 public function calculate_marketvalue($id, $type = 'regular')
 {
     if ($id === NULL) {
         $id = $this->qid;
     }
     if ($id === NULL) {
         return false;
     }
     require_once dirname(__DIR__) . DS . 'models' . DS . 'question.php';
     // Get point values for actions
     $BC = new Config($this->_db);
     $p_Q = $BC->get('ask');
     $p_A = $BC->get('answer');
     $p_R = $BC->get('answervote');
     $p_RQ = $BC->get('questionvote');
     $p_A_accepted = $BC->get('accepted');
     $calc = 0;
     // Get actons and sum up
     $ar = new Tables\Response($this->_db);
     $result = $ar->getActions($id);
     if ($type != 'royalty') {
         $calc += $p_Q;
         // ! this is different from version before code migration !
         $calc += count($result) * $p_A;
     }
     // Calculate as if there is at leat one answer
     if ($type == 'maxaward' && count($result) == 0) {
         $calc += $p_A;
     }
     for ($i = 0, $n = count($result); $i < $n; $i++) {
         $calc += $result[$i]->helpful * $p_R;
         $calc += $result[$i]->nothelpful * $p_R;
         if ($result[$i]->state == 1 && $type != 'royalty') {
             $accepted = 1;
         }
     }
     if (isset($accepted) or $type == 'maxaward') {
         $calc += $p_A_accepted;
     }
     // Add question votes
     $aq = new Tables\Question($this->_db);
     $aq->load($id);
     if ($aq->state != 2) {
         $calc += $aq->helpful * $p_RQ;
     }
     $calc = $calc ? $calc : '0';
     return $calc;
 }