Application->getUnitOption($prefix, 'TableName');
return $temp ? $this->Application->GetTempName($table_name, 'prefix:'.$prefix) : $table_name;
}
function prepareMInputXML($records, $use_fields)
{
$xml = '';
foreach ($records as $record) {
$xml .= '';
foreach ($record as $field_name => $field_value) {
if (!in_array($field_name, $use_fields)) {
continue;
}
$xml .= ''.$field_value.'';
}
$xml .= '';
}
return $xml ? ''.$xml.'' : '';
}
function prepareErrorsXML(&$object, $fields_hash)
{
$xml = '';
foreach ($fields_hash as $field_name => $field_value) {
$object->SetField($field_name, $field_value);
if (!$object->ValidateField($field_name)) {
$xml .= ''.$object->GetErrorMsg($field_name, false).'';
}
}
return ''.$xml.'';
}
/**
* Validates MInput control fields
*
* @param kEvent $event
*/
function OnValidateMInputFields(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ($items_info) {
list ($id, $field_values) = each($items_info);
echo $this->prepareErrorsXML($object, $field_values);
}
$event->status = erSTOP;
}
function parseMInputXML($xml)
{
$xml_helper =& $this->Application->recallObject('kXMLHelper');
/* @var $xml_helper kXMLHelper */
$root_node =& $xml_helper->Parse($xml);
$root_node =& $root_node->FindChild('records');
if (!$root_node || !$root_node->firstChild) {
return false;
}
$records = Array ();
$current_node = $root_node->firstChild;
/* @var $current_node kXMLNode */
do {
$record = Array();
$sub_node =& $current_node->firstChild;
/* @var $current_node kXMLNode */
do {
$record[$sub_node->Attributes['NAME']] = $sub_node->Data;
}while ( ($sub_node =& $sub_node->NextSibling()) );
$records[] = $record;
} while (($current_node =& $current_node->NextSibling()));
return $records;
}
/**
* Loads selected values from sub_prefix to main item virtual field.
* Called from OnAfterItemLoad of main prefix.
*
* @param kEvent $event
* @param string $store_field main item's field name, to store values into
* @param string $sub_prefix prefix used to store info about selected items
* @param Array $use_fields fields, used in value string building
*/
function LoadValues(&$event, $store_field, $sub_prefix, $use_fields)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$foreign_key = $this->Application->getUnitOption($sub_prefix, 'ForeignKey');
$sql = 'SELECT *
FROM '.$this->getTable($sub_prefix, $object->IsTempTable()).'
WHERE '.$foreign_key.' = '.$object->GetID();
$selected_items = $this->Conn->Query($sql);
$object->SetDBField($store_field, $this->prepareMInputXML($selected_items, $use_fields));
}
}
?>