Hello, is it possible to edit the expiry date and maximum uses of a code after the code is already created?

Comments

scristian’s picture

I did a custom action for this to be used on views_bulk_operations. This change only expiration date, but can be easily changed to change maximum uses.
Also, it uses Date module.

/**
 * Implementation of hook_action_info().
 */
function your_module_action_info() {
  return array(
    'regcode_edit_expiration_date' => array(
      'type'         	=> 'regcode',
      'description'		=> t('Edit Expiration Date'),
      'configurable' 	=> TRUE,
      'hooks'        	=> array('any' => TRUE),
    ),
	);
}


function regcode_edit_expiration_date_form($context){
	$form = array();

	foreach($context['selection'] as $code){
		$codes .= $code->regcode_code .", "; 
	}
	
	$form['new_expiration_date'] = array(
		'#type'						=> 'date_select',
		'#date_format' 		=> "Y-m-d",
		'#default_value'	=> 'current expiration date', 
		'#title'					=> 'New expiration date',
		'#description'		=> 'New expiration date for code[s]: '.$codes,
		'#date_year_range' => '0:+10',
		'#required' 			=> TRUE,
	);
	
	return $form;
}

function regcode_edit_expiration_date_submit($form, $form_state){
	$new_date = array();	
	$new_date['new_expiration_date'] = $form_state['values']['new_expiration_date'];
	
	return $new_date;
}

function regcode_edit_expiration_date(&$object, $context = array()){
	$new_expiration = strtotime($context['new_expiration_date']);
	db_query('UPDATE {regcode} SET expires=%d WHERE rid=%d', $new_expiration, $object->rid);
}
schiavone’s picture

Version: 6.x-2.7 » 7.x-1.x-dev
Issue summary: View changes

Has anyone tried this with 7.x? If not I might be able to get this into a patch.

progpapa’s picture

Status: Active » Needs review
StatusFileSize
new6.41 KB

The code in #1 requires only smaller changes to work with D7.

I've turned this into a patch for the regcode module, removed the Date module dependency and added an action for changing max uses.

(If you've overridden the view at admin/structure/views/view/regcode, you'll need to add the two new VBO actions manually, otherwise they should show up after a cache clear.)