这个应用是延续上一个Batch,原因是数据一多,之前EXCEL操作可以一次批量复制,在网页面上不能实Excel灵活,只能一个记录一个记录的操作十分的费时,使用VBO的批处理可以实现对布匹数据一次性多记录的处理,可以按余量扣仓和定量扣仓的操作方式进行。
以下是我的代码:
<?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 版本