From 2ecf29c7482f5de6318ef52206a3dbbaf335c989 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Wed, 26 Jun 2013 00:37:40 +0300 Subject: [PATCH] code style --- ipf/admin/modelinline.php | 66 +++++++++++++++++++++------------------ ipf/admin/views.php | 3 +- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/ipf/admin/modelinline.php b/ipf/admin/modelinline.php index d1619d6..f49d666 100644 --- a/ipf/admin/modelinline.php +++ b/ipf/admin/modelinline.php @@ -8,7 +8,8 @@ abstract class IPF_Admin_ModelInline var $orderby = 'id'; - function __construct($parentModel,$data=null){ + function __construct($parentModel,$data=null) + { $this->parentModel = $parentModel; $modelName = $this->getModelName(); @@ -23,16 +24,21 @@ abstract class IPF_Admin_ModelInline return IPF_Utils::appByModel($this->getModelName()); } - function getAddNum(){ return 4; } + function getAddNum() + { + return 4; + } - function getLegend(){ + function getLegend() + { return get_class($this->model); } - function isValid(){ - foreach($this->formset as &$form){ - if (!$form->isValid()){ - if (!$form->isAdd){ + function isValid() + { + foreach ($this->formset as &$form) { + if (!$form->isValid()) { + if (!$form->isAdd) { return false; } } @@ -45,17 +51,19 @@ abstract class IPF_Admin_ModelInline return IPF_Shortcuts::GetFormForModel($model_obj, $data, $extra); } - function getFkName(){ - foreach($this->model->getTable()->getRelations() as $rel){ + function getFkName() + { + foreach($this->model->getTable()->getRelations() as $rel) { if ($rel->getClass()==get_class($this->parentModel)) return $rel->getAlias(); } throw new IPF_Exception(__('Cannot get fkName for '.$this->getModelName())); } - function getFkLocal(){ - foreach($this->model->getTable()->getRelations() as $rel){ - if ($rel->getClass()==get_class($this->parentModel)) + function getFkLocal() + { + foreach($this->model->getTable()->getRelations() as $rel) { + if ($rel->getClass() == get_class($this->parentModel)) return $rel->getLocal(); } throw new IPF_Exception(__('Cannot get fkLocal for '.$this->getModelName())); @@ -78,7 +86,7 @@ abstract class IPF_Admin_ModelInline $first = true; - if ($this->parentModel->exists()){ + if ($this->parentModel->exists()) { $query = IPF_ORM_Query::create() ->from(get_class($this->model)) ->where($this->getFkLocal().'='.$this->parentModel->id); @@ -88,54 +96,52 @@ abstract class IPF_Admin_ModelInline else $objects = $query->orderby($this->orderby)->execute(); - foreach ($objects as $obj){ + foreach ($objects as $obj) { $prefix = 'edit_'.get_class($this->model).'_'.$obj->id.'_'; $d = array(); - if ($data===null){ - foreach ($obj->getData() as $k=>$v){ + if ($data===null) { + foreach ($obj->getData() as $k=>$v) { $d[$prefix.$k] = $v; } - } - else{ - foreach ($data as $k=>$v){ - if (strpos($k,$prefix)==0) + } else { + foreach ($data as $k=>$v) { + if (strpos($k,$prefix) == 0) $d[$k] = $v; } } $form = $this->_getForm($obj, $d, $form_extra); - $form->prefix = $prefix; $form->fields = array_merge(array( new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'is_remove')), - ),$form->fields); + ), $form->fields); $form->isAdd = false; - if ($first){ + if ($first) { $form->isFirst = true; $first = false; - } - else + } else { $form->isFirst = false; + } $this->formset[] = $form; } } $n_addnum = $this->getAddNum(); - for($i=0; $i<$n_addnum; $i++ ){ + for ($i = 0; $i < $n_addnum; $i++) { $form = $this->_getForm($this->model->copy(), null, $form_extra); $form->fields = array_merge(array(new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'delete_', 'widget_attrs'=>array('disabled'=>'disabled')))),$form->fields); $form->prefix = 'add_'.get_class($this->model).'_'.$i.'_'; $form->data = $data; $form->isAdd = true; - if ($first){ + if ($first) { $form->isFirst = true; $first = false; - } - else + } else { $form->isFirst = false; + } $this->formset[] = $form; } } @@ -183,7 +189,7 @@ abstract class IPF_Admin_ModelInline $fk_local = $this->getFkLocal(); foreach ($this->formset as $form) { if ($form->isValid()) { - if ($form->isAdd){ + if ($form->isAdd) { unset($form->cleaned_data[0]); $form->cleaned_data[$fk_local] = $parent_obj->id; $form->save(); diff --git a/ipf/admin/views.php b/ipf/admin/views.php index b451d06..98d6f88 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -440,7 +440,7 @@ function IPF_Admin_Views_FileBrowser($request, $match){ $pth = explode('/',$curr_dir); $path = array(); $cd = '/admin/filebrowser/'; - foreach($pth as $p){ + foreach($pth as $p) { $cd.=$p.'/'; $path[] = array('cd'=>$cd, 'name'=>$p); } @@ -470,3 +470,4 @@ function IPF_Admin_Views_FileBrowserRename($request, $match) $name=$old_name; return new IPF_HTTP_Response($name); } + -- 2.49.0