您的位置:首页 > 编程语言 > VB

Drupal 中 写VBO操作模块

2016-07-12 09:20 288 查看
内容就不说别的什么了,直接贴下代码:

<?php

/**
* @file
* Defines "fabric_base_vbo"
*
* @TODO: Split admin functions into their own file.
*/
/* function fabric_base_vbo_action_info(&$form, $form_state, $form_id) {
定义一个VBO操作列表
} */
//新定义一个VBO 批量设置出仓库操作
function fabric_base_vbo_action_info(){
return array(
'fabric_base_vbo_action'=>array(
'type'=>'entity',
'label'=>t('批量出仓'),
'behavior'=>array('change_property'),
'configurable'=>FALSE,
'vbo_configurable'=>TRUE,
'triggers'=>array('any'),
'permissions'=>array('fabric base vbo','storage vbo'),
),

);
}

//定义一个VBO configuration form 的操作方法
function fabric_base_vbo_action_views_bulk_operations_form($options){
$form=array();
$form['vbo']['select']= array(
'#type' => 'select',
'#title' => t('批量操作选项'),
'#options'=>array(
'AllSelect'=>t('余量出仓'),
'Something'=>t('部分出仓'),
),
'#default_value'=>!empty($options['vbo']['select'])?$options['vbo']['select']:'',

);
$form['vbo']['num']=array(
'#type'=>'textfield',
'#title'=>t('数量'),
'#default_value'=>0,
'#size'=>60,

);
return $form;
}
function fabric_base_vbo_action_form($settings,&$form_state){
//dpm($form_state);
// watchdog('views','Execute action from',array(),WATCHDOG_DEBUG);
$form=array();
$form['vbo']['select']= array(
'#type' => 'select',
'#title' => t('批量操作选项'),
'#options'=>array(
'AllSelect'=>t('余量出仓'),
'Something'=>t('部分出仓'),
),
'#default_value'=>isset($settings['settings']['vbo']['select'])?$settings['settings']['vbo']['select']:'',

);
$form['vbo']['num']=array(
'#type'=>'textfield',
'#title'=>t('数量'),
'#default_value'=>0,
'#size'=>60,
);
return $form;
}
function fabric_base_vbo_action_submit($form,$form_state){
$return =array();
switch ($form_state['values']['select'])
{
case 'AllSelect':
$return['select']=$form_state['values']['select'];
break;
case 'Something':
$return['select']=$form_state['values']['select'];
$return['num']=$form_state['values']['num'];
break;
default:break;
}
return $return;
}

function fabric_base_vbo_action(&$entity,$context){

if (!isset($context['node']->nid)){
return;
}
$node=node_load($context['node']->nid);

if(!isset($node->field_warehousestorageio['und'][0]['value'])){
$message=t('Can not Storage,Fabric @nid have not setting',array(
'@nid'=>$context['node']->nid,
));
return drupal_set_message($message);
}
if($node->field_warehousestorageio['und'][0]['value']<=0){
$message=t('Can not Storage,Fabric @nid have 0 unit!',array(
'@nid'=>$context['node']->nid,
));
return drupal_set_message($message);
}
// dpm($node);
switch ($context['select'])
{
case 'AllSelect':
$node->field_warehousestoio['und'][0]['first']=-(int)$node->field_warehousestorageio['und'][0]['value'];
$node->field_warehousestoio['und'][0]['second']=time();
$node->field_warehousestorageio['und'][0]['value']=0;
node_save($node);
$message=t('Fabric @nid was update @num unit',array(
'@nid'=>$context['node']->nid,
'@num'=>$node->field_warehousestoio['und'][0]['first'],
));
drupal_set_message($message);
break;
case 'Something':
if (!isset($context['num']) || !(int)$context['num']){
$message=t('Setting Error!Check the Num.');
return drupal_set_message($message);
}
if($node->field_warehousestorageio['und'][0]['value']+$context['num']>=0){
dpm(1);
$node->field_warehousestoio['und'][0]['first']=$context['num'];
$node->field_warehousestoio['und'][0]['second']=time();
$node->field_warehousestorageio['und'][0]['value']+=$context['num'];
$storagenum=$context['num'];
}else{
dpm(0);
$node->field_warehousestoio['und'][0]['first']=$node->field_warehousestorageio['und'][0]['value'];
$node->field_warehousestoio['und'][0]['second']=time();
$storagenum=$node->field_warehousestorageio['und'][0]['value'];
$node->field_warehousestorageio['und'][0]['value']=0;
}
node_save($node);

$message=t('Fabric @nid was update @num unit',array(
'@nid'=>$context['node']->nid,
'@num'=>$storagenum,
));
drupal_set_message($message);

break;
default:break;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  drupal vbo