PHP code example of heimrichhannot / contao-privacy

1. Go to this page and download the library: Download heimrichhannot/contao-privacy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heimrichhannot / contao-privacy example snippets


class MyModule {
    // ...
    public function compile() {
        // this represents your function for sending the opt in email
        $success = $this->sendOptInEmail($firstname, $lastname, $email);

        // only create a protocol entry if the email has indeed been sent
        if ($success)
        {
            $protocolManager = new \HeimrichHannot\Privacy\Manager\ProtocolManager();
            $protocolManager->addEntryFromModule(
                // the type of action
                \HeimrichHannot\Privacy\Backend\ProtocolEntry::TYPE_FIRST_OPT_IN,
                // the id of your destination protocol archive
                1,
                // the data you want to add to the protocol entry to be created
                // CAUTION: Do NOT store personal data for which you don't have the user's permission!
                [
                    'firstname' => $firstname,
                    'lastname'  => $lastname,
                    'email'     => $email
                ],
                // the \Contao\Module instance you're calling from
                $this,
                // optional: composer package name of the bundle your module lives in (version is retrieved automatically from composer.lock)
                'acme/contao-my-bundle'
            );
        }
    }
    // ...
}

class MyContentElement {
    // ...
    public function compile() {
        // this represents your function for sending the opt in email
        $success = $this->sendOptInEmail($firstname, $lastname, $email);

        // only create a protocol entry if the email has indeed been sent
        if ($success)
        {
            $protocolManager = new \HeimrichHannot\Privacy\Manager\ProtocolManager();
            $protocolManager->addEntryFromContentElement(
                // the type of action
                \HeimrichHannot\Privacy\Backend\ProtocolEntry::TYPE_FIRST_OPT_IN,
                // the id of your destination protocol archive
                1,
                // the data you want to add to the protocol entry to be created
                // CAUTION: Do NOT store personal data for which you don't have the user's permission!
                [
                    'firstname' => $firstname,
                    'lastname'  => $lastname,
                    'email'     => $email
                ],
                // the \Contao\ContentElement instance you're calling from
                $this,
                // optional: composer package name of the bundle your content element lives in (version is retrieved automatically from composer.lock)
                'acme/contao-my-bundle'
            );
        }
    }
    // ...
}

class MyClass {
    // ...
    public function someFunction() {
        // this represents your function for sending the opt in email
        $success = $this->sendOptInEmail($firstname, $lastname, $email);

        // only create a protocol entry if the email has indeed been sent
        if ($success)
        {
            $protocolManager = new \HeimrichHannot\Privacy\Manager\ProtocolManager();
            $protocolManager->addEntry(
                // the type of action
                \HeimrichHannot\Privacy\Backend\ProtocolEntry::TYPE_FIRST_OPT_IN,
                // the id of your destination protocol archive
                1,
                // the data you want to add to the protocol entry to be created
                // CAUTION: Do NOT store personal data for which you don't have the user's permission!
                [
                    'firstname' => $firstname,
                    'lastname'  => $lastname,
                    'email'     => $email
                ],
                // optional: composer package name of the bundle your code lives in (version is retrieved automatically from composer.lock)
                'acme/contao-my-bundle'
            );
        }
    }
    // ...
}