From 3f3b891d862337d77d52ef89d5740d5b7697a506 Mon Sep 17 00:00:00 2001 From: avl Date: Fri, 22 May 2009 15:26:45 +0300 Subject: [PATCH] Improve Verbose & granular HumanTitle() --- ipf/admin/model.php | 12 ++++++++---- ipf/admin/views.php | 6 +----- ipf/utils.php | 12 +++++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ipf/admin/model.php b/ipf/admin/model.php index 27db862..5e49108 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -161,6 +161,10 @@ class IPF_Admin_Model{ $this->modelName = $modelName; } + public function verbose_name(){ + return IPF_Utils::humanTitle($this->modelName); + } + public function setUp(){ $this->model = new $this->modelName; } @@ -354,7 +358,7 @@ class IPF_Admin_Model{ $context = array( 'mode'=>'add', 'page_title'=>'Add '.$this->modelName, - 'classname'=>$this->modelName, + 'classname'=>$this->verbose_name(), 'form'=>$form, 'inlineInstances'=>$this->inlineInstances, 'lapp'=>$lapp, @@ -403,7 +407,7 @@ class IPF_Admin_Model{ $context = array( 'mode'=>'change', 'page_title'=>'Edit '.$this->modelName, - 'classname'=>$this->modelName, + 'classname'=>$this->verbose_name(), 'object'=>$o, 'form'=>$form, 'inlineInstances'=>$this->inlineInstances, @@ -424,7 +428,7 @@ class IPF_Admin_Model{ } $context = array( 'page_title'=>'Delete '.$this->modelName, - 'classname'=>$this->modelName, + 'classname'=>$this->verbose_name(), 'object'=>$o, 'lapp'=>$lapp, 'lmodel'=>$lmodel, @@ -540,7 +544,7 @@ class IPF_Admin_Model{ 'header'=>$this->header, 'objects'=>$objects, 'pager'=>$pager, - 'classname'=>$this->modelName, + 'classname'=>$this->verbose_name(), 'perms'=>$this->getPerms($request), 'filters'=>$this->filters, 'admin_title' => IPF::get('admin_title'), diff --git a/ipf/admin/views.php b/ipf/admin/views.php index b49b461..db7f5ff 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -16,12 +16,8 @@ function IPF_Admin_Views_Index($request, $match){ if ($ma!==null){ $perms = $ma->getPerms($request); if (array_search('view', $perms)!==false){ - if (method_exists($ma, 'verbose_name')) - $mname = $ma->verbose_name(); - else - $mname = $m; $models[] = new IPF_Template_ContextVars(array( - 'name'=>$mname, + 'name'=>$ma->verbose_name(), 'path'=>strtolower($m), 'perms'=>$perms, )); diff --git a/ipf/utils.php b/ipf/utils.php index 2e369d4..0a25f10 100644 --- a/ipf/utils.php +++ b/ipf/utils.php @@ -84,7 +84,17 @@ class IPF_Utils { } static function humanTitle($s){ - return ucfirst(str_replace('_',' ',str_replace('_id','',$s))); + $s = ucfirst(str_replace('_',' ',str_replace('_id','',$s))); + $ns = ''; + for ($i=0; $i0) && (ucfirst($s[$i-1])!=$s[$i-1]) && (ucfirst($s[$i])==$s[$i]) ) + $ns .= ' '; + if ($s[$i]=='_') + $ns .= ' '; + else + $ns .= $s[$i]; + } + return $ns; } static function randomString($len=35) -- 2.49.0