return array('view', 'add', 'change', 'delete');
}
- protected function setInlines($model, &$data){
+ protected function setInlines($model, $data){
$il = $this->inlines();
if (is_array($il)){
foreach($il as $inlineName=>$inlineClassName){
$form = $this->_getAddForm($this->model,null,array('user_fields'=>$this->fields()));
$this->_setupAddForm($form);
$data = array();
- $this->setInlines($this->model, &$data);
+ $this->setInlines($this->model);
}
$context = array(
$form = $this->_getEditForm($o,&$data,array('user_fields'=>$this->fields()));
$this->_setupEditForm($form);
$this->setInlines($o, &$data);
-
if ( ($form->isValid()) && ($this->isValidInlines()) ) {
$item = $form->save();
$this->saveInlines($item);
}
$form = $this->_getEditForm($o,&$data,array('user_fields'=>$this->fields()));
$this->_setupEditForm($form);
- $this->setInlines($o, &$data);
+ $this->setInlines($o);
}
$context = array(
var $parentModel = null;
var $formset = null;
- function __construct($parentModel,$data){
+ function __construct($parentModel,$data=null){
$this->parentModel = $parentModel;
$modelName = $this->getModelName();
$this->model = new $modelName();
-
$this->createFormSet($data);
}
throw new IPF_Exception(__('Cannot get fkLocal for '.$this->getModelName()));
}
- function createFormSet(&$data){
+ function createFormSet($data){
$this->formset = array();
foreach ($objects as $obj){
$prefix = 'edit_'.get_class($this->model).'_'.$obj->id.'_';
$d = array();
- foreach ($obj->getData() as $k=>$v)
- $d[$prefix.$k] = $v;
- foreach ($data as $k=>$v){
- if (strpos($k,$prefix)==0)
- $d[$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)
+ $d[$k] = $v;
+ }
+ }
+
$form = $this->_getForm($obj, $d,
array('exclude'=>array($this->getFkName(),$this->getFkLocal()))
);
+
+
$form->prefix = $prefix;
$form->fields = array_merge(array(
new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'is_remove')),
}
function save($parent_obj){
-
if ($this->parentModel->exists()){
$objects = IPF_ORM_Query::create()
->from(get_class($this->model))
foreach($this->formset as $form){
if ($form->isAdd)
continue;
+
@list($x1,$x2,$id,$x3) = @split('_',$form->prefix);
if ($id==$obj->id){
if ($form->cleaned_data[0]==true)
if($form->cleaned_data[$fname]=='')
unset($form->cleaned_data[$fname]);
}
- }
+ }
$obj->synchronizeWithArray($form->cleaned_data);
$obj->save();
}
$this->cleaned_data = array();
$this->errors = array();
$form_methods = get_class_methods($this);
+
foreach ($this->fields as $name=>$field) {
$value = $field->widget->valueFromFormData($this->addPrefix($name), &$this->data);
try {
if ((bool)$value) {
$extra_attrs['checked'] = 'checked';
}
+ $extra_attrs['value'] = '1';
return parent::render($name, '', $extra_attrs);
}
public function valueFromFormData($name, $data)
{
- if (!isset($data[$name])
- or false === $data[$name] or (string)$data[$name] === '0') {
+ if (!isset($data[$name]) or false === $data[$name] or (string)$data[$name] === '0' or (string)$data[$name] === 'off') {
return false;
}
return true;
$this->assignIdentifier((array) $value);
continue;
}
-
if ($deep && $this->getTable()->hasRelation($key)) {
$this->get($key)->synchronizeWithArray($value);
} else if ($this->getTable()->hasField($key)) {
$this->set($key, $value);
}
}
-
// eliminate relationships missing in the $array
foreach ($this->_references as $name => $obj) {
if ( ! isset($array[$name])) {
unset($this->$name);
}
}
-
if ($refresh) {
$this->refresh();
}