Framework  3.9
DataImportColumn Class Reference
+ Inheritance diagram for DataImportColumn:
+ Collaboration diagram for DataImportColumn:

Public Member Functions

 __construct ($field, $position, $label="", $options, $importer, $update_empty=true)
 Creates a data import column definition. More...
 
 formatOptionPreview ($obj, $old)
 For fields whose value is derived from a provided options array, format the display of the column in the preview table. More...
 
 startFormatPreview ($obj, $old, $field)
 If the value has changed, show the new value in bold. More...
 
 getWarning ($obj)
 
 endFormatPreview ($old, $field)
 If the value has changed, show the old value in the table preview. More...
 
 isChanged ($old, $field)
 Determine if the value has changed. More...
 
 formatPreview ($obj, $old)
 Default preview table formatter. More...
 
 importOption ($obj, $value)
 If no customized callback function for setting the columns value on import is provided for a column with options, use this import logic. More...
 
 formatOptions ()
 Called by input table - show the set of options that represent valid input for the column. More...
 
 import ($obj, $value)
 Default importer for columns. More...
 
- Public Member Functions inherited from DataItem
 DataItem ()
 Constructor. More...
 
 __sleep ()
 
 fireEvent ($event)
 Fires the specified event to all registered handlers. More...
 
 joinTransaction ($tx)
 Join the DataItem to the specified DataTransaction. More...
 
 getTransaction ()
 Retrieves the current DataTransaction. More...
 
 cast ($class)
 Cast this object to another class. More...
 
 disablePrimaryKey ()
 
 enablePrimaryKey ()
 
 getHiddenFields ()
 Retrieves the list of hidden fields. More...
 
 populate ($line, $alias=false)
 Populates the object using the supplied associative array (field -> value). More...
 
 getFields ()
 Retrieve the field type list for this object. More...
 
 overrideFieldType ($field, $type)
 Override the type for the specified field. More...
 
 getFieldList ($alias="")
 Returned a comma-separated list of the fields for this object (applying the assigned filter if there is one). More...
 
 getFieldArray ()
 Return an array of field names for this object filtered by any active filter. More...
 
 hasField ($field)
 Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter. More...
 
 hasRelation ($relation)
 Returns true if this DataItem contains a relation with the specified name. More...
 
 getPrimaryKey ()
 Retrieves the primary key field name. More...
 
 getPrimaryKeyList ()
 Retrieves a list of all the primary keys used for an object as an array. More...
 
 get ($field)
 Retrieve the value for the specified field. More...
 
 set ($field, $value)
 Set the value of the specified field. More...
 
 getType ($field)
 Retrieves the data type of the specified field. More...
 
 getFilter ()
 Returns the filter set on this object. More...
 
 setFilter ($filter)
 Sets the filter on this object. More...
 
 getFieldAliases ()
 Retrieve the list of field aliases. More...
 
 getFieldAnnotations ()
 Retrieve the list of field annotations. More...
 
 pack ()
 The pack() method is called prior to persisting a DataItem to storage. More...
 
 unpack ()
 The unpack() method is called after populating a DataItem. More...
 
 load ($id)
 Load the object with the specified primary key. More...
 
 old ()
 Retrieves the currently stored state of the DataItem from the database and returns it as a new object. More...
 
 loadComposite ()
 Creates an outer CompositeDataItem from its base component. More...
 
 save ()
 Store the object in the database. More...
 
 select ()
 Select the object from the database, based on the value of the primary key field. More...
 
 exists ($constraint="")
 Check whether the object exists in the database. More...
 
 update ()
 Update the row in the database that corresponds to this object. More...
 
 updateExplicit ($updates, $params=null)
 Executes an explicit update command against the database. More...
 
 insert ()
 Insert a new row in the database to store this object. More...
 
 delete ($constraint="")
 Delete the row in the database that corresponds to this object. More...
 
 deleteAll ()
 Delete all the rows in the database that correspond to this class. More...
 
 tableExists ()
 Check if the table for this class exists in the database. More...
 
 duplicate ()
 Persists a duplicate of the DataItem to the database under a new primary key. More...
 
 distinctValues ($field, $sorted=false, $constraint="")
 Retrieves the distinct values in the database for the specified field across the specified set of records. More...
 
 fromGET ()
 Automatically populate the object based on parameters in the $_GET collection. More...
 
 fromPOST ()
 Automatically populate the object based on parameters in the $_POST collection. More...
 
 fromREQUEST ()
 Automatically populate the object based on parameters in either the $_GET or $_POST collection, depending on the method used to access the page. More...
 
 fromDataSet ($params)
 Automatically populate the object based on a custom set of parameters (such as a filtered $_POST collection) More...
 
 compare ($to)
 Compare this object to another object. More...
 
 copy ($from)
 Copies values from another object, field by field. More...
 
 cloneFrom ($from)
 Copies values from another object, field by field, excluding the primary key. More...
 
 cacheLookup ($id)
 Populate the object from the local cache if the object is marked as "cacheLocal". More...
 
 getRelated ($class, $field="")
 Returns a single item related by the specified foreign key. More...
 
 getRelatedList ($class, $field="", $orderBy="")
 Returns a list of items that are related to this item. More...
 
 crossReference ($class, $xref, $orderBy="", $pkField="", $xrefField="")
 Returns a list of items related to this item via a cross-reference table. More...
 
 queryValue ($func)
 Query the database to calculate an aggregate value. More...
 
 toXML ($indent=0, $path=null)
 Generates an XML representation of the object. More...
 
 fromXML ($node)
 Populates the object from the specified XML node. More...
 
 toJSON ()
 
 format ($template="", $separator=", ")
 Substitute values for field names in a string, with the fields formatted using their type's default format or according to the formatting template sting passed in. More...
 
 formatField ($template)
 
 formatThroughRelation ($template, $separator=", ")
 
 prettifyFieldName ($field)
 
 relateTo ($target, $field="")
 Link this object to the specified target by setting corresponding field to the value of the target's primary key. More...
 
- Public Member Functions inherited from AbstractDataItem
 decorate ($name, $value)
 Adds a decoration to the DataItem. More...
 
 getDecoration ($name)
 Retrieve the value of a decoration on the current DataItem. More...
 
 setOption ($opt)
 Set a behavior option flag. More...
 
 clearOptions ($opt)
 Clear the specified behavior option flag. More...
 
 getConnection ()
 Retrieves a connection to the database. More...
 
 getIdentityConstraint ()
 Subclasses can override this function to provide additional identity constraints to be used when querying or updating. More...
 
 populate ($line)
 Populates the object using the supplied associative array (field -> value). More...
 
 getPrimaryKeyValue ()
 Retrieves the primary key value. More...
 
 quoteFieldValue ($field, $type=null)
 Returns the properly quoted value of the specified field. More...
 
 quoteValue ($val, $type)
 
 formatFieldValue ($field, $template="")
 
 formatFieldForXML ($field)
 Format field for XML output. More...
 
 reformatToSQLDate ($date)
 Reformats the specified date to be in a format used by the database. More...
 
 reformatFromSQLDate ($date)
 
 fromJSON ($json)
 Populate from the supplied JSON object. More...
 
 prettifyClassName ($plural=false)
 

Public Attributes

 $fields
 
 $options = array()
 optional - from related table or DataItem array whose value must match imported value More...
 
 $importer
 optional callback to handle customized login on import of a column More...
 
 $template
 formatting template for preview display of the data item field More...
 
 $preview_template
 formatting template for preview display of the entire cell More...
 
 $warnings = array()
 store warnings indexed by the object row number pseudo field More...
 
- Public Attributes inherited from DataItem
 $_tx = null
 
 $_pkDisabled = false
 
- Public Attributes inherited from AbstractDataItem
 $filter
 
 $_options = 0
 
 $_tx = null
 Tracks the current database transaction for each DataItem. More...
 
 $_decorations = null
 

Additional Inherited Members

- Static Public Member Functions inherited from DataItem
static registerEventHandler ($class, $event, $handler)
 Register an event handler for a specific event and DataItem class. More...
 
- Static Public Attributes inherited from DataItem
static $_eventMap = array()
 
static $dataTypeRendererMap
 

Detailed Description

Definition at line 871 of file data_import_manager.inc.

Constructor & Destructor Documentation

◆ __construct()

DataImportColumn::__construct (   $field,
  $position,
  $label = "",
  $options,
  $importer,
  $update_empty = true 
)

Creates a data import column definition.

Parameters
string$field- column name for table imported to
number$position- column order/position in import
string$label- label for the column
array$options- optional set of valid options for the imported data, if lookup is used
callback$importer- optional for handling customizezd data import logic for the column
booleanupdate_empty - whether to save updated values that are empty, overriding existing nonempty values

Definition at line 896 of file data_import_manager.inc.

897  {
898  $this->primary_key = "field";
899  $this->table = "import_column";
900 
901  $this->field = $field;
902  $this->label = $label;
903  $this->position = $position;
904  $this->importer = $importer;
905  $this->options = $options;
906  $this->update_empty = $update_empty;
907 
908  if($this->options && !$importer)
909  {
910  $this->importer = array($this, importOption);
911  }
912 
913  if($this->options)
914  {
915  $this->preview_template = array($this, formatOptionPreview);
916  }
917  else
918  {
919  $this->preview_template = array($this, formatPreview);
920  }
921 
922  $this->template = "{{$field}}";
923  }
formatOptionPreview($obj, $old)
For fields whose value is derived from a provided options array, format the display of the column in ...
formatPreview($obj, $old)
Default preview table formatter.
$importer
optional callback to handle customized login on import of a column
importOption($obj, $value)
If no customized callback function for setting the columns value on import is provided for a column w...
$options
optional - from related table or DataItem array whose value must match imported value

Member Function Documentation

◆ endFormatPreview()

DataImportColumn::endFormatPreview (   $old,
  $field 
)

If the value has changed, show the old value in the table preview.

Parameters
obj$old
string$field
Returns
string

Definition at line 995 of file data_import_manager.inc.

996  {
997  if($this->isChanged($old, $field))
998  {
999  $value .= "</b></br><i>" . $old->format($this->template) . "</i>";
1000  }
1001 
1002  return $value;
1003  }
isChanged($old, $field)
Determine if the value has changed.

◆ formatOptionPreview()

DataImportColumn::formatOptionPreview (   $obj,
  $old 
)

For fields whose value is derived from a provided options array, format the display of the column in the preview table.

Parameters
obj$obj
obj$old
Returns
string

Definition at line 933 of file data_import_manager.inc.

934  {
935  $field = $this->field;
936 
937  $value = $this->startFormatPreview($obj, $old, $field);
938 
939  if(!$value)
940  {
941  $value .= $this->options[$obj->$field] . " (" . $obj->format($this->template) . ")";
942  }
943 
944  $value .= $this->endFormatPreview($old, $field);
945 
946  return $value;
947  }
endFormatPreview($old, $field)
If the value has changed, show the old value in the table preview.
startFormatPreview($obj, $old, $field)
If the value has changed, show the new value in bold.

◆ formatOptions()

DataImportColumn::formatOptions ( )

Called by input table - show the set of options that represent valid input for the column.

Definition at line 1078 of file data_import_manager.inc.

1079  {
1080  if(!count($this->options))
1081  {
1082  return "N/A";
1083  }
1084 
1085  foreach($this->options as $key => $value)
1086  {
1087  $out[] = $value;
1088  }
1089  $out = implode("<br>", $out);
1090 
1091  return "<div class='scrollbox' style='height: 200px; overflow: scroll; border: none'>$out</div>";
1092  }

◆ formatPreview()

DataImportColumn::formatPreview (   $obj,
  $old 
)

Default preview table formatter.

Parameters
obj$obj
obj$old
Returns
string

Definition at line 1035 of file data_import_manager.inc.

1036  {
1037  $field = $this->field;
1038 
1039  $value = $this->startFormatPreview($obj, $old, $field);
1040 
1041  $value .= $obj->format($this->template);
1042 
1043  $value .= $this->endFormatPreview($old, $field);
1044 
1045  return $value;
1046  }

◆ getWarning()

DataImportColumn::getWarning (   $obj)

Definition at line 977 of file data_import_manager.inc.

978  {
979  if(array_key_exists($obj->row_number, $this->warnings))
980  {
981  return $this->warnings[$obj->row_number];
982  }
983 
984  return "";
985  }

◆ import()

DataImportColumn::import (   $obj,
  $value 
)

Default importer for columns.

Parameters
obj$obj
string$value

Definition at line 1100 of file data_import_manager.inc.

1101  {
1102  $field = $this->field;
1103  $obj->$field = $value;
1104  }

◆ importOption()

DataImportColumn::importOption (   $obj,
  $value 
)

If no customized callback function for setting the columns value on import is provided for a column with options, use this import logic.

Parameters
obj$obj
string$value

Definition at line 1056 of file data_import_manager.inc.

1057  {
1059  if(!count($options)) return;
1060  $label = $this->label;
1061 
1062  $options = array_flip($this->options);
1063 
1064  if(array_key_exists($value, $options))
1065  {
1066  $obj->$field = $options[$value];
1067  }
1068  else
1069  {
1070  $this->warning[$obj->row_number] = "{$label} $value not found";
1071  }
1072  }

◆ isChanged()

DataImportColumn::isChanged (   $old,
  $field 
)

Determine if the value has changed.

We can discern this using the filter b/c for objects for which a match in the db was found, we include in the inclusion filter only those fields whose value has changed.

Parameters
obj$old
string$field
Returns
boolean

Definition at line 1015 of file data_import_manager.inc.

1016  {
1017  if(!$old) return false;
1018 
1019  $filter = $old->getFilter();
1020  if($filter && !$filter->isExcluded($field))
1021  {
1022  return true;
1023  }
1024 
1025  return false;
1026  }

◆ startFormatPreview()

DataImportColumn::startFormatPreview (   $obj,
  $old,
  $field 
)

If the value has changed, show the new value in bold.

If we have a warning for this object and this column, display it in the preview.

Parameters
obj$obj
obj$old
string$field
Returns
string

Definition at line 959 of file data_import_manager.inc.

960  {
961  $warning = $this->getWarning($obj);
962  if($warning)
963  {
964  $obj->fields[$field] = HTML;
965  $value = "<span class='warning'>{$warning}</warning>\n";
966  }
967 
968  if($this->isChanged($old, $field))
969  {
970  $obj->fields[$field] = HTML;
971  $value .= "<b>";
972  }
973 
974  return $value;
975  }

Member Data Documentation

◆ $fields

DataImportColumn::$fields
Initial value:
= array(
"field" => String,
"label" => String,
"position" => Number,
"update_empty" => Boolean,
)

Definition at line 873 of file data_import_manager.inc.

◆ $importer

DataImportColumn::$importer

optional callback to handle customized login on import of a column

Definition at line 881 of file data_import_manager.inc.

◆ $options

DataImportColumn::$options = array()

optional - from related table or DataItem array whose value must match imported value

Definition at line 880 of file data_import_manager.inc.

◆ $preview_template

DataImportColumn::$preview_template

formatting template for preview display of the entire cell

Definition at line 883 of file data_import_manager.inc.

◆ $template

DataImportColumn::$template

formatting template for preview display of the data item field

Definition at line 882 of file data_import_manager.inc.

◆ $warnings

DataImportColumn::$warnings = array()

store warnings indexed by the object row number pseudo field

Definition at line 884 of file data_import_manager.inc.


The documentation for this class was generated from the following file: