本文整理汇总了PHP中RuleAction::find方法的典型用法代码示例。如果您正苦于以下问题:PHP RuleAction::find方法的具体用法?PHP RuleAction::find怎么用?PHP RuleAction::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RuleAction
的用法示例。
在下文中一共展示了RuleAction::find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportRulesToXML
/**
* Export rules in a xml format
*
* @param items array the input data to transform to xml
*
* @since version 0.85
*
* @return nothing, send attachment to browser
**/
static function exportRulesToXML($items = array())
{
if (!count($items)) {
return false;
}
$rulecollection = new self();
$rulecritera = new RuleCriteria();
$ruleaction = new RuleAction();
//create xml
$xmlE = new SimpleXMLElement('<rules/>');
//parse all rules
foreach ($items as $key => $ID) {
$rulecollection->getFromDB($ID);
if (!class_exists($rulecollection->fields['sub_type'])) {
continue;
}
$rule = new $rulecollection->fields['sub_type']();
unset($rulecollection->fields['id']);
unset($rulecollection->fields['date_mod']);
$name = Dropdown::getDropdownName("glpi_entities", $rulecollection->fields['entities_id']);
$rulecollection->fields['entities_id'] = $name;
//add root node
$xmlERule = $xmlE->addChild('rule');
//convert rule direct indexes in XML
foreach ($rulecollection->fields as $key => $val) {
$xmlERule->{$key} = $val;
}
//find criterias
$criterias = $rulecritera->find("`rules_id` = '{$ID}'");
foreach ($criterias as &$criteria) {
unset($criteria['id']);
unset($criteria['rules_id']);
$available_criteria = $rule->getCriterias();
$crit = $criteria['criteria'];
if (self::isCriteraADropdown($available_criteria, $criteria['condition'], $crit)) {
$criteria['pattern'] = Html::clean(Dropdown::getDropdownName($available_criteria[$crit]['table'], $criteria['pattern']));
}
//convert criterias in XML
$xmlECritiera = $xmlERule->addChild('rulecriteria');
foreach ($criteria as $key => $val) {
$xmlECritiera->{$key} = $val;
}
}
//find actions
$actions = $ruleaction->find("`rules_id` = '{$ID}'");
foreach ($actions as &$action) {
unset($action['id']);
unset($action['rules_id']);
//process FK (just in case of "assign" action)
if ($action['action_type'] == "assign" && strpos($action['field'], '_id') !== false && !($action['field'] == "entities_id" && $action['value'] == 0)) {
$field = $action['field'];
if ($action['field'][0] == "_") {
$field = substr($action['field'], 1);
}
$table = getTableNameForForeignKeyField($field);
$action['value'] = Html::clean(Dropdown::getDropdownName($table, $action['value']));
}
//convert actions in XML
$xmlEAction = $xmlERule->addChild('ruleaction');
foreach ($action as $key => $val) {
$xmlEAction->{$key} = $val;
}
}
}
//convert SimpleXMLElement to xml string
$xml = $xmlE->asXML();
//send attachment to browser
header('Content-type: application/xml');
header('Content-Disposition: attachment; filename="rules.xml"');
echo $xml;
//exit;
}