original_string: protected function setBayesian(array $data)
      {
          $rating = $this->getBayesian($data);
  
          if (empty($rating['bayesian_rating'])) {
              $this->db->delete('rating', array('product_id' => $data['product_id']));
              return array();
          }
  
          $sql = 'INSERT INTO rating
                  SET rating=:rating, votes=:votes, product_id=:product_id
                  ON DUPLICATE KEY UPDATE rating=:rating, votes=:votes';
  
          $params = array(
              'product_id' => $data['product_id'],
              'votes' => $rating['this_num_votes'],
              'rating' => $rating['bayesian_rating']
          );
  
          $this->db->run($sql, $params);
          return $rating;
      }
code: protected function setBayesian(array $data)
      {
          $rating = $this->getBayesian($data);
  
          if (empty($rating['bayesian_rating'])) {
              $this->db->delete('rating', array('product_id' => $data['product_id']));
              return array();
          }
  
          $sql = 'INSERT INTO rating
                  SET rating=:rating, votes=:votes, product_id=:product_id
                  ON DUPLICATE KEY UPDATE rating=:rating, votes=:votes';
  
          $params = array(
              'product_id' => $data['product_id'],
              'votes' => $rating['this_num_votes'],
              'rating' => $rating['bayesian_rating']
          );
  
          $this->db->run($sql, $params);
          return $rating;
      }
code_tokens: protected function setBayesian ( array $ data ) { $ rating = $ this -> getBayesian ( $ data ) ; if ( empty ( $ rating [ 'bayesian_rating' ] ) ) { $ this -> db -> delete ( 'rating' , array ( 'product_id' => $ data [ 'product_id' ] ) ) ; return array ( ) ; } $ sql = 'INSERT INTO rating
                  SET rating=:rating, votes=:votes, product_id=:product_id
                  ON DUPLICATE KEY UPDATE rating=:rating, votes=:votes' ; $ params = array ( 'product_id' => $ data [ 'product_id' ] , 'votes' => $ rating [ 'this_num_votes' ] , 'rating' => $ rating [ 'bayesian_rating' ] ) ; $ this -> db -> run ( $ sql , $ params ) ; return $ rating ; }
docstring: Sets bayesian rating and votes for the given product
  @param array $data
  @return array
docstring_tokens: Sets bayesian rating and votes for the given product