Get en email from the archive by its ID

@param  int  $iId   The email's ID
@param array $aData The data array

@return mixed   stdClass on success, false on failure
@throws \Nails\Common\Exception\FactoryException
972723
public function getById($iId, $aData = [])
    {
        if (empty($aData['where'])) {
            $aData['where'] = [];
        }

        $aData['where'][] = [$this->sTableAlias . '.id', $iId];

        $aEmails = $this->getAll(null, null, $aData);

        return !empty($aEmails) ? reset($aEmails) : false;
    }
1183460
protected function getCountCommonCompileFilters(array &$aData)
    {
        /**
         * Handle filters
         * Filters are basically an easy way to modify the query's where element.
         */

        //  Checkbox Filters
        if (!empty($aData['cbFilters'])) {

            foreach ($aData['cbFilters'] as $iFilterIndex => $oFilter) {

                /**
                 * If a column isn't specified by the filter then ignore it. This is a
                 * feature/hack to allow the dev to add items to the search box but not
                 * force them to use the default filtering mechanism
                 */
                if (empty($oFilter->getColumn())) {
                    continue;
                }

                $aWhereFilter = [];
                foreach ($oFilter->getOptions() as $iOptionIndex => $oOption) {
                    if (!empty($_GET['cbF'][$iFilterIndex][$iOptionIndex])) {
                        //  Filtering is happening and the item is to be filtered
                        $aWhereFilter[] = $this->getCountCommonCompileFiltersString(
                            $oFilter->getColumn(),
                            $oOption->getValue(),
                            $oOption->isQuery()
                        );
                    } elseif (empty($_GET['cbF']) && $oOption->isSelected()) {
                        //  There's no filtering happening and the item is checked by default
                        $aWhereFilter[] = $this->getCountCommonCompileFiltersString(
                            $oFilter->getColumn(),
                            $oOption->getValue(),
                            $oOption->isQuery()
                        );
                    }
                }

                $aWhereFilter = array_filter($aWhereFilter);

                if (!empty($aWhereFilter)) {

                    if (!isset($aData['where'])) {
                        $aData['where'] = [];
                    }

                    $aData['where'][] = '(' . implode(' OR ', $aWhereFilter) . ')';
                }
            }
        }

        //  Dropdown Filters
        if (!empty($aData['ddFilters'])) {

            foreach ($aData['ddFilters'] as $iFilterIndex => $oFilter) {

                /**
                 * If a column isn't specified by the filter then ignore it. This is a
                 * feature/hack to allow the dev to add items to the search box but not
                 * force them to use the default filtering mechanism
                 */
                if (empty($oFilter->getColumn())) {
                    continue;
                }

                $sWhereFilter = [];

                //  Are we even filtering this filter?
                if (isset($_GET['ddF'][$iFilterIndex])) {

                    //  Does the option exist, if so, filter by it
                    $iSelectedIndex = !empty((int) $_GET['ddF'][$iFilterIndex]) ? (int) $_GET['ddF'][$iFilterIndex] : 0;
                    $oOption        = $oFilter->getOption($iSelectedIndex);

                    if ($oOption && $oOption->getValue()) {
                        $sWhereFilter = $this->getCountCommonCompileFiltersString(
                            $oFilter->getColumn(),
                            $oOption->getValue(),
                            $oOption->isQuery()
                        );
                    }

                } else {

                    //  No filtering happening but does this item have an item checked by default?
                    foreach ($oFilter->getOptions() as $oOption) {
                        if ($oOption->isSelected()) {
                            $sWhereFilter = $this->getCountCommonCompileFiltersString(
                                $oFilter->getColumn(),
                                $oOption->getValue(),
                                $oOption->isQuery()
                            );
                            break;
                        }
                    }
                }

                if (!empty($sWhereFilter)) {

                    if (!isset($aData['where'])) {
                        $aData['where'] = [];
                    }

                    $aData['where'][] = $sWhereFilter;
                }
            }
        }
    }
1100010
public function load($mView, $aData = [], $bReturn = false)
    {
        if (is_array($mView)) {

            $sOut = '';
            foreach ($mView as $sView) {
                if ($bReturn) {
                    $sOut .= $this->load($sView, $aData, $bReturn);
                } else {
                    $this->load($sView, $aData, $bReturn);
                }
            }
            return $bReturn ? $sOut : $this;

        } elseif (is_string($mView)) {

            $aData = array_merge($this->getData(), (array) $aData);
            ob_start();

            try {
                $sResolvedPath = $this->resolvePath($mView);
            } catch (ViewNotFoundException $e) {
                @ob_end_clean();
                throw $e;
            }

            extract($aData);
            include $sResolvedPath;

            if (!array_key_exists($sResolvedPath, $this->aLoadedViews)) {
                $this->aLoadedViews[$sResolvedPath] = 0;
            }

            $this->aLoadedViews[$sResolvedPath]++;

            if ($bReturn) {
                $sBuffer = ob_get_contents();
                @ob_end_clean();
                return $sBuffer;
            } elseif (ob_get_level() > $this->iBufferLevel + 1) {
                ob_end_flush();
            } else {
                $oOutput = Factory::service('Output');
                $oOutput->append_output(ob_get_contents());
                @ob_end_clean();
            }

            return $this;
        } else {
            return $this;
        }
    }
1154098
public function getByValidToken($sToken, array $aData = [])
    {
        if (!isset($aData['where'])) {
            $aData['where'] = [];
        }

        $aData['where'][] = '(expires IS NULL OR expires > NOW())';

        return $this->getByToken($sToken, $aData);
    }
467012
public function assignArray($aData)
    {
        $this->clear();
        if (count($aData)) {
            $oSaved = clone $this->getBaseObject();

            foreach ($aData as $aItem) {
                $oListObject = clone $oSaved;
                $this->_assignElement($oListObject, $aItem);
                if ($oListObject->getId()) {
                    $this->_aArray[$oListObject->getId()] = $oListObject;
                } else {
                    $this->_aArray[] = $oListObject;
                }
            }
        }
    }
326005
protected function getCountCommon(array $aData = [])
    {
        //  @deprecated - searching should use the search() method, but this in place
        //  as a quick fix for loads of admin controllers
        if (!empty($aData['keywords']) && !empty($this->searchableFields)) {
            if (empty($aData['or_like'])) {
                $aData['or_like'] = [];
            }

            $sAlias = $this->getTableAlias(true);

            foreach ($this->searchableFields as $mField) {

                //  If the field is an array then search across the columns concatenated together
                if (is_array($mField)) {

                    $sMappedFields = array_map(function ($sInput) use ($sAlias) {
                        if (strpos($sInput, '.') !== false) {
                            return $sInput;
                        } else {
                            return $sAlias . $sInput;
                        }
                    }, $mField);

                    $aData['or_like'][] = ['CONCAT_WS(" ", ' . implode(',', $sMappedFields) . ')', $aData['keywords']];

                } else {
                    if (strpos($mField, '.') !== false) {
                        $aData['or_like'][] = [$mField, $aData['keywords']];
                    } else {
                        $aData['or_like'][] = [$sAlias . $mField, $aData['keywords']];
                    }
                }
            }
        }

        // --------------------------------------------------------------------------

        $this->getCountCommonCompileSelect($aData);
        $this->getCountCommonCompileFilters($aData);
        $this->getCountCommonCompileWheres($aData);
        $this->getCountCommonCompileLikes($aData);
        $this->getCountCommonCompileHavings($aData);
        $this->getCountCommonCompileSort($aData);
    }
389941
public function getChildren($iId, $bRecursive = false, array $aData = [])
    {
        $aQueryData = $aData;
        if (!array_key_exists('where', $aQueryData)) {
            $aQueryData['where'] = [];
        }
        $aQueryData['where'][] = ['parent_id', $iId];

        $aChildren = $this->getAll($aQueryData);
        foreach ($aChildren as $oChild) {
            if ($bRecursive) {
                $oChild->children = $this->getChildren($oChild->id, $bRecursive, $aData);
            }
        }
        return $aChildren;
    }
412297
public function getId($iId = null)
    {
        $oInput = Factory::service('Input');
        $iId    = (int) $iId ?: (int) $oInput->get('id');

        if (empty($iId)) {
            throw new ApiException('Invalid Invoice ID', 404);
        }

        $oInvoiceModel = Factory::model('Invoice', 'nails/module-invoice');
        $oInvoice      = $oInvoiceModel->getById($iId, ['expand' => ['customer']]);

        if (empty($oInvoice)) {
            throw new ApiException('Invalid Invoice ID', 404);
        }

        return Factory::factory('ApiResponse', 'nails/module-api')
                      ->setData($this->formatInvoice($oInvoice));
    }
26185
public function getIdAdresse($idEvenement)
    {
        if (!isset($idEvenement)) {
                        return false;
        }
        $idEvenementGroup = $this->getIdGroupeEvenement($idEvenement);
        $requete ="
				SELECT idAdresse
				FROM _adresseEvenement
				WHERE  idEvenement = $idEvenementGroup
				";
        $result = $this->connexionBdd->requete($requete);
        $res = mysql_fetch_assoc($result);
        return $res['idAdresse'];
    }
988357
protected function getCountCommonCompileSort(array &$aData)
    {
        $oDb = Factory::service('Database');

        if (!empty($aData['sort'])) {

            /**
             * How we handle sorting
             * =====================
             *
             * - If $aData['sort'] is a string assume it's the field to sort on, use the default order
             * - If $aData['sort'] is a single dimension array then assume the first element (or the element
             *   named 'column') is the column; and the second element (or the element named 'order') is the
             *   direction to sort in
             * - If $aData['sort'] is a multidimensional array then loop each element and test as above.
             *
             **/

            if (is_string($aData['sort'])) {

                //  String
                $oDb->order_by($aData['sort']);

            } elseif (is_array($aData['sort'])) {

                $mFirst = reset($aData['sort']);

                if (is_string($mFirst)) {

                    //  Single dimension array
                    $aSort = $this->getCountCommonParseSort($aData['sort']);

                    if (!empty($aSort['column'])) {
                        $oDb->order_by($aSort['column'], $aSort['order']);
                    }

                } else {

                    //  Multi dimension array
                    foreach ($aData['sort'] as $sort) {

                        $aSort = $this->getCountCommonParseSort($sort);

                        if (!empty($aSort['column'])) {
                            $oDb->order_by($aSort['column'], $aSort['order']);
                        }
                    }
                }
            }

        }
    }
643364
public function update($sTable, $iUserId, $aData)
    {
        //  Safety: Ensure that the user_id is not overridden
        $aData['user_id'] = $iUserId;

        $oDb = Factory::service('Database');
        $oDb->where('user_id', $iUserId);
        if ($oDb->count_all_results($sTable)) {

            $oDb->set($aData);
            $oDb->where('user_id', $iUserId);
            $bResult = $oDb->update($sTable);

        } else {

            $oDb->set($aData);
            $bResult = $oDb->insert($sTable);
        }

        if ($bResult) {
            $this->unsetCache('user-meta-' . $sTable . '-' . $iUserId);
        }

        return $bResult;
    }
1205494
public function getTitre($idAdresse)
    {
        $requete ="SELECT e2.titre
				FROM evenements e1, evenements e2
				LEFT JOIN _adresseEvenement ae on ae.idEvenement = e1.idEvenement
				WHERE ae.idAdresse = $idAdresse
				AND e2.idEvenement = e1.`idEvenementRecuperationTitre` ";
        $result = $this->connexionBdd->requete($requete);
        $retValue = mysql_fetch_assoc($result);
        return $retValue['titre'];
    }
623665
public function createMany(array $aData)
    {
        $oDb = Factory::service('Database');
        try {
            $oDb->trans_begin();
            foreach ($aData as $aDatum) {
                if (!$this->create($aDatum)) {
                    throw new ModelException('Failed to create item with data: ' . json_encode($aDatum));
                }
            }
            $oDb->trans_commit();
            return true;
        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $this->setError($e->getMessage());
            return false;
        }
    }
106223
public function getByToken($sToken, array $aData = [])
    {
        if (!$this->tableTokenColumn) {
            throw new ModelException(static::class . '::getByToken() Column variable not set.', 1);
        }

        return $this->getByColumn($this->tableTokenColumn, $sToken, $aData);
    }
639348
public function getSearch($aData = [])
    {
        if (!userHasPermission('admin:auth:accounts:browse')) {
            $oHttpCodes = Factory::service('HttpCodes');
            throw new ApiException(
                'You are not authorised to search users',
                $oHttpCodes::STATUS_UNAUTHORIZED
            );
        }

        return parent::getSearch($aData);
    }
36758
protected function getCountCommon(array $aData = [])
    {
        //  Define the selects
        $oDb = Factory::service('Database');
        $oDb->select($this->tableAlias . '.*');
        $oDb->select([
            $this->tableEmailAlias . '.email',
            $this->tableEmailAlias . '.code email_verification_code',
            $this->tableEmailAlias . '.is_verified email_is_verified',
            $this->tableEmailAlias . '.date_verified email_is_verified_on',
        ]);
        $oDb->select($this->getMetaColumns($this->tableMetaAlias));
        $oDb->select([
            $this->tableGroupAlias . '.slug group_slug',
            $this->tableGroupAlias . '.label group_name',
            $this->tableGroupAlias . '.default_homepage group_homepage',
            $this->tableGroupAlias . '.acl group_acl',
        ]);

        // --------------------------------------------------------------------------

        //  Define the joins
        $oDb->join(
            $this->tableEmail . ' ' . $this->tableEmailAlias,
            $this->tableAlias . '.id = ' . $this->tableEmailAlias . '.user_id AND ' . $this->tableEmailAlias . '.is_primary = 1',
            'LEFT'
        );

        $oDb->join(
            $this->tableMeta . ' ' . $this->tableMetaAlias,
            $this->tableAlias . '.id = ' . $this->tableMetaAlias . '.user_id',
            'LEFT'
        );

        $oDb->join(
            $this->tableGroup . ' ' . $this->tableGroupAlias,
            $this->tableAlias . '.group_id = ' . $this->tableGroupAlias . '.id',
            'LEFT'
        );

        //  Let the parent method handle sorting, etc
        parent::getCountCommon($aData);
    }
148768
function get_message($uid, $raw = null)
    {
        if ( $this->stream !== null && $this->stream !== false ) {

            if ( $raw === null ) {
                $raw = $this->options['raw'];
            }

            $raw_header  = imap_fetchheader($this->stream, $uid, FT_UID);
            $raw_body    = imap_body($this->stream, $uid, FT_UID);
            $raw_message = $raw_header . $raw_body;

            if ( $raw ) {
                return $raw_message;
            } else {
                if ( class_exists('Email_Parser') ) {
                    return new Email_Parser($raw_message);
                }
            }

        }
    }