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 = Config::values();
     $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
 /**
  * Delete a record
  *
  * @param   boolean  $isSpam
  * @return  void
  */
 public function removeTask($isSpam = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getInt('id', 0);
     $parentid = Request::getInt('parentid', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     $email = 1;
     // Turn off/on
     $gratitude = 1;
     // Turn off/on
     $message = '';
     // Load the report
     $report = new ReportAbuse($this->database);
     $report->load($id);
     $report->reviewed = Date::toSql();
     $report->reviewed_by = User::get('id');
     $report->note = Request::getVar('note', '');
     // Get the reported item
     $results = Event::trigger('support.getReportedItem', array($report->referenceid, $report->category, $parentid));
     // Check the results returned for a reported item
     $reported = null;
     if ($results) {
         foreach ($results as $result) {
             if ($result) {
                 $reported = $result[0];
             }
         }
     }
     // Remove the reported item and any other related processes that need be performed
     $results = Event::trigger('support.deleteReportedItem', array($report->referenceid, $parentid, $report->category, $message));
     if ($results) {
         foreach ($results as $result) {
             if ($result) {
                 $message .= $result;
             }
         }
     }
     if ($isSpam) {
         $results = Event::trigger('antispam.onAntispamTrain', array($reported->text, $isSpam));
     }
     // Mark abuse report as deleted
     $report->state = 2;
     if (!$report->store()) {
         throw new Exception($report->getError(), 500);
     }
     // Notify item owner
     if ($email) {
         $user = User::getInstance($reported->author);
         // Email "from" info
         $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
         // Email subject
         $subject = Lang::txt('COM_SUPPORT_REPORT_ABUSE_EMAIL_SUBJECT', Config::get('sitename'));
         // Plain text
         $eview = new View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'abuse_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->reported = $reported;
         $eview->report = $report;
         $eview->author = $user;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         // HTML
         $eview->setLayout('abuse_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         // Build message
         $message = new Message();
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_removal');
         $message->addPart($plain, 'text/plain');
         $message->addPart($html, 'text/html');
         // Send the email
         if (Utilities::checkValidEmail($user->get('email'))) {
             $message->send();
         }
     }
     // Check the HUB configuration to see if banking is turned on
     $upconfig = Component::params('com_members');
     $banking = $upconfig->get('bankAccounts');
     // Give some points to whoever reported abuse
     if ($banking && $gratitude) {
         $BC = \Hubzero\Bank\Config::values();
         $ar = $BC->get('abusereport');
         // How many points?
         if ($ar) {
             $ruser = User::getInstance($report->created_by);
             if (is_object($ruser) && $ruser->get('id')) {
                 $BTL = new \Hubzero\Bank\Teller($ruser->get('id'));
                 $BTL->deposit($ar, Lang::txt('COM_SUPPORT_ACKNOWLEDGMENT_FOR_VALID_REPORT'), 'abusereport', $id);
             }
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_REPORT_ITEM_TAKEN_DOWN'));
 }
Esempio n. 4
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;
 }