欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

平忠自定义规则 rules rule 有大用

shiping1 的头像
shipingzhongcustomrules.info文件
; $Id$
name = Shipingzhong custom rules
description = Shipingzhong Custom rules
core = 6.x
package = custom
project = "shipingzhongcustomrules"



shipingzhongcustomrules.module文件
//它里面没有内容


shipingzhongcustomrules.rules.inc文件

<?php

function shipingzhongcustomrules_rules_action_info() {
  $actions = array(
    'add_sort_value_action' => array(
      'label' => '给课程和教程的排序字段赋初始值',
      'arguments' => array(
        'node' => array('type' => 'node', 'label' => t('Content')),
      ),
      'module' => 'Node',
    ),
    'update_kecheng_price_and_image' => array(
      'label' => '更新课程的价格和图',
      'arguments' => array(
        'node' => array('type' => 'node', 'label' => t('Content')),
      ),
      'module' => 'Node',
    ),
    'copy_shiping_to_red5' => array(
      'label' => '复制视频到red5',
      'arguments' => array(
        'node' => array('type' => 'node', 'label' => t('Content')),
      ),
      'module' => 'Node',
    ),
  );
  return $actions;
}


 
function add_sort_value_action($node) {
    if(empty($node->field_sort[0]['value']) && (strcmp($node->field_sort[0]['value'],'0')!=0)){
        $node->field_sort[0]['value'] = 4*($node->nid);
    }
    //drupal_set_message('这就是排序值'.$node->field_sort[0]['value']);
    return array('node' => $node);
}


function update_kecheng_price_and_image($node) {
    //得到课程的id
    $keChengId = db_result(db_query("select nid from {content_type_kecheng} where field_productkit_nid=%d",$node->nid));
    $keyChengObj = node_load($keChengId);
    $keyChengObj->field_price[0]['value']  = $node->sell_price;
    $keyChengObj->field_cart_img[0]['fid'] = $node->field_image_cache[0]['fid'];
    node_save($keyChengObj);
    //$node->field_sort[0]['value'] = 4*($node->nid);
    drupal_set_message('课程的价格和课程的购物车中的图也已更新');
    
}

//复制视频到 red5
function copy_shiping_to_red5($node){
    
        $shipingName = $node->field_jiaochengshiping[0]['filename'];
        $shipingPath = $node->field_jiaochengshiping[0]['filepath'];
        $shipingTuPath = $node->field_shipingtu[0]['filepath'];
        if($shipingName){
            //$node->field_shiping_bofang_intro[0]['value'] = "[jwplayer|config=sample|file=".$shipingName."|streamer=rtmp://211.149.191.199/oflaDemo|image=http://yc.4000512126.com/".$shipingTuPath."]";
            copy($_SERVER['DOCUMENT_ROOT'].'/'.$shipingPath,'C:/Program Files/Red5/webapps/oflaDemo/streams/'.$shipingName);
            //$node->field_shiping_bofang_intro[0]['value'] = "[jwplayer|config=sample|file=".$shipingName."|streamer=rtmp://localhost/oflaDemo|image=http://yc.4000512126.com/".$shipingTuPath."]";
            //copy($_SERVER['DOCUMENT_ROOT'].'/'.$shipingPath,'/usr/local/red5/webapps/totalcontrollive/streams/'.$shipingName);
        }
        drupal_set_message('已复制视频到播放器!');
    
}



//这是增加rules的条件
function shipingzhongcustomrules_rules_condition_info() {
  return array(
    'judge_first_login_everyday' => array(
      'label' => t('judge_first_login_everyday'),
      'base' => 'judge_first_login_everyday',
    ),
  );
}

//这是判断用户的每天的第一次登录
function judge_first_login_everyday()
{
    global $user;
    if(1>0){
        print_r($user->access);
        return false;
    }
    else{
        return false;
    }
    
}
普通分类: