var $orderby = 'id';
- function __construct($parentModel,$data=null){
+ function __construct($parentModel,$data=null)
+ {
$this->parentModel = $parentModel;
$modelName = $this->getModelName();
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;
}
}
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()));
$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);
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;
}
}
$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();