42 lines
1016 B
PHP
42 lines
1016 B
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* Manage the next record ID
|
|
*
|
|
* @package lnAuth
|
|
* @category Models
|
|
* @author Deon George
|
|
* @copyright (c) 2014 Deon George
|
|
* @license http://dev.leenooks.net/license.html
|
|
*/
|
|
abstract class lnAuth_Model_Record_ID extends ORM {
|
|
protected $_primary_key = 'module_id';
|
|
|
|
// This module doesnt keep track of column updates automatically
|
|
protected $_created_column = FALSE;
|
|
protected $_updated_column = FALSE;
|
|
|
|
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 HTTP_Exception::factory(501,'Unable to increase ID for :table',array(':table'=>$mid));
|
|
|
|
return $this->id;
|
|
}
|
|
}
|
|
?>
|