From a1863504c2e842d156e089fe35993dc2bc7fcc1b Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 7 May 2013 21:08:57 +0300 Subject: [PATCH] code style fixes --- ipf/admin/model.php | 159 +++++++++++++++++++++++--------------- ipf/admin/modelinline.php | 18 ++--- ipf/admin/views.php | 5 +- ipf/application.php | 1 + ipf/auth/app.php | 53 +++++++------ ipf/orm/connection.php | 2 +- 6 files changed, 138 insertions(+), 100 deletions(-) diff --git a/ipf/admin/model.php b/ipf/admin/model.php index 32e09c1..d0d49c7 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -278,21 +278,23 @@ class DateHierarchyListFilter extends BaseListFilter { } } -class IPF_Admin_Model{ +class IPF_Admin_Model +{ static $models = array(); - public static function register($classModel, $classAdmin){ + public static function register($classModel, $classAdmin) + { IPF_Admin_Model::$models[$classModel] = new $classAdmin($classModel); } - public static function isModelRegister($classModel){ - if (array_key_exists($classModel, IPF_Admin_Model::$models)) - return true; - return false; + public static function isModelRegister($classModel) + { + return array_key_exists($classModel, IPF_Admin_Model::$models); } - public static function getModelAdmin($classModel){ - if (array_key_exists($classModel, IPF_Admin_Model::$models)){ + public static function getModelAdmin($classModel) + { + if (array_key_exists($classModel, IPF_Admin_Model::$models)) { $ma = IPF_Admin_Model::$models[$classModel]; $ma->setUp(); return $ma; @@ -305,11 +307,13 @@ class IPF_Admin_Model{ var $inlineInstances = array(); var $perPage = 50; - public function __construct($modelName){ + public function __construct($modelName) + { $this->modelName = $modelName; } - public function verbose_name(){ + public function verbose_name() + { return IPF_Utils::humanTitle($this->modelName); } @@ -318,70 +322,83 @@ class IPF_Admin_Model{ public function titleEdit() { return 'Edit ' . $this->verbose_name(); } public function titleDelete() { return 'Delete ' . $this->verbose_name(); } - public function setUp(){ + public function setUp() + { $this->model = new $this->modelName; } - public function getPerms($request){ + public function getPerms($request) + { return array('view', 'add', 'change', 'delete'); } - protected function setInlines($model, $data=null){ + protected function setInlines($model, $data=null) + { $il = $this->inlines(); - if (is_array($il)){ - foreach($il as $inlineName=>$inlineClassName){ + if (is_array($il)) { + foreach($il as $inlineName=>$inlineClassName) { $this->inlineInstances[] = new $inlineClassName($model,$data); } } } - protected function saveInlines($obj){ - foreach($this->inlineInstances as $inlineInstance){ + protected function saveInlines($obj) + { + foreach($this->inlineInstances as $inlineInstance) { $inlineInstance->save($obj); } } - protected function _listFilters(){ + protected function _listFilters() + { return array(); } - protected function _setupEditForm($form){ + protected function _setupEditForm($form) + { $this->_setupForm($form); } - protected function _setupAddForm($form){ + protected function _setupAddForm($form) + { $this->_setupForm($form); } - protected function _setupForm($form){ - + protected function _setupForm($form) + { } - public function fields(){return null;} + public function fields() + { + return null; + } - public function inlines(){return null;} + public function inlines() + { + return null; + } - public function isValidInlines(){ - foreach($this->inlineInstances as &$il){ - if ($il->isValid()===false){ + public function isValidInlines() + { + foreach ($this->inlineInstances as &$il) + if ($il->isValid() === false) return false; - } - } return true; } - public function ListItemsHeader(){ + public function ListItemsHeader() + { $this->header = array(); if (method_exists($this,'list_display')) $this->names = $this->list_display(); else $this->names = $this->model->getTable()->getColumnNames(); - foreach ($this->names as $name){ + foreach ($this->names as $name) { $this->header[$name] = new IPF_Template_ContextVars(array( - 'title'=>IPF_Utils::humanTitle($name), - 'name'=>$name, - 'sortable'=>null, + 'title' => IPF_Utils::humanTitle($name), + 'name' => $name, + 'sortable' => null, )); } return $this->header; @@ -399,14 +416,15 @@ class IPF_Admin_Model{ $this->q = IPF_ORM_Query::create()->from($this->modelName)->orderby($ord); } - public function ListRow($o){ + public function ListRow($o) + { $row = array(); - foreach($this->header as &$h){ + foreach ($this->header as &$h) { $listMethod = 'column_'.$h['name']; - if (method_exists($this,$listMethod)) + if (method_exists($this,$listMethod)) { $str = $this->$listMethod($o); - else{ + } else { $t = $o->getTable()->getTypeOf($h['name']); $str = $o->$h['name']; if ($t=='boolean'){ @@ -422,73 +440,86 @@ class IPF_Admin_Model{ return $row; } - protected function linksRow(&$row, $o){ - if (method_exists($this,'list_display_links')){ + protected function linksRow(&$row, $o) + { + if (method_exists($this, 'list_display_links')) { $links_display = $this->list_display_links(); - }else{ + } else { $links_display = null; $i = 1; } - foreach($row as $name=>&$v){ - if ($links_display){ - if (array_search($name, $links_display)!==false) + foreach ($row as $name => &$v) { + if ($links_display) { + if (array_search($name, $links_display) !== false) $v = ''.$v.''; - }else{ - if ($i==1) + } else { + if ($i == 1) $v = ''.$v.''; $i++; } } } - protected function UrlForResult($o){ + protected function UrlForResult($o) + { return $o->__get($this->model->getTable()->getIdentifier()).'/'; } - protected function _getForm($model_obj, $data, $extra){ + protected function _getForm($model_obj, $data, $extra) + { return IPF_Shortcuts::GetFormForModel($model_obj,$data,$extra); } - protected function _getEditForm($model_obj, $data, $extra){ + protected function _getEditForm($model_obj, $data, $extra) + { return $this->_getForm($model_obj, $data, $extra); } - protected function _getAddForm($model_obj, $data, $extra){ + protected function _getAddForm($model_obj, $data, $extra) + { return $this->_getForm($model_obj, $data, $extra); } - protected function _getListTemplate(){ + protected function _getListTemplate() + { return 'admin/items.html'; } - protected function _getAddTemplate(){ + protected function _getAddTemplate() + { return 'admin/change.html'; } - protected function _getChangeTemplate(){ + protected function _getChangeTemplate() + { return 'admin/change.html'; } - protected function _beforeEdit($o){ + protected function _beforeEdit($o) + { $this->_beforeChange($o); } - protected function _beforeAdd($o){ + protected function _beforeAdd($o) + { $this->_beforeChange($o); } protected function _beforeChange($o){ } - protected function _afterEdit($o){ + protected function _afterEdit($o) + { $this->_afterChange($o); } - protected function _afterAdd($o){ + protected function _afterAdd($o) + { $this->_afterChange($o); } - protected function _afterChange($o){ + protected function _afterChange($o) + { } // Views Function @@ -695,19 +726,22 @@ class IPF_Admin_Model{ return IPF_Shortcuts::RenderToResponse($this->_getListTemplate(), $context, $request); } - protected function _ListFilterQuery($request){ + protected function _ListFilterQuery($request) + { foreach($this->filters as $f){ $f->FilterQuery($request,$this->q); } } - protected function _isSearch(){ + protected function _isSearch() + { if (method_exists($this,'_searchFields')) return true; return false; } - protected function _ListSearchQuery($request){ + protected function _ListSearchQuery($request) + { $this->search_value = null; if (!$this->_isSearch()) return; @@ -727,7 +761,8 @@ class IPF_Admin_Model{ return false; } - protected function _GetFilters($request){ + protected function _GetFilters($request) + { $this->filters = array(); $rels = $this->model->getTable()->getRelations(); foreach($this->_listFilters() as $f){ diff --git a/ipf/admin/modelinline.php b/ipf/admin/modelinline.php index 4ab936c..ef20ee8 100644 --- a/ipf/admin/modelinline.php +++ b/ipf/admin/modelinline.php @@ -1,8 +1,7 @@ getModelName())); } - function createFormSet($data){ - + function createFormSet($data) + { $this->formset = array(); $o = $this->_orderableColumn(); @@ -148,8 +148,8 @@ abstract class IPF_Admin_ModelInline{ ->orderby('id') ->where($this->getFkLocal().'='.$this->parentModel->id) ->execute(); - foreach ($objects as $obj){ - foreach($this->formset as $form){ + foreach ($objects as $obj) { + foreach ($this->formset as $form) { if ($form->isAdd) continue; diff --git a/ipf/admin/views.php b/ipf/admin/views.php index 86b47ee..2d64b99 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -176,9 +176,8 @@ function IPF_Admin_Views_Reorder($request, $match) $lmodel = $match[2]; $am = IPF_Admin_App::GetAppModelFromSlugs($lapp, $lmodel); - - if ($am !== null) - { + + if ($am !== null) { $app = $am['app']; $m = $am['modelname']; diff --git a/ipf/application.php b/ipf/application.php index 52e488a..f32af43 100644 --- a/ipf/application.php +++ b/ipf/application.php @@ -77,3 +77,4 @@ abstract class IPF_Application{ IPF_ORM::loadModels($this->path.'models'); } } + diff --git a/ipf/auth/app.php b/ipf/auth/app.php index 9fafdea..5568add 100644 --- a/ipf/auth/app.php +++ b/ipf/auth/app.php @@ -13,30 +13,33 @@ class IPF_Auth_App extends IPF_Application )); } - static function login($request, $user){ + static function login($request, $user) + { $request->user = $user; $request->session->clear(); $request->session->setData('login_time', gmdate('Y-m-d H:i:s')); $user->save(); } - public function getTitle(){ + public function getTitle() + { return 'User Accounts'; } - static function logout($request){ + static function logout($request) + { $request->user = new User(); $request->session->clear(); $request->session->setData('logout_time', gmdate('Y-m-d H:i:s')); } - + static function createPermissionsFromModels(array $pathesToModels) { $baseAdmin = new IPF_Admin_Model(); $basePerms = $baseAdmin->getPerms(); $permsTable = IPF_ORM::getTable('Permission'); $appList = IPF_Project::getInstance()->appList(); - + $permissions = array(); foreach ($pathesToModels as $path) @@ -44,7 +47,7 @@ class IPF_Auth_App extends IPF_Application foreach (IPF_ORM::filterInvalidModels(IPF_ORM::loadModels($path)) as $modelName) { $adminModel = IPF_Admin_Model::getModelAdmin($modelName); - + if ($adminModel) { $perms = method_exists($adminModel, 'getPerms') ? $adminModel->getPerms(null) : $basePerms; @@ -60,22 +63,22 @@ class IPF_Auth_App extends IPF_Application } } } - + print "COLLECTED PERMS:\n----\n".implode("\n", $permissions)."\n----\n"; if (count($permissions)) { $existingPerms = array(); - + foreach ($permsTable->findAll() as $model) $existingPerms[] = $model->name; - + print "EXISTING PERMS:\n----\n".implode("\n",$existingPerms)."\n----\n"; if (count($existingPerms)) { $toDel = array_diff($existingPerms, $permissions); - + print "2DEL:\n----\n".implode("\n",$toDel)."\n----\n"; if (count($toDel)) @@ -102,9 +105,9 @@ class IPF_Auth_App extends IPF_Application $toAdd = $permissions; } - + print "2ADD:\n----\n".implode("\n",$toAdd)."\n----\n"; - + foreach ($toAdd as $name) { $model = new Permission(); @@ -115,11 +118,11 @@ class IPF_Auth_App extends IPF_Application else { print "REMOVE ALL\n"; - + $permsTable->createQuery()->delete()->execute(); // no women, no cry... } } - + static function ArePermissionsEnabled() { try { @@ -128,27 +131,27 @@ class IPF_Auth_App extends IPF_Application return true; } } - + static function checkPermissions($request, $app, $modelName, array $perms) { $count = count($perms); - + if (!$count) return array(); - + $permissions = array_combine($perms, array_fill(0, $count, false)); - + if ($request->user->isAnonymous() || !($request->user->is_staff || $request->user->is_superuser)) return $permissions; - + if ($request->user->is_superuser || !self::ArePermissionsEnabled()) return array_combine($perms, array_fill(0, $count, true)); - + $user_permissions = array(); - + foreach ($request->user->Permissions as $up) $user_permissions[] = $up->name; - + foreach ($request->user->Roles as $role) { foreach ($role->Permissions as $rp) @@ -157,12 +160,12 @@ class IPF_Auth_App extends IPF_Application $user_permissions[] = $rp->name; } } - + if (!count($user_permissions)) return $permissions; - + $prefix = get_class($app).'|'.$modelName.'|'; - + foreach ($permissions as $permName=>&$permValue) { $permissionValue = $prefix.$permName; diff --git a/ipf/orm/connection.php b/ipf/orm/connection.php index 6575a4f..ab0d593 100644 --- a/ipf/orm/connection.php +++ b/ipf/orm/connection.php @@ -845,4 +845,4 @@ abstract class IPF_ORM_Connection extends IPF_ORM_Configurable implements Counta { return IPF_ORM_Utils::getConnectionAsString($this); } -} \ No newline at end of file +} -- 2.49.0