本文整理汇总了PHP中object::attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP object::attributes方法的具体用法?PHP object::attributes怎么用?PHP object::attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object
的用法示例。
在下文中一共展示了object::attributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchElement
/**
* Renders the element
*
* @access public
* @param string $name name of the element combined with $control_name like "$control_name[$name]"
* @param mixed $value pre-selected value of the element
* @param object $node reference to the XML node that defined this element
* @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
* @return string HTML output that renders the element
*/
function fetchElement($name, $value, &$node, $control_name)
{
$htmlId = $node->attributes('id') ? $node->attributes('id') : '';
$disabled = $value ? 'disabled="disabled"' : '';
$pManager =& getPluginManager();
$pManager->loadPlugins('acl');
$aclData = $pManager->invokeMethod('acl', 'getACL', null, null);
$aclHandlersList = array();
$aclHandlersList[] = JHTML::_('select.option', 0, JText::_('Please Select'));
$jsOutput = JHTML::_('jwf.indentedLine', 'var aclLists = {', 3);
foreach ($pManager->settings['acl'] as $p) {
if ($aclData[$p->id] == null) {
continue;
}
$jsOutput .= JHTML::_('jwf.indentedLine', "'{$p->id}' : {", 4);
foreach ($aclData[$p->id] as $groupID => $groupTitle) {
$jsOutput .= JHTML::_('jwf.indentedLine', "{$groupID} : '{$groupTitle}',", 5);
}
$jsOutput = JHTML::_('jwf.trimComma', $jsOutput);
$jsOutput .= JHTML::_('jwf.indentedLine', '},', 4);
$aclHandlersList[] = JHTML::_('select.option', $p->id, $p->name);
}
$jsOutput = JHTML::_('jwf.trimComma', $jsOutput);
$jsOutput .= JHTML::_('jwf.indentedLine', '};', 3);
$output = JHTML::_('jwf.startJSBlock', 2);
$output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.acl = '{$value}';", 3);
$output .= $jsOutput;
$output .= JHTML::_('jwf.endJSBlock', 2);
$output .= JHTML::_('select.genericlist', $aclHandlersList, "{$control_name}[{$name}]", "{$disabled} class='inputbox' size='1' onchange='selectACLSystemFromList(this)'", 'value', 'text', $value, $htmlId);
return $output;
}
示例2: fetchElement
/**
* Renders the element
*
* @access public
* @param string $name name of the element combined with $control_name like "$control_name[$name]"
* @param mixed $value pre-selected value of the element
* @param object $node reference to the XML node that defined this element
* @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
* @return string HTML output that renders the element
*/
function fetchElement($name, $value, &$node, $control_name)
{
$htmlId = $node->attributes('id') ? 'id="' . $node->attributes('id') . '"' : '';
$pManager =& getPluginManager();
$pManager->loadPlugins('component');
$output = JHTML::_('jwf.startJSBlock', 2);
$output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.category = '{$value}';", 3);
$output .= JHTML::_('jwf.indentedLine', 'var categoriesData = {', 3);
$categoryLists = $pManager->invokeMethod('component', 'getCategories', null, null);
foreach ($categoryLists as $contentType => $data) {
if ($data) {
$output .= JHTML::_('jwf.indentedLine', "{$contentType}:{", 4);
foreach ($data as $id => $obj) {
$output .= JHTML::_('jwf.indentedLine', $obj->getId() . ' : \'' . $obj->getTitle() . '\',', 5);
if (count($obj->getChildren())) {
$output .= $this->fetchChildren($obj, 1);
}
}
if (count($data)) {
$output = JHTML::_('jwf.trimComma', $output);
}
$output .= JHTML::_('jwf.indentedLine', "},", 4);
}
}
$output = JHTML::_('jwf.trimComma', $output);
$output .= JHTML::_('jwf.indentedLine', '};', 3);
$output .= JHTML::_('jwf.endJSBlock', 2);
$output .= JHTML::_('jwf.indentedLine', "<select multiple='multiple' name='{$control_name}[{$name}][]' {$htmlId} size='5'></select>", 2);
return $output;
}
示例3: fetchElement
/**
* Fetch a calendar element
*
* @param string $name Field name
* @param string $value The date value
* @param object $node JSimpleXMLElement node object containing the settings for the element
* @param string $control_name Control name
*
* @return string HTML string for a calendar
*
* @deprecated 12.1
* @see JFormFieldCalendar
* @since 11.1
*/
public function fetchElement($name, $value, &$node, $control_name)
{
// Deprecation warning.
JLog::add('JElementCalendar::fetchElement() is deprecated.', JLog::WARNING, 'deprecated');
// Load the calendar behavior
JHtml::_('behavior.calendar');
$format = $node->attributes('format') ? $node->attributes('format') : '%Y-%m-%d';
$class = $node->attributes('class') ? $node->attributes('class') : 'inputbox';
$id = $control_name . $name;
$name = $control_name . '[' . $name . ']';
return JHtml::_('calendar', $value, $name, $id, $format, array('class' => $class));
}
示例4: test
/**
* Method to test if two values are equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @param object $field A reference to the form field.
* @param mixed $values The values to test for validiaty.
* @return mixed JException on invalid rule, true if the value is valid, false otherwise.
*/
public function test(&$field, &$values)
{
$return = false;
$field1 = (string) $field->attributes()->name;
$field2 = (string) $field->attributes()->field;
// Check the rule.
if (!$field2) {
return new JException('Invalid Form Rule :: ' . get_class($this));
}
// Test the two values against each other.
if ($values[$field1] == $values[$field2]) {
$return = true;
}
return $return;
}
示例5: fetchElement
/**
* Renders the element
*
* @access public
* @param string $name name of the element combined with $control_name like "$control_name[$name]"
* @param mixed $value pre-selected value of the element
* @param object $node reference to the XML node that defined this element
* @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
* @return string HTML output that renders the element
*/
function fetchElement($name, $value, &$node, $control_name)
{
$htmlId = $node->attributes('id') ? $node->attributes('id') : '';
$pManager =& getPluginManager();
$pManager->loadPlugins('component');
$output = JHTML::_('jwf.startJSBlock', 2);
$output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.component = '{$value}';", 3);
$output .= JHTML::_('jwf.endJSBlock', 2);
$contentTypesList = array();
foreach ($pManager->settings['component'] as $p) {
$contentTypesList[] = JHTML::_('select.option', $p->id, $p->name);
}
$output .= JHTML::_('select.genericlist', $contentTypesList, $control_name . '[' . $name . ']', 'onchange="updateCategoryList(this)" class="inputbox" size="1"', 'value', 'text', $value, $htmlId);
return $output;
}
示例6: test
/**
* Method to test if two values are equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @param object $field A reference to the form field.
* @param mixed $values The values to test for validiaty.
* @return mixed JException on invalid rule, true if the value is valid, false otherwise.
* @since 1.6
*/
public function test(&$field, &$values)
{
$name = (string) $field->attributes()->name;
// TODO: probably should check to see if the action is even available for this field.
// $values[$name];
return true;
}
示例7: fetchElement
/**
* Fetch the HTML code for the parameter element.
*
* @param string $name The field name.
* @param mixed $value The value of the field.
* @param object $node The current XML node.
* @param string $control_name The name of the HTML control.
*
* @since 11.1
*
* @deprecated 12.1
*/
public function fetchElement($name, $value, &$node, $control_name)
{
$ctrl = $control_name . '[' . $name . ']';
$attribs = ' ';
if ($v = $node->attributes('size')) {
$attribs .= 'size="' . $v . '"';
}
if ($v = $node->attributes('class')) {
$attribs .= 'class="' . $v . '"';
} else {
$attribs .= 'class="inputbox"';
}
if ($m = $node->attributes('multiple')) {
$attribs .= 'multiple="multiple"';
$ctrl .= '[]';
}
return JHtml::_('select.genericlist', $this->_getOptions($node), $ctrl, array('id' => $control_name . $name, 'list.attr' => $attribs, 'list.select' => $value));
}
示例8: test
/**
* Method to test if an e-mail address is unique.
*
* @param object $field A reference to the form field.
* @param mixed $values The values to test for validiaty.
* @return mixed JException on invalid rule, true if the value is valid, false otherwise.
* @since 1.6
*/
public function test(&$field, &$values)
{
$return = false;
$name = (string) $field->attributes()->name;
$check = (string) $field->attributes()->unique == 'true' || (string) $field->attributes()->unique == 'unique';
// If the field is empty and not required, the field is valid.
if ((string) $field->attributes()->required != 'true') {
// Get the data for the field.
$value = array_key_exists($name, $values) ? $values[$name] : null;
// If the data is empty, return valid.
if ($value == null) {
return true;
}
}
// Check if we should test for uniqueness.
if ($check) {
$key = (string) $field->attributes()->field;
$value = isset($values[$key]) ? $values[$key] : 0;
// Check the rule.
if (!$key) {
return new JException('Invalid Form Rule :: ' . get_class($this));
}
// Check if the username is unique.
$db =& JFactory::getDbo();
$db->setQuery('SELECT count(*) FROM `#__users`' . ' WHERE `email` = ' . $db->Quote($values[$name]) . ' AND ' . $db->nameQuote($key) . ' != ' . $db->Quote($value));
$duplicate = (bool) $db->loadResult();
// Check for a database error.
if ($db->getErrorNum()) {
return new JException('Database Error :: ' . $db->getErrorMsg());
}
// Test the value against the regular expression.
if (parent::test($field, $values) && !$duplicate) {
$return = true;
}
} else {
// Test the value against the regular expression.
if (parent::test($field, $values)) {
$return = true;
}
}
return $return;
}
示例9: test
/**
* Method to test if a username is unique.
*
* @param object $field A reference to the form field.
* @param mixed $values The values to test for validiaty.
* @return mixed JException on invalid rule, true if the value is valid, false otherwise.
*/
public function test(&$field, &$values)
{
$return = false;
$name = (string) $field->attributes()->name;
$key = (string) $field->attributes()->field;
$value = isset($values[$key]) ? $values[$key] : 0;
// Check the rule.
if (!$key) {
return new JException('Invalid Form Rule :: ' . get_class($this));
}
// Check if the username is unique.
$db =& JFactory::getDbo();
$db->setQuery('SELECT count(*) FROM `#__users`' . ' WHERE `username` = ' . $db->Quote($values[$name]) . ' AND ' . $db->nameQuote($key) . ' != ' . $db->Quote($value));
$duplicate = (bool) $db->loadResult();
// Check for a database error.
if ($db->getErrorNum()) {
return new JException('Database Error :: ' . $db->getErrorMsg());
}
if (!$duplicate) {
$return = true;
}
return $return;
}
示例10: getAttribute
/**
* Method to get an attribute of the field
*
* @param string $name Name of the attribute to get
* @param mixed $default Optional value to return if attribute not found
* @return mixed Value of the attribute / default
*/
public function getAttribute($name, $default = null)
{
if ($this->element instanceof SimpleXMLElement) {
$attributes = $this->element->attributes();
// Ensure that the attribute exists
if (property_exists($attributes, $name)) {
$value = $attributes->{$name};
if ($value !== null) {
return (string) $value;
}
}
}
return $default;
}
示例11: test
/**
* Method to test the value.
*
* @param object $field A reference to the form field.
* @param mixed $values The values to test for validiaty.
* @return boolean True if the value is valid, false otherwise.
* @since 1.6
* @throws JException on invalid rule.
*/
public function test(&$field, &$values)
{
$return = false;
$name = $field->attributes('name');
// Check for a valid regex.
if (empty($this->_regex)) {
throw new JException('Invalid Form Rule :: ' . get_class($this));
}
// Add unicode property support if available.
if (JCOMPAT_UNICODE_PROPERTIES) {
$this->_modifiers = strpos($this->_modifiers, 'u') ? $this->_modifiers : $this->_modifiers . 'u';
}
// Test the value against the regular expression.
if (preg_match('#' . $this->_regex . '#' . $this->_modifiers, $values[$name])) {
$return = true;
}
return $return;
}
示例12: get_name_date
/**
* Функция получения названия и сроков проведения кампании
*
* @return array $params - параметры кампании: 'name' - название,
* 'start_date' - UNIXTIMESTAMP дата начала кампании
* 'end_date' - UNIXTIMESTAMP дата завершения кампании
*/
public function get_name_date()
{
$result = array();
if (!isset($this->campaign->attributes()->name)) {
$result['name'] = NULL;
} else {
$result['name'] = (string) $this->campaign->attributes()->name;
}
/*if (!isset($this->campaign->attributes()->start_date)) {
$result['start_date'] = NULL;
} else {
$result['start_date'] = (string)$this->campaign->attributes()->start_date;
}
if (!isset($this->campaign->attributes()->end_date)) {
$result['end_date'] = NULL;
} else {
$result['end_date'] = (string)$this->campaign->attributes()->end_date;
}*/
return $result;
}
示例13: _isValid
/**
* Method to test if a value is valid for a field.
*
* @param object $field The field to validate.
* @param array $values The values to validate.
* @return mixed Boolean on success, JException on error.
* @since 1.6
*/
protected function _isValid(&$field, $values)
{
$result = true;
// Get the validator type.
if ($type = $field->attributes('validate')) {
// Get the validator class.
$class = 'JFormRule' . $type;
if (!class_exists($class)) {
jimport('joomla.filesystem.path');
// Attempt to load the rule file.
if ($file = JPath::find(EFormValidator::addRulePath(), $type . '.php')) {
require_once $file;
}
if (!class_exists($class)) {
return new JException(JText::sprintf('Libraries_Form_Validator_Rule_Not_Found', $type), 0, E_ERROR);
}
}
// Run the validator.
$rule = new $class();
$result = $rule->test($field, $values);
}
return $result;
}
示例14: _typecastXmlValue
/**
* Type case XML values based on attributes
*
* This method typecasts the xml values based on the
* attributes of the SimpleXMLElement Object passed
* to the method.
*
* @param object $valueObj SimpleXMLElement
* @return mixed value for placing into array
*/
private static function _typecastXmlValue($valueObj)
{
// get the element attributes
$attribs = $valueObj->attributes();
// the element is null, so jump out here
if (isset($attribs->nil) && $attribs->nil || isset($attribs->null) && $attribs->null || (string) $valueObj == 'null') {
return null;
}
// switch on the type attribute
// switch works even if $attribs->type isn't set
$type = isset($attribs->coerced_type) ? $attribs->coerced_type : $attribs->type;
switch ($type) {
case 'datetime':
return self::_timestampToUTC((string) $valueObj);
break;
case 'integer':
return (int) $valueObj;
break;
case 'boolean':
$value = (string) $valueObj;
// look for a number inside the string
if (is_numeric($value)) {
return (bool) $value;
}
return $value == 'true';
break;
case 'array':
return array();
default:
return (string) $valueObj;
}
}
示例15: _toArray
/**
* Recursive method to toArray
*
* @param object $xml SimpleXMLElement object
* @param array $parentData Parent array with data
* @param string $ns Namespace of current child
* @param array $namespaces List of namespaces in XML
* @return void
*/
protected static function _toArray($xml, &$parentData, $ns, $namespaces)
{
$data = array();
foreach ($namespaces as $namespace) {
foreach ($xml->attributes($namespace, true) as $key => $value) {
if (!empty($namespace)) {
$key = $namespace . ':' . $key;
}
$data['@' . $key] = (string) $value;
}
foreach ($xml->children($namespace, true) as $child) {
self::_toArray($child, $data, $namespace, $namespaces);
}
}
$asString = trim((string) $xml);
if (empty($data)) {
$data = $asString;
} elseif (!empty($asString)) {
$data['@'] = $asString;
}
if (!empty($ns)) {
$ns .= ':';
}
$name = $ns . $xml->getName();
if (isset($parentData[$name])) {
if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
$parentData[$name] = array($parentData[$name]);
}
$parentData[$name][] = $data;
} else {
$parentData[$name] = $data;
}
}