Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
serial.inc_.txt | 6.46 KB | rebel |
Comments
Comment #1
colanComment #2
rebel CreditAttribution: rebel commentedDifference 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
-
Comment #3
luisasasi CreditAttribution: luisasasi commentedThank 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
Comment #4
kaizerking CreditAttribution: kaizerking commentedWow 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.
Comment #5
colanI 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!