Skip to content

Commit

Permalink
Add entity
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Nov 20, 2019
1 parent df3a301 commit 009e692
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 0 deletions.
215 changes: 215 additions & 0 deletions Entity/CustomLog.php
@@ -0,0 +1,215 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace MauticPlugin\MauticCustomReportBundle\Entity;

use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping as ORM;
use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Entity\LeadEventLog;

class CustomLog
{
/**
* @var int
*/
protected $id;

/**
* @var \DateTime
*/
protected $dateAdded;

/**
* @var string
*/
protected $url;

/**
* @var Lead
*/
protected $lead;

/**
* @var LeadEventLog
*/
protected $log;


public function __construct()
{
$this->setDateAdded(new \DateTime());
}

/**
* @param ORM\ClassMetadata $metadata
*/
public static function loadMetadata(ORM\ClassMetadata $metadata)
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable('custom_contact_log')
->setCustomRepositoryClass(CustomLogRepository::class)
->addId()
->addIndex(['url', 'date_added'], 'url_date_added')
->addIndex(['date_added'], 'date_added');

$builder->createManyToOne(
'lead',
'Mautic\LeadBundle\Entity\Lead'
)->addJoinColumn('lead_id', 'id', true, false, 'SET NULL')
->cascadePersist()
->build();

$builder->createManyToOne(
'log',
'Mautic\LeadBundle\Entity\LeadEventLog'
)->addJoinColumn('log_id', 'id', true, false, 'SET NULL')
->cascadePersist()
->build();

$builder->addField('url', Type::STRING, ['length' => 728]);
$builder->addNamedField('dateAdded', 'datetime', 'date_added');

}


/**
* Prepares the metadata for API usage.
*
* @param $metadata
*/
public static function loadApiMetadata(ApiMetadataDriver $metadata)
{
$metadata->setGroupPrefix('custom_log')
->addListProperties(
[
'id',
'dateAdded',
]
)
->build();
}


/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}

/*
* Set dateAdded.
*
* @param \DateTime $dateAdded
*
* @return LeadEventLog
*/
public function setDateAdded($dateAdded)
{
$this->dateAdded = $dateAdded;

return $this;
}

/**
* Get dateAdded.
*
* @return \DateTime
*/
public function getDateAdded()
{
return $this->dateAdded;
}


public function getCreatedBy()
{

}

public function getHeader()
{

}

public function getPublishStatus()
{

}

/**
* @param string $url
*
* @return CustomLog
*/
public function setUrl($url)
{
$this->url = $url;

return $this;
}

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

/**
* @param Lead $lead
*
* @return CustomLog
*/
public function setLead($lead)
{
$this->lead = $lead;

return $this;
}

/**
* @return Lead
*/
public function getLead()
{
return $this->lead;
}

/**
* @param LeadEventLog $log
*
* @return CustomLog
*/
public function setLog($log)
{
$this->log = $log;

return $this;
}

/**
* @return LeadEventLog
*/
public function getLog()
{
return $this->log;
}


}
18 changes: 18 additions & 0 deletions Entity/CustomLogRepository.php
@@ -0,0 +1,18 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace MauticPlugin\MauticCustomReportBundle\Entity;

use Mautic\CoreBundle\Entity\CommonRepository;

class CustomLogRepository extends CommonRepository
{
}
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,10 @@
3. Clear cache (app/cache/prod/)
4. Go to /s/plugins/reload

### Command to sync

php /app/console mautic:source:created:contacts:migration

## More Mautic stuff

- Plugins from Mautic Extendee Family https://mtcextendee.com/plugins
Expand Down

0 comments on commit 009e692

Please sign in to comment.