ImportExportController
Adds features for importing and exporting data.
class Backend\Behaviors\ImportExportController
extends Backend\Classes\ControllerBehavior
This behavior is implemented in the controller like so:
public $implement = [
\Backend\Behaviors\ImportExportController::class,
];
public $importExportConfig = 'config_import_export.yaml';
The $importExportConfig
property makes reference to the configuration
values as either a YAML file, located in the controller view directory,
or directly as a PHP array.
Traits
Trait | Description |
---|---|
AssetMaker
|
Asset Maker Trait Adds asset based methods to a class |
ConfigMaker
|
Config Maker Trait Adds configuration based methods to a class |
ExtensionTrait
|
Extension trait |
SessionMaker
|
Session Maker Trait |
ViewMaker
|
View Maker Trait Adds view based methods to a class |
WidgetMaker
|
Widget Maker Trait |
Properties
public $exportColumns : array
Export column configuration.
public $exportModel : Model
Export model
public $importColumns : array
Import column configuration.
public
$importExportConfig
:
mixed
= "config_import_export.yaml"
Configuration for this behaviour
public $importModel : Model
Import model
protected
$actions
:
array
= ["import","export","download"]
Visible actions in context of the controller
protected
$exportFileName
:
string
= "export.csv"
File name used for export output.
protected $exportFormatFormWidget : Backend\Classes\WidgetBase
Reference to the widget used for standard export options.
protected $exportOptionsFormWidget : Backend\Classes\WidgetBase
Reference to the widget used for custom export options.
protected $importOptionsFormWidget : Backend\Classes\WidgetBase
Reference to the widget used for specifying import options.
protected $importUploadFormWidget : Backend\Classes\WidgetBase
Reference to the widget used for uploading import file.
protected
$requiredConfig
:
array
= []
Configuration values that must exist when applying the primary config file.
public $assetPath : string
Specifies a path to the asset directory.
public
static
$extendableStaticCalledClass
:
string
= null
The calling class when using a static method.
public $layout : string
Layout to use for the view.
public
$suppressLayout
:
bool
= false
Prevents the use of a layout.
public
$vars
:
array
= []
A list of variables to pass to the page.
protected
$assets
:
array
= {"js":[],"css":[],"rss":[]}
Collection of assets to display in the layout.
protected $config : array
Supplied configuration.
protected $configPath : string
Specifies a path to the config directory.
protected $controller : Backend\Classes\Controller
Reference to the back end controller.
protected
static
$extensionCallbacks
:
array
= []
Used to extend the constructor of an extension class. Eg:
BehaviorClass::extend(function($obj) { })
protected
$extensionHidden
:
mixed
= {"fields":[],"methods":["extensionIsHiddenField","extensionIsHiddenMethod"]}
protected $layoutPath : string
Specifies a path to the layout directory.
protected
$requiredProperties
:
array
= []
Properties that must exist in the controller using this behavior.
protected $viewPath : string | array
Specifies a path to the views directory.
Methods
public __construct (Backend\Classes\Controller $controller)
Behavior constructor
Property | Type | Description |
---|---|---|
$controller | Backend\Classes\Controller |
public
download ($name, $outputName = null
)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
$outputName | mixed |
mixed
|
public export ()
public
exportFromList (string $definition = null
, array $options = []
)
: void
Outputs the list results as a CSV export.
Property | Type | Description |
---|---|---|
$definition | string |
string
|
$options | array |
array
|
public exportGetModel ()
public exportRender ()
public import ()
public
importExportMakePartial (string $partial, array $params = []
)
: string
Controller accessor for making partials within this behavior.
Property | Type | Description |
---|---|---|
$partial | string |
string
|
$params | array |
array
|
Partial contents
public importGetModel ()
public importIsColumnRequired ($columnName)
Property | Type | Description |
---|---|---|
$columnName | mixed |
mixed
|
public importRender ()
public onExport ()
public onExportLoadForm ()
public onImport ()
public onImportLoadColumnSampleForm ()
public onImportLoadForm ()
public prepareExportVars () : void
Prepares the view data.
public prepareImportVars () : void
Prepares the view data.
protected checkPermissionsForType ($type) : View
Checks to see if the import/export is controlled by permissions and if the logged in user has permissions.
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
protected checkRequiredImportColumns ()
protected checkUseListExportMode ()
protected createCsvReader (string $path) : CsvReader
Create a new CSV reader with options selected by the user
Property | Type | Description |
---|---|---|
$path | string |
string
|
protected getExportColumns ()
protected getFormatOptionsFromPost () : array
Returns the file format options from postback. This method can be used to define presets.
protected getImportDbColumns ()
protected getImportFileColumns ()
protected getImportFilePath ()
protected getImportSourceIndexOffset (bool $firstRowTitles) : int
Get the index offset to add to the reported row number in status messages
Property | Type | Description |
---|---|---|
$firstRowTitles | bool |
bool
Whether or not the first row contains column titles |
$offset
protected getModelForType ($type)
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
protected getRedirectUrlForType ($type)
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
protected makeExportFormatFormWidget ()
protected makeExportOptionsFormWidget ()
protected makeImportOptionsFormWidget ()
protected makeImportUploadFormWidget ()
protected makeListColumns ($config)
Property | Type | Description |
---|---|---|
$config | mixed |
mixed
|
protected makeOptionsFormWidgetForType ($type)
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
protected processExportColumnsFromPost ()
public
addCss (array | string $name, array $attributes = []
)
: void
Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | array | string |
array | string
Specifies a path (URL) or an array of paths to the stylesheet(s). |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public
addJs (array | string $name, array $attributes = []
)
: void
Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | array | string |
array | string
Specifies a path (URL) or an array of paths to the script(s). |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public
addRss (string $name, array $attributes = []
)
: void
Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | string |
string
Specifies a path (URL) to the RSS channel |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public addViewPath (string | array $path) : void
Prepends a path on the available view path locations.
Property | Type | Description |
---|---|---|
$path | string | array |
string | array
|
public
combineAssets (array $assets, string $localPath = ""
)
: string
Run the provided assets through the Asset Combiner
Property | Type | Description |
---|---|---|
$assets | array |
array
Collection of assets |
$localPath | string |
string
Prefix all assets with this path (optional) |
public static extend (callable $callback)
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
public extensionApplyInitCallbacks ()
public static extensionExtendCallback (callable $callback) : void
Helper method for ::extend()
static method
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
public extensionIsHiddenField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
public extensionIsHiddenMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
public flushAssets () : void
Disables the use, and subequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.
public
getAssetPath (string $fileName, string $assetPath = null
)
: string
Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.
Property | Type | Description |
---|---|---|
$fileName | string |
string
File to load. |
$assetPath | string |
string
Explicitly define an asset path. |
Relative path to the asset file.
public getAssetPaths () : array
Returns an array of all registered asset paths.
public static getCalledExtensionClass ()
public
getConfig (string $name = null
, mixed $default = null
)
: string
Safe accessor for configuration values.
Property | Type | Description |
---|---|---|
$name | string |
string
Config name, supports array names like "field[key]" |
$default | mixed |
mixed
Default value if nothing is found |
public
getConfigPath (string $fileName, mixed $configPath = null
)
: string
Locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.
Property | Type | Description |
---|---|---|
$fileName | string |
string
File to load. |
$configPath | mixed |
mixed
Explicitly define a config path. |
Full path to the config file.
public
getViewPath (string $fileName, $viewPaths = null
)
: string
Locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.
If the fileName cannot be found it will be returned unmodified.
Property | Type | Description |
---|---|---|
$fileName | string |
string
|
$viewPaths | mixed |
mixed
|
public getViewPaths () : array
Returns the active view path locations.
public
guessConfigPath (string $suffix = ""
)
: string
Guess the package path for the called class.
Property | Type | Description |
---|---|---|
$suffix | string |
string
An extra path to attach to the end |
public
guessConfigPathFrom (string $class, string $suffix = ""
)
: string
Guess the package path from a specified class.
Property | Type | Description |
---|---|---|
$class | string |
string
Class to guess path from. |
$suffix | string |
string
An extra path to attach to the end |
public
guessViewPath (string $suffix = ""
, boolean $isPublic = false
)
: string | null
Guess the package path for the called class.
Property | Type | Description |
---|---|---|
$suffix | string |
string
An extra path to attach to the end |
$isPublic | boolean |
boolean
Returns public path instead of an absolute one |
public
guessViewPathFrom (string $class, string $suffix = ""
, boolean $isPublic = false
)
: string | null
Guess the package path from a specified class.
Property | Type | Description |
---|---|---|
$class | string |
string
Class to guess path from. |
$suffix | string |
string
An extra path to attach to the end |
$isPublic | boolean |
boolean
Returns public path instead of an absolute one |
public hasAssetsDefined () : bool
Returns true if assets any have been added.
public
makeAssets ($type = null
)
: string | null
Outputs <link>
and <script>
tags to load assets previously added
with addJs, addCss, & addRss method calls depending on the provided $type
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
public
makeConfig (array $configFile = []
, array $requiredConfig = []
)
: array | stdClass
Reads the contents of the supplied file and applies it to this object.
Property | Type | Description |
---|---|---|
$configFile | array |
array
|
$requiredConfig | array |
array
|
public
makeConfigFromArray (array $configArray = []
)
: stdClass
Makes a config object from an array, making the first level keys properties of a new object.
Property | Type | Description |
---|---|---|
$configArray | array |
array
Config array. |
The config object
public
makeFileContents (string $filePath, array $extraParams = []
)
: string
Makes all views in context of the controller, not the behavior.
Property | Type | Description |
---|---|---|
$filePath | string |
string
Absolute path to the view file. |
$extraParams | array |
array
Parameters that should be available to the view. |
public
makeFormWidget (string $class, array $fieldConfig = []
, array $widgetConfig = []
)
: Backend\Classes\FormWidgetBase
Makes a form widget object with the supplied form field and widget configuration.
Property | Type | Description |
---|---|---|
$class | string |
string
Widget class name |
$fieldConfig | array |
array
A field name, an array of config or a FormField object. |
$widgetConfig | array |
array
An array of config. |
The widget object
public
makeLayout ($name = null
, array $params = []
, boolean $throwException = true
)
: string | bool
Render a layout, defaulting to the layout propery specified on the class
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
$params | array |
array
|
$throwException | boolean |
boolean
|
The layout contents, or false.
public
makeLayoutPartial (string $partial, array $params = []
)
: string
Renders a layout partial
Property | Type | Description |
---|---|---|
$partial | string |
string
|
$params | array |
array
|
public
makePartial (string $partial, array $params = []
, boolean $throwException = true
)
: mixed
Render a partial file contents located in the views folder.
Property | Type | Description |
---|---|---|
$partial | string |
string
|
$params | array |
array
|
$throwException | boolean |
boolean
|
Partial contents or false if not throwing an exception.
public makeView (string $view) : string
Loads the specified view. Applies the layout if one is set.
The view file must have the .php extension (or ".htm" for historical reasons) and be located in the views directory
Property | Type | Description |
---|---|---|
$view | string |
string
|
public
makeViewContent (string $contents, $layout = null
)
: string
Renders supplied contents inside a layout.
Property | Type | Description |
---|---|---|
$contents | string |
string
|
$layout | mixed |
mixed
|
public
makeWidget (string $class, array $widgetConfig = []
)
: mixed | Backend\Classes\WidgetBase
Makes a widget object with the supplied configuration file.
Property | Type | Description |
---|---|---|
$class | string |
string
Widget class name |
$widgetConfig | array |
array
An array of config. |
The widget object
public mergeConfig (mixed $configA, mixed $configB) : stdClass
Merges two configuration sources, either prepared or not, and returns them as a single configuration object.
Property | Type | Description |
---|---|---|
$configA | mixed |
mixed
|
$configB | mixed |
mixed
|
The config object
public resetSession () : void
Resets all session data related to this widget.
public
setConfig (mixed $config, array $required = []
)
Sets the configuration values
Property | Type | Description |
---|---|---|
$config | mixed |
mixed
Config object or array |
$required | array |
array
Required config items |
protected addAsset (string $type, string $path, array $attributes)
Adds the provided asset to the internal asset collections
Property | Type | Description |
---|---|---|
$type | string |
string
The type of the asset: 'js' || 'css' || 'rss' |
$path | string |
string
The path to the asset |
$attributes | array |
array
The attributes for the asset |
protected controllerMethodExists (string $methodName) : bool
Returns true in case if a specified method exists in the extended controller.
Property | Type | Description |
---|---|---|
$methodName | string |
string
Specifies the method name |
protected extensionHideField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
protected extensionHideMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
protected getAssetEntryBuildPath (array $asset) : string
Internal helper, attaches a build code to an asset path
Property | Type | Description |
---|---|---|
$asset | array |
array
Stored asset array |
protected getAssetScheme (string $asset) : string
Internal helper, get asset scheme
Property | Type | Description |
---|---|---|
$asset | string |
string
Specifies a path (URL) to the asset. |
protected getLocalPath (string | null $relativePath)
Property | Type | Description |
---|---|---|
$relativePath | string | null |
string | null
|
protected
getSession (string $key = null
, string $default = null
)
: string
Retrieves a widget related key/value pair from session data.
Property | Type | Description |
---|---|---|
$key | string |
string
Unique key for the data store. |
$default | string |
string
A default value to use when value is not found. |
protected handleViewException (Throwable $e, integer $obLevel) : void
Handle a view exception.
Property | Type | Description |
---|---|---|
$e | Throwable |
Throwable
|
$obLevel | integer |
integer
|
protected hideAction (mixed $methodName)
Protects a public method from being available as an controller action.
These methods could be defined in a controller to override a behavior default action. Such methods should be defined as public, to allow the behavior object to access it. By default public methods of a controller are considered as actions. To prevent this occurrence, methods should be hidden by using this method.
Property | Type | Description |
---|---|---|
$methodName | mixed |
mixed
Specifies a method name. |
protected makeSessionId () : string
Returns a unique session identifier for this widget and controller action.
protected putSession (string $key, mixed $value) : void
Saves a widget related key/value pair in to session data.
Property | Type | Description |
---|---|---|
$key | string |
string
Unique key for the data store. |
$value | mixed |
mixed
The value to store. |
protected removeDuplicates () : void
Removes duplicate assets from the entire collection.