File pdf versions

Hi I add the following code to the pdf template I created call pricedetail to enable versions of PDF files.


$extrafields = new ExtraFields($this->db);
			$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
			//Add the code to load extrafield into object
			$object->fetch($rowid);
			$object->fetch_optionals($rowid,$extralabels);
			//var_dump($object->array_options ); exit;
			if ( !(isset($object->array_options['options_version' ]))){
					$object->array_options['options_version' ] =0;
					$object->insertExtraFields($trigger = '',$userused = null);
			}
			if ($object->statut != $object::STATUS_DRAFT &&   $object->statut != $object::STATUS_SIGNED    &&   $object->statut != $object::STATUS_BILLED   &&   $object->statut != $object::STATUS_NOTSIGNED ) {
				$object->array_options['options_version' ]++;
				$object->insertExtraFields($trigger = '',$userused = null);
				}
			   $withoutExt = preg_replace('/\.\w+$/', '', $file);
				$file =  $withoutExt  . "-"  .  $object->array_options['options_version' ] . ".pdf";
				$pdf->Output($file, 'F');

I was wondering if it was a good place to do this and does it practices for dolibarr ?