This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/Model/Record/Id.php
2013-03-20 23:04:51 +11:00

42 lines
1.1 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package OSB
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Record_Id extends ORM_OSB {
protected $_primary_key = 'module_id';
// This module doesnt keep track of column updates automatically
protected $_created_column = FALSE;
protected $_updated_column = FALSE;
// @todo we need $mid here, since if there is no record, we cant figure out the module that called us.
public function next_id($mid) {
if (is_null($this->id)) {
$this->module_id = $mid;
// We'll get the next ID as the MAX(id) of the table
$mo = ORM::factory('Module',$mid);
$max = DB::select(array('MAX(id)','id'))
->from($mo->name)
->where('site_id','=',Company::instance()->site());
$this->id = $max->execute()->get('id');
}
$this->id++;
if (! $this->save())
throw new Koahan_Exception(_('Unable to increase ID for :table'),array(':table'=>$mid));
return $this->id;
}
}
?>