Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, Feb 5, 11:19 AM

in-portal

Index: branches/RC/core/units/general/helpers/controls/minput_helper.php
===================================================================
--- branches/RC/core/units/general/helpers/controls/minput_helper.php (nonexistent)
+++ branches/RC/core/units/general/helpers/controls/minput_helper.php (revision 10022)
@@ -0,0 +1,124 @@
+<?php
+
+ class MInputHelper extends kHelper {
+
+
+ /**
+ * Returns user education table name
+ *
+ * @param kDBItem $object
+ * @return string
+ */
+ function getTable($prefix, $temp=false)
+ {
+ $table_name = $this->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 .= '<record>';
+ foreach ($record as $field_name => $field_value) {
+ if (!in_array($field_name, $use_fields)) {
+ continue;
+ }
+ $xml .= '<field name="'.$field_name.'">'.$field_value.'</field>';
+ }
+ $xml .= '</record>';
+ }
+
+ return $xml ? '<records>'.$xml.'</records>' : '';
+ }
+
+ 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 .= '<field name="'.$field_name.'">'.$object->GetErrorMsg($field_name, false).'</field>';
+ }
+ }
+
+ return '<errors>'.$xml.'</errors>';
+ }
+
+ /**
+ * 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));
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/RC/core/units/general/helpers/controls/minput_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.8.1
\ No newline at end of property
Index: branches/RC/core/units/general/helpers/controls/edit_picker_helper.php
===================================================================
--- branches/RC/core/units/general/helpers/controls/edit_picker_helper.php (nonexistent)
+++ branches/RC/core/units/general/helpers/controls/edit_picker_helper.php (revision 10022)
@@ -0,0 +1,69 @@
+<?php
+
+ class EditPickerHelper extends kHelper {
+
+
+ function getTable($prefix, $temp=false)
+ {
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ return $temp ? $this->Application->GetTempName($table_name, 'prefix:'.$prefix) : $table_name;
+ }
+
+ /**
+ * Applies filter for multiple lists in inp_edit_picker control.
+ * Called from SetCustomQuery of prefix, that contains all available items.
+ *
+ * @param kEvent $event
+ * @param string $storage_field main item's field name, where values are located
+ */
+ function applyFilter(&$event, $storage_field)
+ {
+ if ($event->Special != 'selected' && $event->Special != 'available') {
+ return ;
+ }
+
+ $object =& $event->getObject();
+ /* @var $object kDBList */
+
+ $main_object =& $this->Application->recallObject($event->getEventParam('link_to_prefix'));
+ /* @var $main_object kDBItem */
+
+ $selected_items = $main_object->GetDBField($storage_field);
+ if ($selected_items) {
+ $filter_type = $event->Special == 'selected' ? 'IN' : 'NOT IN';
+ $selected_items = explode('|', substr($selected_items, 1, -1));
+ $filter_clause = $object->IDField.' '.$filter_type.' ('.implode(',', $selected_items).')';
+ }
+ else {
+ $filter_clause = ($event->Special == 'selected') ? 'FALSE' : 'TRUE';
+ }
+
+ $object->addFilter('edit_picker_filter', $filter_clause);
+ }
+
+ /**
+ * 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 $source_field prefix and it's field used to store info about selected items (format: prefix.field)
+ */
+ function LoadValues(&$event, $store_field, $source_field)
+ {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ list ($sub_prefix, $sub_prefix_field) = explode('.', $source_field);
+ $foreign_key = $this->Application->getUnitOption($sub_prefix, 'ForeignKey');
+
+ $sql = 'SELECT '.$sub_prefix_field.'
+ FROM '.$this->getTable($sub_prefix, $object->IsTempTable()).'
+ WHERE '.$foreign_key.' = '.$object->GetID();
+ $selected_items = array_unique($this->Conn->GetCol($sql));
+
+ $object->SetDBField($store_field, $selected_items ? '|'.implode('|', $selected_items).'|' : '');
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/RC/core/units/general/helpers/controls/edit_picker_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.8.1
\ No newline at end of property
Index: branches/RC/core/units/general/helpers/controls/controls_config.php
===================================================================
--- branches/RC/core/units/general/helpers/controls/controls_config.php (nonexistent)
+++ branches/RC/core/units/general/helpers/controls/controls_config.php (revision 10022)
@@ -0,0 +1,11 @@
+<?php
+
+ $config = Array(
+ 'Prefix' => 'control-helpers',
+ 'EventHandlerClass' => Array('class' => 'kEventHandler', 'file' => '', 'build_event' => 'OnBuild'),
+
+ 'RegisterClasses' => Array(
+ Array('pseudo'=>'MInputHelper','class'=>'MInputHelper','file'=>'minput_helper.php','build_event'=>'','require_classes'=>'kHelper'),
+ Array('pseudo' => 'EditPickerHelper', 'class' => 'EditPickerHelper', 'file' => 'edit_picker_helper.php', 'build_event' => '', 'require_classes' => Array('kHelper')),
+ ),
+ );
\ No newline at end of file
Property changes on: branches/RC/core/units/general/helpers/controls/controls_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.8.1
\ No newline at end of property

Event Timeline