discuz updatemembercount,notification_add 解析

来源:互联网 发布:oimo.js 编辑:程序博客网 时间:2024/06/08 09:12

这个函数的原始定义如下:

[php] view plaincopy在CODE上查看代码片派生到我的代码片
  1. function updatemembercount($uids$dataarr = array(), $checkgroup = true, $operation = ''$relatedid = 0, $ruletxt = '') {  
  2.         if(!empty($uids) && (is_array($dataarr) && $dataarr)) {  
  3.                 require_once libfile('function/credit');  
  4.                 return _updatemembercount($uids$dataarr$checkgroup$operation$relatedid$ruletxt);  
  5.         }  
  6.         return true;  
  7. }  
里面调用了另一个函数:

[php] view plaincopy在CODE上查看代码片派生到我的代码片
  1. function _updatemembercount($uids$dataarr = array(), $checkgroup = true, $operation = ''$relatedid = 0, $ruletxt = '') {  
  2.         if(empty($uids)) return;  
  3.         if(!is_array($dataarr) || empty($dataarr)) return;  
  4.         if($operation && $relatedid) {  
  5.                 $writelog = true;  
  6.                 $log = array(  
  7.                         'uid' => $uids,  
  8.                         'operation' => $operation,  
  9.                         'relatedid' => $relatedid,  
  10.                         'dateline' => time(),  
  11.                 );  
  12.         } else {  
  13.                 $writelog = false;  
  14.         }  
  15.         $data = array();  
  16.         foreach($dataarr as $key => $val) {  
  17.                 if(empty($val)) continue;  
  18.                 $val = intval($val);  
  19.                 $id = intval($key);  
  20.                 $id = !$id && substr($key, 0, -1) == 'extcredits' ? intval(substr($key, -1, 1)) : $id;  
  21.                 if(0 < $id && $id < 9) {  
  22.                         $data['extcredits'.$id] = $val;  
  23.                         if($writelog) {  
  24.                                 $log['extcredits'.$id] = $val;  
  25.                         }  
  26.                 } else {  
  27.                         $data[$key] = $val;  
  28.                 }  
  29.         }  
  30.         if($writelog) {  
  31.                 DB::insert('common_credit_log'$log);  
  32.         }  
  33.         if($data) {  
  34.                 include_once libfile('class/credit');  
  35.                 $credit = & credit::instance();  
  36.                 $credit->updatemembercount($data$uids$checkgroup$ruletxt);  
  37.         }  
  38. }  

其中第四个参数和第五个参数在写积分记录的时候有用,如果两者皆不为空,则系统会在积分记录中记录。

第一个参数用户 用户数组,

第二个参数操作规则,如扣减第二个积分3分:array ('extcredits2' => -3);

第三个参数是否检查用户组升级,通常为true

第四个参数是记录相关操作的变量,

第五个参数看名称应该是记录产生这个积分操作的相关的id值(例如像uid,fid,tid这类的),

第六个参数用于当$data数组(即记录积分增减情况的数组)不为空时,重新调用函数并把值传递给第四个变量.

示例:updatemembercount('10', array('extcredits2' => "-1"), true, '', 0, '');   将uid为10的用户第二个积分-1



notification_add($touid, $type, $note, $notevars = array(), $system = 0)
$touid : 发送给谁?
$type : 方式? 常用的是post
$note : 可以自己编辑内容
$notevars = 一些内容参数
$system = 默认情况下为0

示例:notification_add(10,'post','欢迎来我的网站');    给用户id为10的用户发送一条"欢迎来我的网站"的讯息

0 0
原创粉丝点击