protected function _beforeSave() { parent::_beforeSave(); foreach ($this->getModel()->getExprColumns() as $name) { $expr = $this->getModel()->getExpr($name); if ($expr instanceof Kwf_Model_Select_Expr_Parent) { $ref = $this->getModel()->getReference($expr->getParent()); if ($ref === Kwf_Model_RowsSubModel_Interface::SUBMODEL_PARENT) { continue; } } $this->{$name} = $this->getModel()->getExprValue($this, $name); } foreach ($this->getModel()->getProxyContainerModels() as $model) { foreach ($model->getExistingRows() as $proxyRow) { if ($proxyRow->getProxiedRow() === $this) { foreach ($model->getExprColumns() as $name) { $expr = $model->getExpr($name); if ($expr instanceof Kwf_Model_Select_Expr_Parent) { $ref = $model->getReference($expr->getParent()); if ($ref === Kwf_Model_RowsSubModel_Interface::SUBMODEL_PARENT) { continue; } } $this->{$name} = $model->getExprValue($proxyRow, $name); } } } } }
protected function _toArrayWithoutPrimaryKeys() { // TODO: wird in service model momentan nicht korrekt aufgerufen // theoretisch müssten dort auch die primarys von den siblings entfernt werden // aber der service hat momentan eh keine siblings. // test case wäre: return parent::_toArrayWithoutPrimaryKeys(); }
public function __get($name) { if (preg_match('#^name_([a-z]{2})$#', $name, $m)) { $ret = $this->getModel()->getNameByLanguageAndId($m[1], $this->id); } else { $ret = parent::__get($name); } return $ret; }
protected function _beforeSave() { parent::_beforeSave(); foreach ($this->getModel()->getExprColumns() as $name) { $this->{$name} = $this->getModel()->getExprValue($this, $name); } foreach ($this->getModel()->getProxyContainerModels() as $model) { foreach ($model->getExprColumns() as $name) { foreach ($model->getExistingRows() as $proxyRow) { if ($proxyRow->getProxiedRow() === $this) { $this->{$name} = $model->getExprValue($proxyRow, $name); } } } } }
public function getSilblingRow() { $rows = parent::_getSiblingRows(); return $rows[$this->type]; }
protected function _beforeSaveSiblingMaster() { parent::_beforeSaveSiblingMaster(); $this->_siblingRow->{$this->_fieldName} = json_encode($this->_data); }
public function __construct($config) { $data['url'] = $config['url']; $encoding = false; if (substr($data['url'], 0, 7) == 'file://' || substr($data['url'], 0, 6) == 'php://') { $str = file_get_contents($data['url']); } else { $response = $config['model']->getHttpRequestor()->request($data['url']); if ($response->getStatusCode() != 200) { throw new Kwf_Exception("invalid status response from server: " . $response->getStatusCode() . " for '{$data['url']}'"); } $str = $response->getBody(); } if (!$str) { throw new Kwf_Exception("Can't load feed '{$data['url']}', response is empty"); } $originalContent = $str; $str = trim($str); if (preg_match('#<?xml[^>]* encoding=["\']([^"\']*)["\']#', $str, $m)) { $encoding = trim(strtolower($m[1])); if ($encoding != 'utf8' && $encoding != 'utf-8') { try { $str = iconv($encoding, 'utf-8', $str); $str = preg_replace('#(<?xml[^>]* encoding=["\'])([^"\']*)(["\'])#', '\\1utf-8\\3', $str); } catch (Exception $e) { } } } else { if (isset($response)) { $ct = $response->getContentType(); if ($ct) { if (preg_match('#charset=([^;]*)#i', strtolower($ct), $m)) { $encoding = trim($m[1]); if ($encoding != 'utf8' && $encoding != 'utf-8') { $str = iconv($encoding, 'utf-8', $str); } } } } } if (!$encoding) { try { $encoding = $config['model']->getDefaultEncoding(); $str = iconv($encoding, 'utf-8', $str); } catch (Exception $e) { } } $entityLoaderWasDisabled = libxml_disable_entity_loader(true); $this->_xml = simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING); if (!$this->_xml) { //try with another encoding $this->_xml = simplexml_load_string(iconv('iso-8859-1', 'utf-8', $str), 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING); if ($this->_xml) { $encoding = 'iso-8859-1'; } } if (!$this->_xml) { if (class_exists('tidy')) { //maximum length; simply cut off, tidy will repair it properly $maxLength = 5 * 1024 * 1024; if (strlen($str) > $maxLength) { $str = substr($str, 0, $maxLength); } $c = array('indent' => true, 'input-xml' => true, 'output-xml' => true, 'wrap' => '86', 'char-encoding' => 'utf8', 'newline' => 'LF'); $tidy = new tidy(); $tidy->parseString($str, $c, 'utf8'); $tidy->cleanRepair(); $str = $tidy->value; $str = preg_replace('#(<?xml[^>]* encoding=["\'])([^"\']*)(["\'])#', '\\1utf-8\\3', $str); $str = str_replace("", '', $str); $this->_xml = simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING); } } libxml_disable_entity_loader($entityLoaderWasDisabled); if (!$this->_xml) { throw new Kwf_Exception("Can't load feed: '{$data['url']}' " . $originalContent); } if ($this->_xml->channel) { $data['format'] = self::FORMAT_RSS; } else { if ($this->_xml->getName() == 'feed') { $data['format'] = self::FORMAT_ATOM; } else { throw new Kwf_Exception("Can't load feed '{$data['url']}', unknown format: " . $originalContent); } } $data['encoding'] = $encoding; $data['hub'] = null; if ($data['format'] == self::FORMAT_RSS) { $data['title'] = (string) $this->_xml->channel->title; $data['link'] = (string) $this->_xml->channel->link; $data['description'] = (string) $this->_xml->channel->description; //der hub ist im atom namespace in einem rss20 feed //also in diesen namespace wechseln foreach ($this->_xml->channel->children('http://www.w3.org/2005/Atom')->link as $link) { $link = $link->attributes(''); //die attribute sind aber wida im default namespace, also wida rauswechseln if ($link['rel'] == 'hub') { $data['hub'] = (string) $link['href']; break; } } } else { $data['title'] = (string) $this->_xml->title; $data['link'] = null; foreach ($this->_xml->link as $link) { if (!$link['href']) { continue; } if ($link['rel'] != 'self') { $data['link'] = (string) $link['href']; break; } } foreach ($this->_xml->link as $link) { if (!$link['href']) { continue; } if ($link['rel'] == 'hub') { $data['hub'] = (string) $link['href']; break; } } } $config['data'] = $data; Kwf_Benchmark::count('loaded feed'); parent::__construct($config); }
public function __construct(array $config) { $this->_parentRow = $config['parentRow']; parent::__construct($config); }