本文整理汇总了PHP中XMLElement::setattribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::setattribute方法的具体用法?PHP XMLElement::setattribute怎么用?PHP XMLElement::setattribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::setattribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSectionSchema
public function getSectionSchema(&$result, $section_id)
{
$entryManager = new EntryManager($this->_Parent);
$sm = new SectionManager($this->_Parent);
// retrieve this section
$section = $sm->fetch($section_id);
$result->setAttribute('id', $section_id);
$result->setAttribute('handle', $section->_data['handle']);
$entry_count = intval($this->_Parent->Database->fetchVar('count', 0, "SELECT count(*) AS `count` FROM `tbl_entries` WHERE `section_id` = '" . $section_id . "' "));
$result->setAttribute('total-entries', $entry_count);
// instantiate a dummy entry to instantiate fields and default values
$entry =& $entryManager->create();
$entry->set('section_id', $section_id);
$section_fields = $section->fetchFields();
// for each field in the section
foreach ($section_fields as $section_field) {
$field = $section_field->get();
$f = new XMLElement($field['element_name']);
$f->setAttribute('required', $field['required']);
foreach ($field as $key => $value) {
// Core attributes, these are common to all fields
if (in_array($key, array('id', 'type', 'required', 'label', 'location', 'sortorder'))) {
$f->setattribute($key, $value);
}
/*
Other properties are output as element nodes. Here we filter those we
definitely don't want. Fields can have any number of properties, so it
makes sense to filter out those we don't want rather than explicitly
choose the ones we do.
*/
if (!in_array($key, array('id', 'type', 'required', 'label', 'show_column', 'sortorder', 'element_name', 'parent_section', 'location', 'field_id', 'related_field_id', 'static_options', 'dynamic_options', 'pre_populate_source', 'limit', 'allow_author_change'))) {
if (strlen($value) > 0) {
$f->appendChild(new XMLElement(Lang::createHandle($key), $value));
}
}
}
// grab the HTML used in the Publish entry form
$html = new XMLElement('html');
$section_field->displayPublishPanel($html);
$dom = new DomDocument();
$dom->loadXML($html->generate());
$xpath = new DomXPath($dom);
$options = new XMLElement('options');
// find optgroup elements (primarily in Selectbox Link fields)
foreach ($xpath->query("//*[name()='optgroup']") as $optgroup) {
$optgroup_element = new XMLElement('optgroup');
$optgroup_element->setAttribute('label', $optgroup->getAttribute('label'));
$options_xpath = new DomXPath($optgroup);
// append child options of this group
foreach ($optgroup->getElementsByTagName('option') as $option) {
$this->__appendOption($option, $optgroup_element, $field);
}
$options->appendChild($optgroup_element);
}
// find options that aren't children of groups, and list items (primarily for Taglists)
foreach ($xpath->query("//*[name()='option' and not(parent::optgroup)] | //*[name()='li']") as $option) {
$this->__appendOption($option, $options, $field);
}
if ($options->getNumberOfChildren() > 0) {
$f->appendChild($options);
}
/*
When an input has a value and is a direct child of the label, we presume we may need
its value (e.g. a pre-populated Date, Order Entries etc.)
*/
$single_input_value = $xpath->query("//label/input[@value!='']")->item(0);
if ($single_input_value) {
$f->appendChild(new XMLElement('initial-value', $single_input_value->getAttribute('value')));
}
$result->appendChild($f);
}
return $result;
}
示例2: grab
public function grab(array &$param_pool = NULL)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
$result->setAttribute('type', 'section-schema');
// retrieve this section
$section_id = SectionManager::fetchIDFromHandle($this->dsParamSECTION);
$section = SectionManager::fetch($section_id);
$result->setAttribute('id', $section_id);
$result->setAttribute('handle', $section->get('handle'));
$entry_count = EntryManager::fetchCount($section_id);
$result->setAttribute('total-entries', $entry_count);
// instantiate a dummy entry to instantiate fields and default values
$entry = EntryManager::create();
$entry->set('section_id', $section_id);
$section_fields = $section->fetchFields();
// for each field in the section
foreach ($section_fields as $section_field) {
$field = $section_field->get();
// Skip fields that have not been selected:
if (!in_array($field['element_name'], $this->dsParamFIELDS)) {
continue;
}
$f = new XMLElement($field['element_name']);
$f->setAttribute('required', $field['required']);
foreach ($field as $key => $value) {
// Core attributes, these are common to all fields
if (in_array($key, array('id', 'type', 'required', 'label', 'location', 'show_column', 'sortorder'))) {
$f->setattribute(Lang::createHandle($key), General::sanitize($value));
}
/*
Other properties are output as element nodes. Here we filter those we
definitely don't want. Fields can have any number of properties, so it
makes sense to filter out those we don't want rather than explicitly
choose the ones we do.
*/
if (!in_array($key, array('id', 'type', 'required', 'label', 'show_column', 'sortorder', 'element_name', 'parent_section', 'location', 'field_id', 'related_field_id', 'static_options', 'dynamic_options', 'pre_populate_source', 'limit', 'allow_author_change'))) {
if (strlen($value) > 0) {
$f->appendChild(new XMLElement(Lang::createHandle($key), General::sanitize($value)));
}
}
}
// Allow a field to define its own schema XML:
if (method_exists($section_field, 'appendFieldSchema')) {
$section_field->appendFieldSchema($f);
$result->appendChild($f);
continue;
}
// check that we can safely inspect output of displayPublishPanel (some custom fields do not work)
if (in_array($field['type'], self::$_incompatible_publishpanel)) {
continue;
}
// grab the HTML used in the Publish entry form
$html = new XMLElement('html');
$section_field->displayPublishPanel($html);
$dom = new DomDocument();
$dom->loadXML($html->generate());
$xpath = new DomXPath($dom);
$options = new XMLElement('options');
// find optgroup elements (primarily in Selectbox Link fields)
foreach ($xpath->query("//*[name()='optgroup']") as $optgroup) {
$optgroup_element = new XMLElement('optgroup');
$optgroup_element->setAttribute('label', $optgroup->getAttribute('label'));
// append child options of this group
foreach ($optgroup->getElementsByTagName('option') as $option) {
$this->__appendOption($option, $optgroup_element, $field);
}
$options->appendChild($optgroup_element);
}
// find options that aren't children of groups, and list items (primarily for Taglists)
foreach ($xpath->query("//*[name()='option' and not(parent::optgroup)] | //*[name()='li']") as $option) {
$this->__appendOption($option, $options, $field);
}
if ($options->getNumberOfChildren() > 0) {
$f->appendChild($options);
}
/*
When an input has a value and is a direct child of the label, we presume we may need
its value (e.g. a pre-populated Date, Order Entries etc.)
*/
$single_input_value = $xpath->query("//label/input[@value!='']")->item(0);
if ($single_input_value) {
$f->appendChild(new XMLElement('initial-value', $single_input_value->getAttribute('value')));
}
$result->appendChild($f);
}
return $result;
}