<?php

namespace XQueue\Maileon\API\Reports;

use XQueue\Maileon\API\AbstractMaileonService;

/**
 *
 *
 * @author Viktor Balogh (Wiera)
 * @author Marcus Ständer | Trusted Mails GmbH | marcus.staender@trusted-mails.com
 */
class ReportsService extends AbstractMaileonService
{

    /**
     * Returns a page of openers.
     *
     * @param long $fromDate
     *  If provided, only the openers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the openers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the openers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the openers by external ids. Each value must correspond to a contacts external id.
     * @param string $formatFilter
     *  Filters the opens by format. Possible values are: html / text.
     * @param array $socialNetworkFilter
     *  Multivalued parameter to filter the opens by the social networks where they occurred.
     * @param array $deviceTypeFilter
     *  Multivalued parameter to filter the opens by device type. Possible values for device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
     * @param bool $embedEmailClientInfos
     *  If the set to true, available email client details will be appended to each open.
     * @param bool $excludeAnonymousOpens
     *  If this is set to true (default), only openers that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getOpens(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $formatFilter = null,
        $socialNetworkFilter = null,
        $deviceTypeFilter = null,
        $embedEmailClientInfos = false,
        $excludeAnonymousOpens = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($excludeAnonymousOpens)) $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";

        if (isset($formatFilter)) $params['format'] = $formatFilter;
        $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
        $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);

        return $this->get('reports/opens', $params);
    }

    /**
     * Returns a page of unique openers.
     *
     * @param long $fromDate
     *  If provided, only the openers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the openers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the openers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the openers by external ids. Each value must correspond to a contacts external id.
     * @param bool $embedEmailClientInfos
     *  If the set to true, available email client details will be appended to each open.
     * @param bool $excludeAnonymousOpens
     *  If this is set to true (default), only openers that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getUniqueOpens(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $embedEmailClientInfos = false,
        $excludeAnonymousOpens = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($excludeAnonymousOpens)) $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";

        return $this->get('reports/opens/unique', $params);
    }

    /**
     * Count openers.
     *
     * @param long $fromDate
     *  If provided, only the openers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the openers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the openers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the openers by external ids. Each value must correspond to a contacts external id.
     * @param string $formatFilter
     *  Filters the opens by format. Possible values are: html / text.
     * @param array $socialNetworkFilter
     *  Multivalued parameter to filter the opens by the social networks where they occurred.
     * @param array $deviceTypeFilter
     *  Multivalued parameter to filter the opens by device type. Possible values for device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
     * @param bool $excludeAnonymousOpens
     *  If this is set to true (default), only openers that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getOpensCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $formatFilter = null,
        $socialNetworkFilter = null,
        $deviceTypeFilter = null,
        $excludeAnonymousOpens = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousOpens)) $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";

        if (isset($formatFilter)) $params['format'] = $formatFilter;
        $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
        $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);

        return $this->get('reports/opens/count', $params);
    }

    /**
     * Count unique openers.
     *
     * @param long $fromDate
     *  If provided, only the openers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the openers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the openers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the openers by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousOpens
     *  If this is set to true (default), only openers that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getUniqueOpensCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $excludeAnonymousOpens = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousOpens)) $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";

        return $this->get('reports/opens/unique/count', $params);
    }

    /**
     * Returns a page of recipients.
     *
     * @param long $fromDate
     *  If provided, only the recipients after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the recipients before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the recipients by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the recipients by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the recipients by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the recipients by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeDeletedRecipients
     *  Supported values: true / false. If set to true, the recipients that have been removed from maileon will be excluded.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getRecipients(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $excludeDeletedRecipients = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($excludeDeletedRecipients)) $params['exclude_deleted_recipients'] = ($excludeDeletedRecipients == true) ? "true" : "false";

        return $this->get('reports/recipients', $params);
    }

    /**
     * Count recipients.
     *
     * @param long $fromDate
     *  If provided, only the recipients after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the recipients before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the recipients by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the recipients by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the recipients by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the recipients by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeDeletedRecipients
     *  Supported values: true / false. If set to true, the recipients that have been removed from maileon will be excluded.
     * @return com_maileon_api_Page
     */
    function getRecipientsCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $excludeDeletedRecipients = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeDeletedRecipients)) $params['exclude_deleted_recipients'] = ($excludeDeletedRecipients == true) ? "true" : "false";

        return $this->get('reports/recipients/count', $params);
    }

    /**
     * Returns a page of clickers.
     *
     * @param long $fromDate
     *  If provided, only the clickers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the clickers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the clickers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the clickers by external ids. Each value must correspond to a contacts external id.
     * @param string $formatFilter
     *  Filters the opens by format. Possible values are: html / text.
     * @param array $linkIdFilter
     *  Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
     * @param string $linkUrlFilter
     *  Filters the clicks by link url.
     * @param array $linkTagFilter
     *  Multivalued parameter to filter the clicks by tags associated to the links.
     * @param array $socialNetworkFilter
     *  Multivalued parameter to filter the opens by the social networks where they occurred.
     * @param array $deviceTypeFilter
     *  Multivalued parameter to filter the opens by device type. Possible values for device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
     * @param bool $embedEmailClientInfos
     *  If the set to true, available email client details will be appended to each open.
     * @param bool $excludeAnonymousClicks
     *  If this is set to true (default), only clicks that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @param bool $embedLinkTags
     *  If the set to true, available link tags will be appended to each click.
     * @return com_maileon_api_Page
     */
    function getClicks(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $formatFilter = null,
        $linkIdFilter = null,
        $linkUrlFilter = null,
        $linkTagFilter = null,
        $socialNetworkFilter = null,
        $deviceTypeFilter = null,
        $embedEmailClientInfos = false,
        $excludeAnonymousClicks = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100,
        $embedLinkTags = false)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($embedLinkTags)) $params['embed_link_tags'] = ($embedLinkTags == true) ? "true" : "false";
        if (isset($excludeAnonymousClicks)) $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";

        if (isset($formatFilter)) $params['format'] = $formatFilter;
        $params = $this->appendArrayFields($params, "link_id", $linkIdFilter);
        if (isset($linkUrlFilter)) $params['link_url'] = $linkUrlFilter;
        $params = $this->appendArrayFields($params, "link_tag", $linkTagFilter);
        $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
        $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);

        return $this->get('reports/clicks', $params);
    }

    /**
     * Returns a page of unique clickers.
     *
     * @param long $fromDate
     *  If provided, only the clickers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the clickers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the clickers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the clickers by external ids. Each value must correspond to a contacts external id.
     * @param bool $embedEmailClientInfos
     *  If the set to true, available email client details will be appended to each open.
     * @param bool $excludeAnonymousClicks
     *  If this is set to true (default), only clicks that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @param bool $embedLinkTags
     *  If the set to true, available link tags will be appended to each click.
     * @return com_maileon_api_Page
     */
    function getUniqueClicks(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $embedEmailClientInfos = false,
        $excludeAnonymousClicks = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100,
        $embedLinkTags = false)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($embedLinkTags)) $params['embed_link_tags'] = ($embedLinkTags == true) ? "true" : "false";
        if (isset($excludeAnonymousClicks)) $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";

        return $this->get('reports/clicks/unique', $params);
    }

    /**
     * Count clickers.
     *
     * @param long $fromDate
     *  If provided, only the clickers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the clickers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the clickers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the clickers by external ids. Each value must correspond to a contacts external id.
     * @param string $formatFilter
     *  Filters the opens by format. Possible values are: html / text.
     * @param array $linkIdFilter
     *  Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
     * @param string $linkUrlFilter
     *  Filters the clicks by link url.
     * @param array $linkTagFilter
     *  Multivalued parameter to filter the clicks by tags associated to the links.
     * @param array $socialNetworkFilter
     *  Multivalued parameter to filter the opens by the social networks where they occurred.
     * @param array $deviceTypeFilter
     *  Multivalued parameter to filter the opens by device type. Possible values for device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
     * @param bool $excludeAnonymousClicks
     *  If this is set to true (default), only clicks that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getClicksCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $formatFilter = null,
        $linkIdFilter = null,
        $linkUrlFilter = null,
        $linkTagFilter = null,
        $socialNetworkFilter = null,
        $deviceTypeFilter = null,
        $excludeAnonymousClicks = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousClicks)) $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";

        if (isset($formatFilter)) $params['format'] = $formatFilter;
        $params = $this->appendArrayFields($params, "link_id", $linkIdFilter);
        if (isset($linkUrlFilter)) $params['link_url'] = $linkUrlFilter;
        $params = $this->appendArrayFields($params, "link_tag", $linkTagFilter);
        $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
        $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);

        return $this->get('reports/clicks/count', $params);
    }

    /**
     * Count unique clickers.
     *
     * @param long $fromDate
     *  If provided, only the clickers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the clickers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the clickers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the clickers by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousClicks
     *  If this is set to true (default), only clicks that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getUniqueClicksCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,

        $excludeAnonymousClicks = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousClicks)) $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";

        return $this->get('reports/clicks/unique/count', $params);
    }

    /**
     * Returns a page of bouncers.
     *
     * @param long $fromDate
     *  If provided, only the bouncers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the bouncers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the bouncers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a contacts external id.
     * @param array $statusCodeFilter
     *  Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit (example: 5.0.0).
     * @param string $typeFilter
     *  Filters the bounces by type: permanent / transient.
     * @param string $sourceFilter
     *  Filters the bounces by their source: mta-listener / reply.
     * @param bool $excludeAnonymousBounces
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getBounces(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $statusCodeFilter = null,
        $typeFilter = null,
        $sourceFilter = null,
        $excludeAnonymousBounces = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($excludeAnonymousBounces)) $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";

        if (isset($typeFilter)) $params['type'] = $typeFilter;
        if (isset($sourceFilter)) $params['source_filter'] = $sourceFilter;

        return $this->get('reports/bounces', $params);
    }

    /**
     * Returns a page of unique bouncers.
     *
     * @param long $fromDate
     *  If provided, only the bouncers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the bouncers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the bouncers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousBounces
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *  Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getUniqueBounces(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $excludeAnonymousBounces = false,
        $standardFields = null,
        $customFields = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($excludeAnonymousBounces)) $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";

        return $this->get('reports/bounces/unique', $params);
    }

    /**
     * Count bouncers.
     *
     * @param long $fromDate
     *  If provided, only the bouncers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the bouncers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the bouncers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a contacts external id.
     * @param array $statusCodeFilter
     *  Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit (example: 5.0.0).
     * @param string $typeFilter
     *  Filters the bounces by type: permanent / transient.
     * @param string $sourceFilter
     *  Filters the bounces by their source: mta-listener / reply.
     * @param bool $excludeAnonymousBounces
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getBouncesCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $statusCodeFilter = null,
        $typeFilter = null,
        $sourceFilter = null,
        $excludeAnonymousBounces = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousBounces)) $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";

        if (isset($typeFilter)) $params['type'] = $typeFilter;
        if (isset($sourceFilter)) $params['source_filter'] = $sourceFilter;

        return $this->get('reports/bounces/count', $params);
    }

    /**
     * Count unique bouncers.
     *
     * @param long $fromDate
     *  If provided, only the bouncers after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the bouncers before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *  Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *  Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the bouncers by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousBounces
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getUniqueBouncesCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $excludeAnonymousBounces = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset($excludeAnonymousBounces)) $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";

        return $this->get('reports/bounces/unique/count', $params);
    }

    /**
     * Returns a page of blocks.
     *
     * @param long $fromDate
     *  If provided, only the blocks after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the blocks before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $contactIds
     *  Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the blocks by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the blocks by external ids. Each value must correspond to a contacts external id.
     * @param array $reasons
     *  Filter by reason, valid: blacklist, bounce_policy.
     * @param string $oldStatus
     *  Filter by old status, valid: allowed, blocked.
     * @param string $newStatus
     *  Filter by new status, valid: allowed, blocked.
     * @param bool $excludeAnonymousBlocks
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @param bool $standardFields
     *  The list of standard contact fields to return.
     * @param bool $customFields
     *  The list of custom contact fields to return.
     * @param integer $pageIndex
     *  The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *  The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getBlocks(
        $fromDate = null,
        $toDate = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $reasons = null,
        $oldStatus = null,
        $newStatus = null,
        $excludeAnonymousBlocks = false,
        $standardFields = null,
        $customFields = null,
        $pageIndex = 1,
        $pageSize = 100)
    {

        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, null, null, null);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset($embedEmailClientInfos)) $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
        if (isset($excludeAnonymousBlocks)) $params['exclude_anonymous_blocks'] = ($excludeAnonymousBlocks == true) ? "true" : "false";

        $params = $this->appendArrayFields($params, "reasons", $reasons);
        if (isset($oldStatus)) $params['old_status'] = $oldStatus;
        if (isset($newStatus)) $params['new_status'] = $newStatus;

        return $this->get('reports/blocks', $params);
    }

    /**
     * Count blocks.
     *
     * @param long $fromDate
     *  If provided, only the blocks after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *  If provided, only the blocks before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $contactIds
     *  Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *  Multivalued parameter to filter the blocks by email addresses.
     * @param array $contactExternalIds
     *  Multivalued parameter to filter the blocks by external ids. Each value must correspond to a contacts external id.
     * @param array $reasons
     *  Filter by reason, valid: blacklist, bounce_policy.
     * @param string $oldStatus
     *  Filter by old status, valid: allowed, blocked.
     * @param string $newStatus
     *  Filter by new status, valid: allowed, blocked.
     *  Filters the bounces by their source: mta-listener / reply.
     * @param bool $excludeAnonymousBlocks
     *  If this is set to true (default), only bounces that have not yet been anonymized (due to deletion/unsubscription) are returned.
     * @return com_maileon_api_Page
     */
    function getBlocksCount(
        $fromDate = null,
        $toDate = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $reasons = null,
        $oldStatus = null,
        $newStatus = null,
        $excludeAnonymousBlocks = false)
    {

        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, null, null);

        if (isset($excludeAnonymousBlocks)) $params['exclude_anonymous_blocks'] = ($excludeAnonymousBlocks == true) ? "true" : "false";

        $params = $this->appendArrayFields($params, "reasons", $reasons);
        if (isset($oldStatus)) $params['old_status'] = $oldStatus;
        if (isset($newStatus)) $params['new_status'] = $newStatus;

        return $this->get('reports/blocks/count', $params);
    }

    /**
     * Returns a page of unsubscriberss.
     *
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param string $source
     *            Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a reply mail (reply) or other.
     * @param bool $embedFieldBackups
     *            Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *            The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *            The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     *
     * @return com_maileon_api_Page
     */
    function getUnsubscribers(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $source = null,
        $embedFieldBackups = false,
        $pageIndex = 1,
        $pageSize = 100)
    {
        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, $source, $embedFieldBackups);

        return $this->get('reports/unsubscriptions', $params);
    }

    /**
     * Count unsubscribers.
     *
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param string $source
     *            Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a reply mail (reply) or other.
     *
     * @return com_maileon_api_Page
     */
    function getUnsubscribersCount(
        $fromDate = null,
        $toDate = null,
        $mailingIds = null,
        $contactIds = null,
        $contactEmails = null,
        $contactExternalIds = null,
        $source = null)
    {
        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, $source);

        return $this->get('reports/unsubscriptions/count', $params);
    }

    /**
     * Returns a page of subscribers.
     *
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousContacts
     *            If this is set to true (default), only subscribers that have not yet been anonymized (due to deletion) are returned.
     * @param bool $standardFields
     *            The list of standard contact fields to return.
     * @param bool $customFields
     *            The list of custom contact fields to return.
     * @param bool $embedFieldBackups
     *            Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     * @param integer $pageIndex
     *            The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *            The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @return com_maileon_api_Page
     */
    function getSubscribers($fromDate = null, $toDate = null, $mailingIds = array(), $contactIds = array(), $contactEmails = array(), $contactExternalIds = array(), $excludeAnonymousContacts = false, $standardFields = array(), $customFields = array(), $embedFieldBackups = false, $pageIndex = 1, $pageSize = 100)
    {
        $params = $this->createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null, $embedFieldBackups);

        $params = $this->appendArrayFields($params, "standard_field", $standardFields);
        $params = $this->appendArrayFields($params, "custom_field", $customFields);
        if (isset ($excludeAnonymousContacts))
            $params ['exclude_anonymous_contacts'] = ($excludeAnonymousContacts == true) ? "true" : "false";

        return $this->get('reports/subscribers', $params);
    }

    /**
     * Count subscribers.
     *
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param bool $excludeAnonymousContacts
     *            If this is set to true (default), only subscribers that have not yet been anonymized (due to deletion) are returned.
     * @return com_maileon_api_Page
     */
    function getSubscribersCount($fromDate = null, $toDate = null, $mailingIds = array(), $contactIds = array(), $contactEmails = array(), $contactExternalIds = array(), $excludeAnonymousContacts = false)
    {
        $params = $this->createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, null);

        if (isset ($excludeAnonymousContacts))
            $params ['exclude_anonymous_contacts'] = ($excludeAnonymousContacts == true) ? "true" : "false";

        return $this->get('reports/subscribers/count', $params);
    }

    /**
     * Creates the common query parameters
     *
     * @param integer $pageIndex
     *            The index of the result page. The index must be greater or equal to 1.
     * @param integer $pageSize
     *            The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param string $source
     *            Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a reply mail (reply) or other.
     * @param bool
     *            $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been backed up for mailings because of a backup instruction. For each unsubscription, the corresponding field backups will be returned if available. Note that this only applies for non anonymizable field backups.
     *
     * @return array
     */
    private function createQueryParameters($pageIndex, $pageSize, $fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, $source, $embedFieldBackups)
    {
        $queryParameters = array(
            'page_index' => $pageIndex,
            'page_size' => $pageSize
        );

        if (isset ($fromDate))
            $queryParameters ['from_date'] = $fromDate;
        if (isset ($toDate))
            $queryParameters ['to_date'] = $toDate;
        if (isset ($source))
            $queryParameters ['source'] = $source;

        $queryParameters = $this->appendArrayFields($queryParameters, "ids", $contactIds);
        $queryParameters = $this->appendArrayFields($queryParameters, "emails", $contactEmails);
        $queryParameters = $this->appendArrayFields($queryParameters, "eids", $contactExternalIds);

        if (isset ($embedFieldBackups))
            $queryParameters ['embed_field_backups'] = ($embedFieldBackups == true) ? "true" : "false";

        if (isset ($mailingIds)) {
            $queryParameters ['mailing_id'] = array();

            foreach ($mailingIds as $mailingId) {
                $queryParameters ['mailing_id'] [] = $mailingId;
            }
        }
        return $queryParameters;
    }

    /**
     * Creates the common query parameters for count operations
     *
     * @param long $fromDate
     *            If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param long $toDate
     *            If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
     * @param array $contactIds
     *            Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
     * @param array $contactEmails
     *            Multivalued parameter to filter the unsubscriptions by email addresses.
     * @param array $contactExternalIds
     *            Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a contacts external id.
     * @param array $mailingIds
     *            Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
     * @param string $source
     *            Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a reply mail (reply) or other.
     *
     * @return array
     */
    private function createCountQueryParameters($fromDate, $toDate, $contactIds, $contactEmails, $contactExternalIds, $mailingIds, $source)
    {
        $queryParameters = array();

        if (isset ($fromDate))
            $queryParameters ['from_date'] = $fromDate;
        if (isset ($toDate))
            $queryParameters ['to_date'] = $toDate;
        if (isset ($source))
            $queryParameters ['source'] = $source;

        $queryParameters = $this->appendArrayFields($queryParameters, "ids", $contactIds);
        $queryParameters = $this->appendArrayFields($queryParameters, "emails", $contactEmails);
        $queryParameters = $this->appendArrayFields($queryParameters, "eids", $contactExternalIds);

        if (isset ($mailingIds)) {
            $queryParameters ['mailing_id'] = array();

            foreach ($mailingIds as $mailingId) {
                $queryParameters ['mailing_id'] [] = $mailingId;
            }
        }
        return $queryParameters;
    }
}


<?php

namespace Cityware\MemoryShared\Storage;

use Cityware\MemoryShared\Storage\Exception\RuntimeException;

class Memcached implements StorageInterface, Feature\CapacityStorageInterface {

    /**
     * Memcached instance
     * @var mixed
     */
    protected $memcached;

    /**
     * Default config
     * @var array
     */
    protected $config = array(
        'host' => '127.0.0.1',
        'port' => 11211,
    );

    /**
     * Construct memcached storge
     * @param array $config
     */
    public function __construct(array $config = null) {
        if (!extension_loaded('memcache')) {
            throw new RuntimeException('Memcache extension must be loaded.');
        }
        if ($config) {
            $this->config = $config;
        }
    }

    /**
     * Memory alloc
     */
    protected function alloc() {
        if (null !== $this->memcached) {
            return;
        }
        $this->memcached = new \Memcache('fork_pool');
        $connexion = @$this->memcached->connect($this->config['host'], $this->config['port']);
        if (!$connexion) {
            throw new RuntimeException('Connexion to memcache refused.');
        }
    }

    /**
     * Test if has datas with $uid key
     * @param mixed $uid
     * @return boolean
     */
    public function has($uid) {
        if (null === $this->memcached) {
            return false;
        }
        $data = $this->read($uid);
        return false !== $data;
    }

    /**
     * Read datas with $uid key
     * @param mixed $uid
     * @return mixed
     */
    public function read($uid) {
        $this->alloc();
        return $this->memcached->get($uid);
    }

    /**
     * Write datas on $uid key
     * @param mixed $uid
     * @param mixed $mixed
     */
    public function write($uid, $mixed) {
        $this->alloc();
        return $this->memcached->set($uid, $mixed);
    }

    /**
     * Clear datas with $uid key
     * @param mixed $uid
     * @return void
     */
    public function clear($uid = null) {
        $this->alloc();
        if ($uid) {
            return $this->memcached->delete($uid);
        }
        return $this->memcached->flush();
    }

    /**
     * Close segment
     * @param int
     */
    public function close() {
        if (null === $this->memcached) {
            return;
        }
        $this->memcached->close();
    }

    /**
     * Get max bloc allow
     */
    public function canAllowBlocsMemory($numBloc) {
        return true; // no limitation
    }

}


<?php

namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

class DocProps extends WriterPart
{
    /**
     * Write docProps/app.xml to XML format.
     *
     * @param Spreadsheet $spreadsheet
     *
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     *
     * @return string XML Output
     */
    public function writeDocPropsApp(Spreadsheet $spreadsheet)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // Properties
        $objWriter->startElement('Properties');
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
        $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');

        // Application
        $objWriter->writeElement('Application', 'Microsoft Excel');

        // DocSecurity
        $objWriter->writeElement('DocSecurity', '0');

        // ScaleCrop
        $objWriter->writeElement('ScaleCrop', 'false');

        // HeadingPairs
        $objWriter->startElement('HeadingPairs');

        // Vector
        $objWriter->startElement('vt:vector');
        $objWriter->writeAttribute('size', '2');
        $objWriter->writeAttribute('baseType', 'variant');

        // Variant
        $objWriter->startElement('vt:variant');
        $objWriter->writeElement('vt:lpstr', 'Worksheets');
        $objWriter->endElement();

        // Variant
        $objWriter->startElement('vt:variant');
        $objWriter->writeElement('vt:i4', $spreadsheet->getSheetCount());
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // TitlesOfParts
        $objWriter->startElement('TitlesOfParts');

        // Vector
        $objWriter->startElement('vt:vector');
        $objWriter->writeAttribute('size', $spreadsheet->getSheetCount());
        $objWriter->writeAttribute('baseType', 'lpstr');

        $sheetCount = $spreadsheet->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            $objWriter->writeElement('vt:lpstr', $spreadsheet->getSheet($i)->getTitle());
        }

        $objWriter->endElement();

        $objWriter->endElement();

        // Company
        $objWriter->writeElement('Company', $spreadsheet->getProperties()->getCompany());

        // Company
        $objWriter->writeElement('Manager', $spreadsheet->getProperties()->getManager());

        // LinksUpToDate
        $objWriter->writeElement('LinksUpToDate', 'false');

        // SharedDoc
        $objWriter->writeElement('SharedDoc', 'false');

        // HyperlinksChanged
        $objWriter->writeElement('HyperlinksChanged', 'false');

        // AppVersion
        $objWriter->writeElement('AppVersion', '12.0000');

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

    /**
     * Write docProps/core.xml to XML format.
     *
     * @param Spreadsheet $spreadsheet
     *
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     *
     * @return string XML Output
     */
    public function writeDocPropsCore(Spreadsheet $spreadsheet)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // cp:coreProperties
        $objWriter->startElement('cp:coreProperties');
        $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
        $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
        $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
        $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
        $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');

        // dc:creator
        $objWriter->writeElement('dc:creator', $spreadsheet->getProperties()->getCreator());

        // cp:lastModifiedBy
        $objWriter->writeElement('cp:lastModifiedBy', $spreadsheet->getProperties()->getLastModifiedBy());

        // dcterms:created
        $objWriter->startElement('dcterms:created');
        $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
        $objWriter->writeRawData(date(DATE_W3C, $spreadsheet->getProperties()->getCreated()));
        $objWriter->endElement();

        // dcterms:modified
        $objWriter->startElement('dcterms:modified');
        $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
        $objWriter->writeRawData(date(DATE_W3C, $spreadsheet->getProperties()->getModified()));
        $objWriter->endElement();

        // dc:title
        $objWriter->writeElement('dc:title', $spreadsheet->getProperties()->getTitle());

        // dc:description
        $objWriter->writeElement('dc:description', $spreadsheet->getProperties()->getDescription());

        // dc:subject
        $objWriter->writeElement('dc:subject', $spreadsheet->getProperties()->getSubject());

        // cp:keywords
        $objWriter->writeElement('cp:keywords', $spreadsheet->getProperties()->getKeywords());

        // cp:category
        $objWriter->writeElement('cp:category', $spreadsheet->getProperties()->getCategory());

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

    /**
     * Write docProps/custom.xml to XML format.
     *
     * @param Spreadsheet $spreadsheet
     *
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     *
     * @return string XML Output
     */
    public function writeDocPropsCustom(Spreadsheet $spreadsheet)
    {
        $customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
        if (empty($customPropertyList)) {
            return;
        }

        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // cp:coreProperties
        $objWriter->startElement('Properties');
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
        $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');

        foreach ($customPropertyList as $key => $customProperty) {
            $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
            $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);

            $objWriter->startElement('property');
            $objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}');
            $objWriter->writeAttribute('pid', $key + 2);
            $objWriter->writeAttribute('name', $customProperty);

            switch ($propertyType) {
                case 'i':
                    $objWriter->writeElement('vt:i4', $propertyValue);

                    break;
                case 'f':
                    $objWriter->writeElement('vt:r8', $propertyValue);

                    break;
                case 'b':
                    $objWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');

                    break;
                case 'd':
                    $objWriter->startElement('vt:filetime');
                    $objWriter->writeRawData(date(DATE_W3C, $propertyValue));
                    $objWriter->endElement();

                    break;
                default:
                    $objWriter->writeElement('vt:lpwstr', $propertyValue);

                    break;
            }

            $objWriter->endElement();
        }

        $objWriter->endElement();

        return $objWriter->getData();
    }
}


<?php

namespace Cityware\MemoryShared\Storage;

use Zend\Db\Adapter\Adapter;
use Zend\Stdlib\Exception;

class Db implements StorageInterface, Feature\CapacityStorageInterface {

    /**
     * Db adapater
     * @var Adapter
     */
    protected $adapter;

    /**
     * Db storage options
     * @var array
     */
    protected $options;

    /**
     * Db storage constructor, need db adapter and db options
     * @param array $options
     */
    public function __construct(array $options = array()) {
        if ($options) {
            $this->setOptions($options);
        }
    }

    /**
     * Test if has datas with $uid key
     * @param mixed $uid
     * @return boolean
     */
    public function has($uid) {
        $options = $this->getOptions();
        $stmt = $this->adapter->query(sprintf('SELECT %s FROM %s WHERE %s = "%s"', $options['column_value'], $options['table'], $options['column_key'], $uid), Adapter::QUERY_MODE_EXECUTE);
        return $stmt->count() > 0;
    }

    /**
     * Read datas with $uid key
     * @param mixed $uid
     * @return mixed
     */
    public function read($uid) {
        $options = $this->getOptions();
        $stmt = $this->adapter->query(sprintf('SELECT %s FROM %s WHERE %s = "%s"', $options['column_value'], $options['table'], $options['column_key'], $uid), Adapter::QUERY_MODE_EXECUTE);
        if ($stmt->count() == 0) {
            return false;
        }
        $current = $stmt->current();
        $datas = $current->getArrayCopy();
        $contents = array_shift($datas);
        return unserialize($contents);
    }

    /**
     * Write datas on $uid key
     * @param mixed $uid
     * @param mixed $mixed
     */
    public function write($uid, $mixed) {
        $options = $this->getOptions();
        $this->adapter->query(sprintf('INSERT INTO %s (%s, %s) VALUES ("%s", %s)', $options['table'], $options['column_key'], $options['column_value'], $uid, $this->adapter->getPlatform()->quoteValue(serialize($mixed))), Adapter::QUERY_MODE_EXECUTE);
        return true;
    }

    /**
     * Clear datas with $uid key
     * @param mixed $uid
     * @return void
     */
    public function clear($uid = null) {
        $options = $this->getOptions();
        if ($uid) {
            if (!$this->has($uid)) {
                return false;
            }
            $stmt = $this->adapter->query(sprintf('DELETE FROM %s WHERE %s = "%s"', $options['table'], $options['column_key'], $uid), Adapter::QUERY_MODE_EXECUTE);
            return true;
        }
        $stmt = $this->adapter->query(sprintf('TRUNCATE TABLE %s', $options['table']), Adapter::QUERY_MODE_EXECUTE);
        return true;
    }

    /**
     * Close storage
     * @param int
     */
    public function close() {
        return; // do not close db connection
    }

    /**
     * Get max bloc allow
     * @return int
     */
    public function canAllowBlocsMemory($numBloc) {
        return true; // no limitation
    }

    /**
     * Get the adapter options
     * @return array
     */
    protected function getOptions() {
        if (null === $this->options) {
            throw new Exception\InvalidArgumentException('Db adapter options must be defined.');
        }
        return $this->options;
    }

    /**
     * Set the db adapter options
     * @param array $options
     */
    protected function setOptions(array $options) {
        if (!array_key_exists('adapter', $options) || !array_key_exists('table', $options) || !array_key_exists('column_key', $options) || !array_key_exists('column_value', $options)) {
            throw new Exception\InvalidArgumentException('Db adapter options must be defined "adapter", "table", "column_key" and "column_value" keys.');
        }
        if (!$options['adapter'] instanceof Adapter) {
            throw new Exception\InvalidArgumentException('Db adapter must be an instance of Zend\Db\Adapter\Adapter.');
        }
        $this->adapter = $options['adapter'];
        $options['table'] = $this->adapter->getPlatform()->quoteIdentifier($options['table']);
        $options['column_key'] = $this->adapter->getPlatform()->quoteIdentifier($options['column_key']);
        $options['column_value'] = $this->adapter->getPlatform()->quoteIdentifier($options['column_value']);
        $this->options = $options;

        return $this;
    }

}


<?php

namespace XQueue\Maileon\API\ContactFilters;

use XQueue\Maileon\API\XML\AbstractXMLWrapper;
use XQueue\Maileon\API\ContactFilters\Rule;

/**
 * The wrapper class for a Maileon contact filter.
 *
 * @author Felix Heinrichs | Trusted Mails GmbH | felix.heinrichs@trusted-mails.com
 * @author Marcus Ständer | Trusted Mails GmbH | marcus.staender@trusted-mails.com
 */
class ContactFilter extends AbstractXMLWrapper
{
    // TODO document fields
    public $author;
    public $countContacts;
    public $countRules;
    public $created;
    public $id;
    public $name;
    public $state;
    public $rules;

    // TODO document arguments
    /**
     * Creates a new contact filter wrapper object.
     *
     * @param number $id
     * @param string $name
     * @param string $author
     * @param number $countContacts
     * @param number $countRules
     * @param string $created
     * @param string $state
     */
    function __construct(
        $id = 0,
        $name = "",
        $author = "",
        $countContacts = 0,
        $countRules = 0,
        $created = "1970-01-01 00:00:00",
        $state = "")
    {
        $this->id = $id;
        $this->name = $name;
        $this->author = $author;
        $this->countContacts = $countContacts;
        $this->countRules = $countRules;
        $this->created = $created;
        $this->state = $state;
    }

    /**
     * Adds a rule to the contact filter
     *
     * @param com_maileon_api_contactfilters_Rule $rule
     */
    function addRule($rule)
    {
        if (!$this->rules) $this->rules = array();
        array_push($this->rules, $rule);
    }

    /**
     * Initializes this contact filter from an XML representation.
     *
     * @param SimpleXMLElement $xmlElement
     *  the XML representation to use
     */
    function fromXML($xmlElement)
    {
        $this->author = $xmlElement->author;
        $this->countContacts = $xmlElement->count_contacts;
        $this->countRules = $xmlElement->count_rules;
        $this->created = $xmlElement->created;
        $this->id = $xmlElement->id;
        $this->name = $xmlElement->name;
        $this->state = $xmlElement->state;
        if ($xmlElement->rules) {
            $rules = $xmlElement->rules;
            foreach ($rules as $rule) {
                array_push($this->rules, new Rule($rule->is_customfield, $rule->field, $rule->operator, $rule->value, $rule->type));
            }
        }
    }

    /**
     * @return \em SimpleXMLElement
     *  containing the serialized representation of this contact filter
     */
    function toXML()
    {
        $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><contactfilter></contactfilter>");

        $xml->addChild("id", $this->id);
        $xml->addChild("name", $this->name);
        $xml->addChild("author", $this->author);
        $xml->addChild("count_contacts", $this->countContacts);
        $xml->addChild("count_rules", $this->countRules);
        $xml->addChild("created", $this->created);
        $xml->addChild("state", $this->state);

        if (isset($this->rules)) {
            $rules = $xml->addChild("rules");
            foreach ($this->rules as $rule) {
                $field = $rules->addChild("rule");
                $field->addChild("is_customfield", ($rule->isCustomfield) ? "true" : "false");
                $field->addChild("field", $rule->field);
                $field->addChild("operator", $rule->operator);
                $field->addChild("value", $rule->value);
                $field->addChild("type", $rule->type);
            }
        }

        return $xml;
    }

    /**
     * @return \em string
     *  containing a human-readable representation of this contact filter
     */
    function toString()
    {

        // Generate standard field string
        $rules = "";
        if (isset($this->rules)) {
            foreach ($this->rules as $rule) {
                $rules .= $rule->toString() . ",";
            }
            $rules = rtrim($rules, ',');
        }

        return "ContactFilter [author=" . $this->author . ", countContacts="
        . $this->countContacts . ", countRules=" . $this->countRules . ", created="
        . $this->created . ", id=" . $this->id . ", name=" . $this->name . ", state="
        . $this->state . ", rules={" . $rules . "}]";
    }
}


<?php

namespace RodrigoPedra\ClearSaleID\Entity\Request;

use InvalidArgumentException;
use RodrigoPedra\ClearSaleID\Entity\XmlEntityInterface;
use RodrigoPedra\ClearSaleID\Exception\RequiredFieldException;
use XMLWriter;

class Passenger implements XmlEntityInterface
{
    const DOCUMENT_TYPE_CPF            = 1;
    const DOCUMENT_TYPE_CNPJ           = 2;
    const DOCUMENT_TYPE_RG             = 3;
    const DOCUMENT_TYPE_IE             = 4;
    const DOCUMENT_TYPE_PASSAPORTE     = 5;
    const DOCUMENT_TYPE_CTPS           = 6;
    const DOCUMENT_TYPE_TITULO_ELEITOR = 7;

    private $documentTypes = [
        self::DOCUMENT_TYPE_CPF,
        self::DOCUMENT_TYPE_CNPJ,
        self::DOCUMENT_TYPE_RG,
        self::DOCUMENT_TYPE_IE,
        self::DOCUMENT_TYPE_PASSAPORTE,
        self::DOCUMENT_TYPE_CTPS,
        self::DOCUMENT_TYPE_TITULO_ELEITOR
    ];

    /** @var  string */
    private $name;

    /** @var  string */
    private $frequentFlyerCard;

    /** @var  int */
    private $legalDocumentType;

    /** @var  string */
    private $legalDocument;

    /**
     * @param  string $name
     * @param  int    $legalDocumentType
     * @param  string $legalDocument
     *
     * @return \RodrigoPedra\ClearSaleID\Entity\Request\Passenger
     */
    public static function create( $name, $legalDocumentType, $legalDocument )
    {
        $instance = new self;

        $instance->setName( $name );
        $instance->setLegalDocumentType( $legalDocumentType );
        $instance->setLegalDocument( $legalDocument );

        return $instance;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param  string $name
     *
     * @return $this
     */
    public function setName( $name )
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return string
     */
    public function getFrequentFlyerCard()
    {
        return $this->frequentFlyerCard;
    }

    /**
     * @param  string $frequentFlyerCard
     *
     * @return $this
     */
    public function setFrequentFlyerCard( $frequentFlyerCard )
    {
        $this->frequentFlyerCard = $frequentFlyerCard;

        return $this;
    }

    /**
     * @return int
     */
    public function getLegalDocumentType()
    {
        return $this->legalDocumentType;
    }

    /**
     * @param  int $legalDocumentType
     *
     * @return $this
     */
    public function setLegalDocumentType( $legalDocumentType )
    {
        if (!in_array( intval( $legalDocumentType ), $this->documentTypes )) {
            throw new InvalidArgumentException( sprintf( 'Invalid document type (%s)', $legalDocumentType ) );
        }

        $this->legalDocumentType = $legalDocumentType;

        return $this;
    }

    /**
     * @return string
     */
    public function getLegalDocument()
    {
        return $this->legalDocument;
    }

    /**
     * @param  string $legalDocument
     *
     * @return $this
     */
    public function setLegalDocument( $legalDocument )
    {
        $this->legalDocument = $legalDocument;

        return $this;
    }

    /**
     * @param  \XMLWriter $XMLWriter
     *
     * @throws \RodrigoPedra\ClearSaleID\Exception\RequiredFieldException
     */
    public function toXML( XMLWriter $XMLWriter )
    {
        $XMLWriter->startElement( 'Passageiro' );

        if ($this->name) {
            $XMLWriter->writeElement( 'Nome', $this->name );
        } else {
            throw new RequiredFieldException( 'Field Nome of the Passenger object is required' );
        }

        if ($this->frequentFlyerCard) {
            $XMLWriter->writeElement( 'ProgramaFidelidade', $this->frequentFlyerCard );
        }

        if ($this->legalDocumentType) {
            $XMLWriter->writeElement( 'TipoDocumentoLegal', $this->legalDocumentType );
        } else {
            throw new RequiredFieldException( 'Field LegalDocumentType of the Passenger object is required' );
        }

        if ($this->legalDocument) {
            $XMLWriter->writeElement( 'DocumentoLegal', $this->legalDocument );
        } else {
            throw new RequiredFieldException( 'Field LegalDocument of the Passenger object is required' );
        }

        $XMLWriter->endElement();
    }
}


<?php

namespace PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer;

use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer;

class SpContainer
{
    /**
     * Parent Shape Group Container.
     *
     * @var SpgrContainer
     */
    private $parent;

    /**
     * Is this a group shape?
     *
     * @var bool
     */
    private $spgr = false;

    /**
     * Shape type.
     *
     * @var int
     */
    private $spType;

    /**
     * Shape flag.
     *
     * @var int
     */
    private $spFlag;

    /**
     * Shape index (usually group shape has index 0, and the rest: 1,2,3...).
     *
     * @var int
     */
    private $spId;

    /**
     * Array of options.
     *
     * @var array
     */
    private $OPT;

    /**
     * Cell coordinates of upper-left corner of shape, e.g. 'A1'.
     *
     * @var string
     */
    private $startCoordinates;

    /**
     * Horizontal offset of upper-left corner of shape measured in 1/1024 of column width.
     *
     * @var int
     */
    private $startOffsetX;

    /**
     * Vertical offset of upper-left corner of shape measured in 1/256 of row height.
     *
     * @var int
     */
    private $startOffsetY;

    /**
     * Cell coordinates of bottom-right corner of shape, e.g. 'B2'.
     *
     * @var string
     */
    private $endCoordinates;

    /**
     * Horizontal offset of bottom-right corner of shape measured in 1/1024 of column width.
     *
     * @var int
     */
    private $endOffsetX;

    /**
     * Vertical offset of bottom-right corner of shape measured in 1/256 of row height.
     *
     * @var int
     */
    private $endOffsetY;

    /**
     * Set parent Shape Group Container.
     *
     * @param SpgrContainer $parent
     */
    public function setParent($parent)
    {
        $this->parent = $parent;
    }

    /**
     * Get the parent Shape Group Container.
     *
     * @return SpgrContainer
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Set whether this is a group shape.
     *
     * @param bool $value
     */
    public function setSpgr($value)
    {
        $this->spgr = $value;
    }

    /**
     * Get whether this is a group shape.
     *
     * @return bool
     */
    public function getSpgr()
    {
        return $this->spgr;
    }

    /**
     * Set the shape type.
     *
     * @param int $value
     */
    public function setSpType($value)
    {
        $this->spType = $value;
    }

    /**
     * Get the shape type.
     *
     * @return int
     */
    public function getSpType()
    {
        return $this->spType;
    }

    /**
     * Set the shape flag.
     *
     * @param int $value
     */
    public function setSpFlag($value)
    {
        $this->spFlag = $value;
    }

    /**
     * Get the shape flag.
     *
     * @return int
     */
    public function getSpFlag()
    {
        return $this->spFlag;
    }

    /**
     * Set the shape index.
     *
     * @param int $value
     */
    public function setSpId($value)
    {
        $this->spId = $value;
    }

    /**
     * Get the shape index.
     *
     * @return int
     */
    public function getSpId()
    {
        return $this->spId;
    }

    /**
     * Set an option for the Shape Group Container.
     *
     * @param int $property The number specifies the option
     * @param mixed $value
     */
    public function setOPT($property, $value)
    {
        $this->OPT[$property] = $value;
    }

    /**
     * Get an option for the Shape Group Container.
     *
     * @param int $property The number specifies the option
     *
     * @return mixed
     */
    public function getOPT($property)
    {
        if (isset($this->OPT[$property])) {
            return $this->OPT[$property];
        }

        return null;
    }

    /**
     * Get the collection of options.
     *
     * @return array
     */
    public function getOPTCollection()
    {
        return $this->OPT;
    }

    /**
     * Set cell coordinates of upper-left corner of shape.
     *
     * @param string $value eg: 'A1'
     */
    public function setStartCoordinates($value)
    {
        $this->startCoordinates = $value;
    }

    /**
     * Get cell coordinates of upper-left corner of shape.
     *
     * @return string
     */
    public function getStartCoordinates()
    {
        return $this->startCoordinates;
    }

    /**
     * Set offset in x-direction of upper-left corner of shape measured in 1/1024 of column width.
     *
     * @param int $startOffsetX
     */
    public function setStartOffsetX($startOffsetX)
    {
        $this->startOffsetX = $startOffsetX;
    }

    /**
     * Get offset in x-direction of upper-left corner of shape measured in 1/1024 of column width.
     *
     * @return int
     */
    public function getStartOffsetX()
    {
        return $this->startOffsetX;
    }

    /**
     * Set offset in y-direction of upper-left corner of shape measured in 1/256 of row height.
     *
     * @param int $startOffsetY
     */
    public function setStartOffsetY($startOffsetY)
    {
        $this->startOffsetY = $startOffsetY;
    }

    /**
     * Get offset in y-direction of upper-left corner of shape measured in 1/256 of row height.
     *
     * @return int
     */
    public function getStartOffsetY()
    {
        return $this->startOffsetY;
    }

    /**
     * Set cell coordinates of bottom-right corner of shape.
     *
     * @param string $value eg: 'A1'
     */
    public function setEndCoordinates($value)
    {
        $this->endCoordinates = $value;
    }

    /**
     * Get cell coordinates of bottom-right corner of shape.
     *
     * @return string
     */
    public function getEndCoordinates()
    {
        return $this->endCoordinates;
    }

    /**
     * Set offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width.
     *
     * @param int $endOffsetX
     */
    public function setEndOffsetX($endOffsetX)
    {
        $this->endOffsetX = $endOffsetX;
    }

    /**
     * Get offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width.
     *
     * @return int
     */
    public function getEndOffsetX()
    {
        return $this->endOffsetX;
    }

    /**
     * Set offset in y-direction of bottom-right corner of shape measured in 1/256 of row height.
     *
     * @param int $endOffsetY
     */
    public function setEndOffsetY($endOffsetY)
    {
        $this->endOffsetY = $endOffsetY;
    }

    /**
     * Get offset in y-direction of bottom-right corner of shape measured in 1/256 of row height.
     *
     * @return int
     */
    public function getEndOffsetY()
    {
        return $this->endOffsetY;
    }

    /**
     * Get the nesting level of this spContainer. This is the number of spgrContainers between this spContainer and
     * the dgContainer. A value of 1 = immediately within first spgrContainer
     * Higher nesting level occurs if and only if spContainer is part of a shape group.
     *
     * @return int Nesting level
     */
    public function getNestingLevel()
    {
        $nestingLevel = 0;

        $parent = $this->getParent();
        while ($parent instanceof SpgrContainer) {
            ++$nestingLevel;
            $parent = $parent->getParent();
        }

        return $nestingLevel;
    }
}


<?php
/**
 * Custom Images Grifus · Extensions For Grifus
 *
 * @author    Josantonius <hello@josantonius.com>
 * @package   eliasis-framework/custom-images-grifus
 * @copyright 2017 - 2018 (c) Josantonius - Custom Images Grifus
 * @license   GPL-2.0+
 * @link      https://github.com/eliasis-framework/custom-images-grifus.git
 * @since     1.0.0
 */

namespace EFG\Modules\CustomImagesGrifus\Controller\Admin;

use Eliasis\Framework\App;
use Eliasis\Framework\Controller;
use Eliasis\Complement\Type\Module;

/**
 * Image controller
 *
 * @since 1.0.0
 */
class Image extends Controller {

	/**
	 * Save images to the server when post has been added or edited.
	 *
	 * @param int     $post_id → post ID.
	 * @param object  $post    → (WP_Post) post object.
	 * @param boolean $update  → true if update post.
	 */
	public function set_images( $post_id, $post, $update ) {

		App::setCurrentID( 'EFG' );

		if ( Module::CustomImagesGrifus()->getOption( 'replace-when-add' ) ) {
			$is_insert_post = App::main()->is_after_insert_post( $post, $update );
			$is_update_post = App::main()->is_after_update_post( $post, $update );
			if ( $is_insert_post || $is_update_post ) {
				$this->model->set_images( $post_id );
			}
		}
	}

	/**
	 * Search post not edited previously and replace images.
	 */
	public function replace_old_images() {

		$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';

		if ( ! wp_verify_nonce( $nonce, 'eliasis' ) && ! wp_verify_nonce( $nonce, 'customImagesGrifusAdmin' ) ) {
			die( 'Busted!' );
		}

		$this->model->set_posts_to_review();
		$response = $this->model->replace_old_images();

		echo json_encode( $response );

		die();
	}

	/**
	 * Replace image when added a movie.
	 *
	 * @since 1.0.1
	 */
	public function replace_when_add() {

		$state = isset( $_POST['state'] ) ? $_POST['state'] : null;
		$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';

		if ( ! wp_verify_nonce( $nonce, 'eliasis' ) && ! wp_verify_nonce( $nonce, 'customImagesGrifusAdmin' ) ) {
			die( 'Busted!' );
		}

		App::setCurrentID( 'EFG' );
		$slug = Module::CustomImagesGrifus()->getOption( 'slug' );
		$this->model->set_replace_when_add( $slug, $state );
		$response = [ 'replace-when-add' => $state ];

		echo json_encode( $response );

		die();
	}

	/**
	 * Delete attached images.
	 *
	 * @since 1.0.1
	 *
	 * @param int $post_id → post ID.
	 *
	 * @return int → attachments deleted
	 */
	public function delete_attached_images( $post_id ) {

		return $this->model->delete_attached_images( $post_id );
	}
}