/** * Bind the model to the widget * * @param One_Model $model */ public function bindModel($model) { $value = $this->requestValue(); // bad name if (is_null($value)) { $value = array(); } // if == NULL, set to 0, because NULL won't be picked up by $model->__modified $attributeName = $this->_name; // When the attributeName starts with 'r__', we're not saving an attribute but a relation if (preg_match('/^r__(.*)_(((?!._).)*)$/iU', $attributeName, $tmp)) { $relName = $tmp[1]; $relRole = $tmp[2]; $relValue = $value; $model->setRelated($relRole, $relValue); } else { $model->{$attributeName} = $value; } }
/** * Bind the model to the widget * * @param One_Model $model */ public function bindModel($model) { $value = $this->requestValue(); // bad name preg_match_all('/([^:]+):([^,]+),?/', $value, $matches); $parts = explode(':', $this->getCfg('role'), 2); $targetAttr = $this->getCfg('targetAttribute'); $tScheme = One_Repository::getScheme($model->getScheme()->getLink($parts[1])->getTarget()); $tIdAttr = $tScheme->getIdentityAttribute()->getName(); $value = array(); if (0 < count($matches[0])) { foreach ($matches[0] as $key => $tmp) { $usedKey = $matches[1][$key]; $usedValue = $matches[2][$key]; if (null === One_Repository::selectOne($tScheme->getName(), $usedKey)) { $tModel = One::make($tScheme->getName()); $tModel->{$targetAttr} = $usedValue; $tModel->insert(); $usedKey = $tModel->{$tIdAttr}; } $value[$usedKey] = $usedKey; } } if (is_null($value)) { $value = array(); } // if == NULL, set to 0, because NULL won't be picked up by $model->__modified $attributeName = $this->_name; // When the attributeName starts with 'r__', we're not saving an attribute but a relation if (preg_match('/^r__(.*)_(((?!._).)*)$/iU', $attributeName, $tmp)) { $relName = $tmp[1]; $relRole = $tmp[2]; $relValue = $value; $model->setRelated($relRole, $relValue); } else { $model->{$attributeName} = $value; } }
/** * Bind the model to the widget * * @param One_Model $model */ public function bindModel($model) { $value = $this->requestValue(); // bad name $attributeName = $this->_name; // When the attributeName starts with 'r__', we're not saving an attribute but a relation if (preg_match('/^r__(.*)_(((?!._).)*)$/iU', $attributeName, $tmp)) { $relName = $tmp[1]; $relRole = $tmp[2]; $relValue = $value; $model->setRelated($relRole, $relValue); } else { $model->{$attributeName} = $value; } }