Esempio n. 1
0
 public static function insertUserPoints($referrerid, $result, $referraluserpoints = 0, $keyreference = '', $datareference = '', $frontmessage = '')
 {
     $jnow = JFactory::getDate();
     $now = $jnow->toSql();
     $points = $result->points;
     $rule_expire = AlphaUserPointsHelper::checkRuleExpireDate($result->rule_expire, $result->type_expire_date);
     $rule_id = $result->id;
     $autoapproved = $result->autoapproved;
     $rule_plugin = $result->plugin_function;
     $rule_name = $result->rule_name;
     $noupdate = 0;
     // get params definitions
     $params = JComponentHelper::getParams('com_alphauserpoints');
     $insertAllActivities = $params->get('insertAllActivities', 0);
     if ($insertAllActivities) {
         if (!$referrerid) {
             return;
         }
     } else {
         if (!$referrerid || $points == 0) {
             return;
         }
     }
     $points = $referraluserpoints > 0 ? $referraluserpoints : $points;
     // load external plugins
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('alphauserpoints');
     $results = $dispatcher->trigger('onBeforeInsertUserActivityAlphaUserPoints', array(&$result, $points, $referrerid, $keyreference, $datareference));
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables');
     // save new points into alpha_userpointsdetails table
     $row = JTable::getInstance('userspointsdetails');
     $row->id = NULL;
     $row->referreid = $referrerid;
     $row->points = $points;
     $row->insert_date = $now;
     $row->expire_date = $rule_expire;
     $row->rule = $rule_id;
     $row->approved = $autoapproved;
     $row->status = $autoapproved;
     $row->keyreference = $keyreference;
     $row->datareference = $datareference;
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     if ($noupdate) {
         return;
     }
     if ($referrerid != 'GUEST' || $referraluserpoints > 0) {
         if ($rule_plugin == '') {
             $rule_plugin = AlphaUserPointsHelper::getPluginFunction($rule_id);
         }
         if ($rule_name == '') {
             $rule_name = AlphaUserPointsHelper::getNameRule($rule_plugin);
         }
         AlphaUserPointsHelper::updateUserPoints($result, $referrerid, $points, $now, $referraluserpoints, $autoapproved, $rule_plugin, $rule_id, $rule_name, $datareference, $frontmessage);
     }
 }