phpDocumentor

EmailsController extends AdminHttpViewController

Class EmailsController

PHP controller that handles the admin/emails page operations. You can also use it to perform email operations from JavaScript by providing encoded JSON arrays with email information from other pages.

Tags
category

System

Table of Contents

$assets  : AssetCollectionInterface
$attachmentsHandler  : AttachmentsHandler
Used for attachment files manipulation.
$contentView  : ContentViewInterface
$emailParser  : EmailParser
Used for parsing and encoding operations.
$emailService  : EmailServiceInterface
Used core emails operations.
$httpContextReader  : HttpContextReaderInterface
$httpResponseProcessor  : HttpResponseProcessorInterface
$postDataArray  : array<string|int, mixed>
$queryParametersArray  : array<string|int, mixed>
$serverDataArray  : array<string|int, mixed>
__construct()  : mixed
actionDataTable()  : JsonHttpControllerResponse
[AJAX - GET] Server-side processing of the main emails table.
actionDefault()  : AdminLayoutHttpControllerResponse
Displays the administration emails page.
actionDelete()  : JsonHttpControllerResponse
[AJAX - POST] Remove email records from the database.
actionDeleteAttachment()  : JsonHttpControllerResponse
[AJAX - POST] Remove existing "tmp" attachment from the server.
actionDeleteOldAttachments()  : JsonHttpControllerResponse
[AJAX - POST] Delete old attachment files from emails.
actionDeleteOldEmails()  : JsonHttpControllerResponse
[AJAX - POST] Delete old emails.
actionDownloadAttachment()  : HttpControllerResponse|AdminLayoutHttpControllerResponse
Download email attachment file.
actionGet()  : JsonHttpControllerResponse
[AJAX - POST] Get email record by ID.
actionGetAttachmentsSize()  : JsonHttpControllerResponse
[AJAX] Get attachments size in MB
actionGetEmailSettings()  : JsonHttpControllerResponse
[AJAX - GET] Get shops email settings and configure the client accordingly.
actionQueue()  : JsonHttpControllerResponse
[AJAX - POST] Queue email records into the database.
actionSend()  : JsonHttpControllerResponse
[AJAX - POST] Sends and saves the provided email collection.
actionUploadAttachment()  : JsonHttpControllerResponse
[AJAX - POST] Upload new attachment file to server.
actionUploadAttachmentWithFileManager()  : JsonHttpControllerResponse
The $_POST array contains information about the file that was uploaded. When an email file is uploaded it is stored in the "uploads/tmp" directory until the email is created and then is is moved to its own directory. The reason for this algorithm is that we do not want email attachments to be in one place altogether.
proceed()  : mixed
Initializes the controller.
validateCurrentAdminStatus()  : mixed
Makes sure that the admin status is currently given in session
_callActionMethod()  : HttpControllerResponseInterface
Invokes an action method by the given action name.
_getPostData()  : string|null
Returns the expected $_POST value by the given key name.
_getPostDataCollection()  : KeyValueCollection
Creates and returns a key value collection which represent the global $_POST array.
_getQueryParameter()  : mixed|null
Returns the expected $_GET value by the given key name.
_getQueryParametersCollection()  : KeyValueCollection
Creates and returns a key value collection which represent the global $_GET array.
_getServerData()  : string|null
Returns the expected $_SERVER value by the given key name.
_getTableOrder()  : string
Get the table order clause in string.
_render()  : string
Renders and returns a template file.
_validatePageToken()  : mixed
Check if the $_POST['pageToken'] or $_GET['pageToken'] variable is provided and if it's valid.
getTemplateFile()  : ExistingFile
Searches the GXModules directory and admin/html directory for a template file, wich can be useed inside the AdminLayoutHttpControllerResponse object for the template parameter.
isValidJson()  : bool
isValidRequestMethod()  : bool
prepareJsonInput()  : array<string|int, mixed>

Properties

Methods

actionDataTable()

[AJAX - GET] Server-side processing of the main emails table.

public actionDataTable() : JsonHttpControllerResponse

The data returned by this method will be used by the main table of the page which will display the emails records. DataTables will automatically make an AJAX request and display the returned data.

Tags
link
https://datatables.net/examples/ajax/objects.html
link
http://www.datatables.net/examples/server_side/simple.html
Return values
JsonHttpControllerResponse

Array that contains the table data.

actionDefault()

Displays the administration emails page.

public actionDefault() : AdminLayoutHttpControllerResponse

The administration page contains various JavaScript controllers which will make AJAX requests to this class in order to get/store email information. Check the JavaScript code of the page in the "admin/javascript/engine/controllers/emails" directory.

Tags
throws
RuntimeException

If page token generator was not found.

throws
InvalidArgumentException
Return values
AdminLayoutHttpControllerResponse

actionDeleteAttachment()

[AJAX - POST] Remove existing "tmp" attachment from the server.

public actionDeleteAttachment() : JsonHttpControllerResponse

This method requires an array present in the $postDataArray that contain the paths to the server "tmp" attachments to be removed. It will not remove attachments that reside in other directories because they might be used by other email records (e.g. forward existing email with attachments -> user might remove attachment that is used by the original email record causing problems to the system).

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionDeleteOldAttachments()

[AJAX - POST] Delete old attachment files from emails.

public actionDeleteOldAttachments() : JsonHttpControllerResponse

This method will filter the emails and remove their attachments on the provided date and before. This is necessary because the admin user needs a way to clean the old unnecessary files from the server and free some extra space. As an extra action this method will empty the "uploads/tmp" directory.

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionGet()

[AJAX - POST] Get email record by ID.

public actionGet() : JsonHttpControllerResponse

This method uses the provided $_POST['email_id'] value to fetch the data of the email and return it to the client. It is not used by the admin/emails page but might be useful in other pages.

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionQueue()

[AJAX - POST] Queue email records into the database.

public actionQueue() : JsonHttpControllerResponse

The queue operation will save the email with a pending status. Queue operation will be executed for all the email records inside the $_POST['collection'] variable.

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionSend()

[AJAX - POST] Sends and saves the provided email collection.

public actionSend() : JsonHttpControllerResponse

This method expects the $_POST['collection'] array to be present, containing email records to be send. Check the "EmailParser" class to see the expected JSON format.

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionUploadAttachment()

[AJAX - POST] Upload new attachment file to server.

public actionUploadAttachment() : JsonHttpControllerResponse

The $_FILES array contains information about the file that was uploaded. When an email file is uploaded it is stored in the "uploads/tmp" directory until the email is created and then is is moved to its own directory. The reason for this algorithm is that we do not want email attachments to be in one place altogether.

Return values
JsonHttpControllerResponse

Returns a success response or exception information.

actionUploadAttachmentWithFileManager()

The $_POST array contains information about the file that was uploaded. When an email file is uploaded it is stored in the "uploads/tmp" directory until the email is created and then is is moved to its own directory. The reason for this algorithm is that we do not want email attachments to be in one place altogether.

public actionUploadAttachmentWithFileManager() : JsonHttpControllerResponse
Return values
JsonHttpControllerResponse

Returns a success response or exception information.

proceed()

Initializes the controller.

public proceed(HttpContextInterface $httpContext) : mixed

Perform the common operations before the parent class proceeds with the controller method execution. In this case every method needs the EmailService so it is loaded once before every method.

Parameters
$httpContext : HttpContextInterface
Return values
mixed

_getPostData()

Returns the expected $_POST value by the given key name.

protected _getPostData(string $keyName) : string|null

This method is the object oriented layer for $_POST[$keyName].

Parameters
$keyName : string

Expected key of post parameter.

Return values
string|null

Either the expected value or null, of not found.

_getQueryParameter()

Returns the expected $_GET value by the given key name.

protected _getQueryParameter(string $keyName) : mixed|null

This method is the object oriented layer for $_GET[$keyName].

Parameters
$keyName : string

Expected key of query parameter.

Return values
mixed|null

Either the expected value or null, of not found.

_getServerData()

Returns the expected $_SERVER value by the given key name.

protected _getServerData(string $keyName) : string|null

This method is the object oriented layer for $_SERVER[$keyName].

Parameters
$keyName : string

Expected key of server parameter.

Return values
string|null

Either the expected value or null, of not found.

_getTableOrder()

Get the table order clause in string.

protected _getTableOrder(array<string|int, mixed> $rule) : string

Since the EmailsController handles the page main table it needs to take care of many operations such as filtering, limiting and ordering. This method will return the correct order string for each table, but needs to be updated if there is a change in the column order.

Parameters
$rule : array<string|int, mixed>

Contains the DataTables order data.

Tags
link
http://www.datatables.net/manual/server-side
Return values
string

Returns the order by value to be used by the CI query builder.

_render()

Renders and returns a template file.

protected _render(string $templateFile, array<string|int, mixed> $contentArray) : string
Parameters
$templateFile : string

Template file to render.

$contentArray : array<string|int, mixed>

Content array which represent the variables of the template.

Return values
string

Rendered template.

_validatePageToken()

Check if the $_POST['pageToken'] or $_GET['pageToken'] variable is provided and if it's valid.

protected _validatePageToken([string $customExceptionMessage = null ]) : mixed

Example: public function proceed(HttpContextInterface $httpContext) { parent::proceed($httpContext); // proceed http context from parent class if($_SERVER['REQUEST_METHOD'] === 'POST') { $this->_validatePageToken(); // CSRF Protection } }

Parameters
$customExceptionMessage : string = null

(optional) You can specify a custom exception message.

Tags
throws
Exception

If the validation fails.

Return values
mixed

getTemplateFile()

Searches the GXModules directory and admin/html directory for a template file, wich can be useed inside the AdminLayoutHttpControllerResponse object for the template parameter.

protected getTemplateFile(string $templateFile) : ExistingFile
Parameters
$templateFile : string

The relative path and filename to search for

Tags
throws
Exception

if the path or file is not found

Return values
ExistingFile

containing absolute file path to the given template file

isValidRequestMethod()

protected isValidRequestMethod(string $method) : bool
Parameters
$method : string
Return values
bool

prepareJsonInput()

protected prepareJsonInput(string $json) : array<string|int, mixed>
Parameters
$json : string
Return values
array<string|int, mixed>

Search results