2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OSB Application Module Method Model
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2012-12-10 21:48:30 +00:00
|
|
|
class Model_Module_Method extends ORM_OSB {
|
2013-04-26 01:42:09 +00:00
|
|
|
// This module doesnt keep track of column updates automatically
|
|
|
|
protected $_created_column = FALSE;
|
|
|
|
protected $_updated_column = FALSE;
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
// Relationships
|
|
|
|
protected $_belongs_to = array(
|
|
|
|
'module'=>array(),
|
|
|
|
);
|
|
|
|
protected $_has_one = array(
|
|
|
|
'record_id'=>array(),
|
|
|
|
);
|
|
|
|
protected $_has_many = array(
|
|
|
|
'group'=>array('through'=>'group_method','foreign_key'=>'method_id')
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $_sorting = array(
|
|
|
|
'name'=>'ASC',
|
|
|
|
);
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
protected $status;
|
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
// Temporarily adjust our name
|
|
|
|
// @todo This is temporary until all our method names are colon delimited.
|
|
|
|
protected function _load_values(array $values) {
|
|
|
|
parent::_load_values($values);
|
|
|
|
|
|
|
|
if (substr_count($this->name,'_') == 1 AND ! substr_count($this->name,':'))
|
|
|
|
$this->name = str_replace('_',':',$this->name);
|
|
|
|
elseif (substr_count($this->name,'_') > 1)
|
|
|
|
throw HTTP_Exception::factory(501,'Method :id has double underscore',array(':id'=>$this->id));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function controller_sub() {
|
|
|
|
return substr_count($this->name,'_') ? substr($this->name,($x=strpos($this->name,'_')),strpos($this->name,':')-$x) : '';
|
|
|
|
}
|
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
public function controller() {
|
2013-06-04 11:50:41 +00:00
|
|
|
return Kohana::classname(sprintf('Controller%s_%s',($this->directory() ? '_' : '').$this->directory(),$this->module->name).$this->controller_sub());
|
2013-05-29 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function directory() {
|
2013-06-04 11:50:41 +00:00
|
|
|
return substr($this->name,0,substr_count($this->name,'_') ? strpos($this->name,'_') : strpos($this->name,':'));
|
2013-05-29 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
/**
|
|
|
|
* Calculate the description for this method on any menu link
|
|
|
|
*/
|
|
|
|
public function menu_display() {
|
|
|
|
// @todo The test for value equal 1 is for legacy, remove when all updated.
|
|
|
|
if ($this->menu_display AND $this->menu_display != 1)
|
|
|
|
return $this->menu_display;
|
|
|
|
else
|
|
|
|
return sprintf('%s: %s',$this->module->name,$this->name);
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-05-29 11:43:59 +00:00
|
|
|
public function method() {
|
2013-06-04 11:50:41 +00:00
|
|
|
return substr($this->name,strpos($this->name,':')+1);
|
2013-05-29 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function status($status=NULL) {
|
|
|
|
if ($status)
|
|
|
|
$this->status = $status;
|
|
|
|
|
|
|
|
return $this->status;
|
|
|
|
}
|
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
public function url() {
|
2013-06-04 11:50:41 +00:00
|
|
|
if (! preg_match('/:/',$this->name))
|
2013-04-26 01:42:09 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
list($type,$action) = preg_split('/:/',$this->name,2);
|
2011-10-14 05:44:12 +00:00
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
return URL::link($this->directory(),$this->module->name.$this->controller_sub().'/'.$action);
|
2011-10-14 05:44:12 +00:00
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
?>
|