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/Module/Method.php

91 lines
2.5 KiB
PHP
Raw Normal View History

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
*/
class Model_Module_Method extends ORM_OSB {
// 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;
// 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() {
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() {
return substr($this->name,0,substr_count($this->name,'_') ? strpos($this->name,'_') : strpos($this->name,':'));
2013-05-29 11:43:59 +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() {
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;
}
public function url() {
if (! preg_match('/:/',$this->name))
return NULL;
list($type,$action) = preg_split('/:/',$this->name,2);
return URL::link($this->directory(),$this->module->name.$this->controller_sub().'/'.$action);
}
2010-11-29 22:41:08 +00:00
}
?>