Hi, I made ​​a change to the serial id and generates 'fattto by YYYYxxxxxx (2012000001) and change the' year in auto

<?php

/**
 /**
 * Generates a unique serial value (unique per node type).
 *
 * @param $nid
 *   id of the node for which to generate a serial value
 * @param $bundle
 *   a containing bundle (e.g. content type)
 * @param $field_name
 *   the field name
 * @param $delete
 *   indicates if temporary records should be deleted
 * @return
 *   the unique serial value number.
 */
function _serial_generate_value($nid, $bundle, $field_name, $delete = TRUE) {

  // Get the name of the relevant table.
  $table = _serial_get_table_name($bundle, $field_name);
    
// modifica maxx serializzazione con reset automatico a fine anno 
// campo composto da anno sid = YYYYXXXXXX 
    
    $annonew = date("Y");								
    $annoold = date("Y");
    
  	$query = db_select($table,'a');
    $query->fields('a',array('sid','nid'));
    $query->range(0,1);
	$query->orderBy('sid', 'DESC');
    $result = $query->execute();
	$record = $result->fetchAssoc();
    
	if($record)
	{
    	$annoold = substr($record["sid"],0,-6);
    }

    if( ($annoold != $annonew) || ($record == null) )
	{
		drupal_set_message("Eseguito cambio Anno o creato record di start-up");
    	$sid = db_insert($table)
			->fields(array(
  			'sid' => $annonew.'000001',
  			'nid' => $nid,
		))
		->execute();
 	}
 	else
	{
 	  	// Create a temporary record for this node and retrieve the serial value.
  		$sid = db_insert($table)
    		->fields(array(
      		'nid' => $nid,
  		))
    	->execute();
	}
// fine modifica maxx


  // If there's a reason why it's come back undefined, reset it.
  $sid = isset($sid) ? $sid : 0;

  // Delete old temporary records:
  if ($delete && ($sid % 10) == 0) {
    db_delete($table)
      ->condition('nid', $nid, '<')
      ->execute();
  }

  // Return the new unique serial value:
  return $sid;
}



CommentFileSizeAuthor
serial.inc_.txt6.46 KBrebel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

colan’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Patch (to be ported) » Needs work
  • Please edit this issue to explain better what this feature is about, and why you need it. It's not clear what you're talking about.
  • New features go into the latest dev branch.
  • All code changes should be provided in patch format.
  • The "patch (to be ported)" is to be used only when a patch for the latest dev branch (e.g. Drupal 7) is finalized, and it needs to be ported to another dev branch (i.e. Drupal 6).
  • When uploading a patch for review, set the state to "needs review".
rebel’s picture

Difference Report - 05/05/2012, 12:26
================================================================================

File 1: "\sites\all\modules\serial\serial.inc"
Last modified on 29/03/2012, 15:49
File 2: "\sites\all\modules\serial\serial.inc_orig"
Last modified on 27/03/2012, 18:15

================================================================================
Lines deleted at 149
================================================================================
-
- // modifica maxx serializzazione con reset automatico a fine anno
- // campo composto da anno sid = YYYYXXXXXX
-
- $annonew = date("Y");
- $annoold = date("Y");
-
- $query = db_select($table,'a');
- $query->fields('a',array('sid','nid'));
- $query->range(0,1);
- $query->orderBy('sid', 'DESC');
- $result = $query->execute();
- $record = $result->fetchAssoc();
-
- if($record)
- {
- $annoold = substr($record["sid"],0,-6);
- }
================================================================================
Lines modified at 168
================================================================================
- if( ($annoold != $annonew) || ($record == null) )
+ // Create a temporary record for this node and retrieve the serial value.
- {
+ $sid = db_insert($table)
- drupal_set_message("Eseguito cambio Anno o creato record di start-up");
+ ->fields(array(
- $sid = db_insert($table)
+ 'nid' => $nid,
- ->fields(array(
+ ))
- 'sid' => $annonew.'000001',
+ ->execute();
================================================================================
Lines deleted at 174
================================================================================
- 'nid' => $nid,
- ))
- ->execute();
- }
- else
- {
- // Create a temporary record for this node and retrieve the serial value.
- $sid = db_insert($table)
- ->fields(array(
- 'nid' => $nid,
- ))
- ->execute();
- }
- // fine modifica maxx
-

luisasasi’s picture

Thank you. Rebel changes work well. The change of year numbering is restarted from 2013000001. Many Italian school sites are using Serial with Rebel correction in serial .module and serial.inc

kaizerking’s picture

Wow good work
I am also looking for this kind of solution but bit different way pl check herehttps://drupal.org/node/1588384#comment-7256294

I am looking to be able to set the start and end numbers per year i.e admin (or permitted user) should be able to set the start number and end number range same way as this is working.but needs the following
1.the year value should not be concatenated,but should be related.

colan’s picture

Status: Needs work » Closed (duplicate)

I know this issue is older, but there was more work done on the other one: #2168071: Add support for year prefix. Please add any functionality from here (that's missing in the other issue) over there. Thanks!