private static function getFieldValues($instance, $fields) { $values = array(); foreach ($fields as $field) { if (StringUtil::endsWith(strtolower($field->get('@type')), 'combo')) { $values[$field->get('@name') . '_value'] = $field->get('@selected', null); } else { $values[$field->get('@name')] = afEditView::getFieldValue($field, $instance); } } return $values; }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(3, new lime_output_color()); $doc = afConfigUtils::getDoc('networkmonitor_snmp', 'editSnmpPackage'); $view = afDomAccess::wrap($doc, 'view'); $fields = $view->wrapAll('fields/field'); $t->is(count($fields), 3); $t->is(afEditView::getParams($fields[1], 'validator/param'), array('class' => 'SnmpPackage', 'column' => 'name', 'unique_error' => 'This name is already used. Please choose another one!')); $validators = json_decode('{"edit[name]":{"immValidatorUnique":{"params":{"class":"SnmpPackage","column":"name","unique_error":"This name is already used. Please choose another one!"}}},"edit[template]":{"immValidatorRequired":[]}}', true); $t->is(afEditView::getValidators($fields), $validators);
private function getFieldValue($field, $object) { $value = afEditView::getFieldValue($field, $object); if (preg_match("/<img[^s]*src=\"([^\"]+)\"[^>]*>/i", $value, $match)) { $value = $this->root; if (substr($match[1], 0, 1) != "/") { $match[1] = "/" . $match[1]; } $value .= $match[1]; if (!file_exists($value)) { $value = ""; } else { $value = "afpdf_image:" . $value; } } else { $value = StringUtil::removeTags($value); } return $value; }