PHP code example of cristiannores / suite-ctrm-generator

1. Go to this page and download the library: Download cristiannores/suite-ctrm-generator 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/ */

    

cristiannores / suite-ctrm-generator example snippets


if (!$driver) {
  $this->adapter = new Zend\Db\Adapter\Adapter([
    'driver' => 'Pdo',
    'dsn'    => 'mysql:dbname=test;host=localhost;charset=utf8',
    'username' => 'root',
    'password' => '', 
    'options' => array(
    'buffer_results' => true,
  )]);
}            

$GLOBALS['suite_crm_path'] = '/var/www/suite/public_html';       

$mapperContacts = new ContactsMapper();

// Guardando contactos
$mapperContacts->store($data);

// Obteniendo contacto por id
$mapperContacts->get($id);

// Actualizando contacto por id
$mapperContacts->update($contact, $id);

 // Encontrando un contacto por parametros
$mapperContacts->findOneBy($find);

// Encontrando  muchos contactos por parametro
$mapperContacts->findManyBy($data);

// Borrando un contacto 
$mapperContacts->delete($id);

// Obteniendo todos los contactos un contacto 
$mapperContacts->getAll();

// Get adapter
$database = new Database();
$adapter = $database->getAdapter();        

try {

    // Iniciando transaccion
    $adapter->getDriver()->getConnection()->beginTransaction();

    $mapperContacts = new ContactsMapper($adapter);
    $mapperEmailAddresses = new EmailAddressesMapper($adapter);

    $contact_id = $mapperContacts->store($contacto);
    $email_id = $mapperEmailAddresses->store($email);

    if ($contact_id && $email_id) {
        $asignado = $mapperEmailAddresses->assignToContact($contact_id, $email_id);

        if ($asignado) {

            // Commit
            $adapter->getDriver()->getConnection()->commit();

        } else {

            // rollback
            $adapter->getDriver()->getConnection()->rollback();
        }
    } else {

        // rollback
        $adapter->getDriver()->getConnection()->rollback();

    }        

} catch (Exception $exc) {

    // rollback
    $adapter->getDriver()->getConnection()->rollback();

} catch (\Zend\Db\Adapter\Exception\ErrorException $ex) {

    // rollback
    $adapter->getDriver()->getConnection()->rollback();

} catch (Zend\Db\Adapter\Exception\RuntimeException $ex) {

    // rollback
    $adapter->getDriver()->getConnection()->rollback();           

}
bash
php generate.php
bash
php generate.php run 
bash
php generate.php run --all