コード例 #1
0
ファイル: points.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Calculate royalties
  *
  * @return     void
  */
 public function royaltyTask()
 {
     $auto = Request::getInt('auto', 0);
     $action = 'royalty';
     if (!$auto) {
         $who = User::get('id');
     } else {
         $who = 0;
     }
     // What month/year is it now?
     $curmonth = Date::of('now')->format("F");
     $curyear = Date::of('now')->format("Y-m");
     $ref = strtotime($curyear);
     $this->_message = 'Royalties on Answers for ' . $curyear . ' were distributed successfully.';
     $rmsg = 'Royalties on Reviews for ' . $curyear . ' were distributed successfully.';
     $resmsg = 'Royalties on Resources for ' . $curyear . ' were distributed successfully.';
     // Make sure we distribute royalties only once/ month
     $MH = new MarketHistory($this->database);
     $royaltyAnswers = $MH->getRecord('', $action, 'answers', $curyear, $this->_message);
     $royaltyReviews = $MH->getRecord('', $action, 'reviews', $curyear, $rmsg);
     $royaltyResources = $MH->getRecord('', $action, 'resources', $curyear, $resmsg);
     // Include economy classes
     if (is_file(PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php')) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php';
     }
     if (is_file(PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php')) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php';
     }
     $AE = new \Components\Answers\Helpers\Economy($this->database);
     $accumulated = 0;
     // Get Royalties on Answers
     if (!$royaltyAnswers) {
         $rows = $AE->getQuestions();
         if ($rows) {
             foreach ($rows as $r) {
                 $AE->distribute_points($r->id, $r->q_owner, $r->a_owner, $action);
                 $accumulated = $accumulated + $AE->calculate_marketvalue($r->id, $action);
             }
             // make a record of royalty payment
             if (intval($accumulated) > 0) {
                 $MH = new MarketHistory($this->database);
                 $data['itemid'] = $ref;
                 $data['date'] = Date::toSql();
                 $data['market_value'] = $accumulated;
                 $data['category'] = 'answers';
                 $data['action'] = $action;
                 $data['log'] = $this->_message;
                 if (!$MH->bind($data)) {
                     $err = $MH->getError();
                 }
                 if (!$MH->store()) {
                     $err = $MH->getError();
                 }
             }
         } else {
             $this->_message = 'There were no questions eligible for royalty payment. ';
         }
     } else {
         $this->_message = 'Royalties on Answers for ' . $curyear . ' were previously distributed. ';
     }
     // Get Royalties on Resource Reviews
     if (!$royaltyReviews) {
         // get eligible
         $RE = new \Components\Resources\Helpers\Economy\Reviews($this->database);
         $reviews = $RE->getReviews();
         // do we have ratings on reviews enabled?
         $plparam = Plugin::params('resources', 'reviews');
         $voting = $plparam->get('voting');
         $accumulated = 0;
         if ($reviews && $voting) {
             foreach ($reviews as $r) {
                 $RE->distribute_points($r, $action);
                 $accumulated = $accumulated + $RE->calculate_marketvalue($r, $action);
             }
             $this->_message .= $rmsg;
         } else {
             $this->_message .= 'There were no reviews eligible for royalty payment. ';
         }
         // make a record of royalty payment
         if (intval($accumulated) > 0) {
             $MH = new MarketHistory($this->database);
             $data['itemid'] = $ref;
             $data['date'] = Date::toSql();
             $data['market_value'] = $accumulated;
             $data['category'] = 'reviews';
             $data['action'] = $action;
             $data['log'] = $rmsg;
             if (!$MH->bind($data)) {
                 $err = $MH->getError();
             }
             if (!$MH->store()) {
                 $err = $MH->getError();
             }
         }
     } else {
         $this->_message .= 'Royalties on Reviews for ' . $curyear . ' were previously distributed. ';
     }
     // Get Royalties on Resources
     if (!$royaltyResources) {
         // get eligible
         $ResE = new \Components\Resources\Helpers\Economy\Reviews($this->database);
         $cons = $ResE->getCons();
         $accumulated = 0;
         if ($cons) {
             foreach ($cons as $con) {
                 $ResE->distribute_points($con, $action);
                 $accumulated = $accumulated + $con->ranking;
             }
             $this->_message .= $resmsg;
         } else {
             $this->_message .= 'There were no resources eligible for royalty payment.';
         }
         // make a record of royalty payment
         if (intval($accumulated) > 0) {
             $MH = new MarketHistory($this->database);
             $data['itemid'] = $ref;
             $data['date'] = Date::toSql();
             $data['market_value'] = $accumulated;
             $data['category'] = 'resources';
             $data['action'] = $action;
             $data['log'] = $resmsg;
             if (!$MH->bind($data)) {
                 $err = $MH->getError();
             }
             if (!$MH->store()) {
                 $err = $MH->getError();
             }
         }
     } else {
         $this->_message .= 'Royalties on Resources for ' . $curyear . ' were previously distributed.';
     }
     if (!$auto) {
         // show output if run manually
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt($this->_message));
     }
 }
コード例 #2
0
ファイル: members.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Calculate point royalties for members
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function onPointRoyalties(\Components\Cron\Models\Job $job)
 {
     $this->database = App::get('db');
     $action = 'royalty';
     // What month/year is it now?
     $curmonth = Date::format("F");
     $curyear = Date::format("Y-m");
     $ref = strtotime($curyear);
     $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_ANSWERS', $curyear);
     $rmsg = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_REVIEWS', $curyear);
     $resmsg = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_RESOURCES', $curyear);
     // Make sure we distribute royalties only once/ month
     $royaltyAnswers = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'answers', $curyear, $this->_message);
     $royaltyReviews = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'reviews', $curyear, $rmsg);
     $royaltyResources = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'resources', $curyear, $resmsg);
     // Include economy classes
     if (is_file(PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php')) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php';
     }
     if (is_file(PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php')) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php';
     }
     $AE = new \Components\Answers\Helpers\Economy($this->database);
     $accumulated = 0;
     // Get Royalties on Answers
     if (!$royaltyAnswers) {
         $rows = $AE->getQuestions();
         if ($rows) {
             foreach ($rows as $r) {
                 $AE->distribute_points($r->id, $r->q_owner, $r->a_owner, $action);
                 $accumulated = $accumulated + $AE->calculate_marketvalue($r->id, $action);
             }
             // make a record of royalty payment
             if (intval($accumulated) > 0) {
                 $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'answers', 'action' => $action, 'log' => $this->_message));
                 if (!$MH->save()) {
                     $err = $MH->getError();
                 }
             }
         } else {
             $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_QUESTIONS');
         }
     } else {
         $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_ANSWERS', $curyear);
     }
     // Get Royalties on Resource Reviews
     if (!$royaltyReviews) {
         // get eligible
         $RE = new \Components\Resources\Helpers\Economy\Reviews($this->database);
         $reviews = $RE->getReviews();
         // do we have ratings on reviews enabled?
         $param = Plugin::byType('resources', 'reviews');
         $plparam = new \Hubzero\Config\Registry($param->params);
         $voting = $plparam->get('voting');
         $accumulated = 0;
         if ($reviews && $voting) {
             foreach ($reviews as $r) {
                 $RE->distribute_points($r, $action);
                 $accumulated = $accumulated + $RE->calculate_marketvalue($r, $action);
             }
             $this->_message .= $rmsg;
         } else {
             $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_REVIEWS');
         }
         // make a record of royalty payment
         if (intval($accumulated) > 0) {
             $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'reviews', 'action' => $action, 'log' => $rmsg));
             if (!$MH->save()) {
                 $err = $MH->getError();
             }
         }
     } else {
         $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_REVIEWS', $curyear);
     }
     // Get Royalties on Resources
     if (!$royaltyResources) {
         // get eligible
         $ResE = new \Components\Resources\Helpers\Economy($this->database);
         $cons = $ResE->getCons();
         $accumulated = 0;
         if ($cons) {
             foreach ($cons as $con) {
                 $ResE->distribute_points($con, $action);
                 $accumulated = $accumulated + $con->ranking;
             }
             $this->_message .= $resmsg;
         } else {
             $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_RESOURCES');
         }
         // make a record of royalty payment
         if (intval($accumulated) > 0) {
             $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'resources', 'action' => $action, 'log' => $resmsg));
             if (!$MH->save()) {
                 $err = $MH->getError();
             }
         }
     } else {
         $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_RESOURCES', $curyear);
     }
     return true;
 }