Source of file NewsletterTrackedLink.php
Size: 1,190 Bytes - Last Modified: 2021-12-23T10:33:22+00:00
/var/www/docs.ssmods.com/process/src/src/Model/NewsletterTrackedLink.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php namespace SilverStripe\Newsletter\Model; use SilverStripe\ORM\DataObject; class NewsletterTrackedLink extends DataObject { private static $db = [ 'Original' => 'Varchar(255)', 'Hash' => 'Varchar(100)', 'Visits' => 'Int' ]; private static $has_one = [ 'Newsletter' => Newsletter::class ]; private static $summary_fields = [ "Newsletter.Subject" => "Newsletter", "Original" => "Link URL", "Visits" => "Visit Counts" ]; private static $table_name = 'NewsletterTrackedLink'; private static $singular_name = 'Tracked Link'; private static $plural_name = 'Tracked Links'; /** * Generate a unique hash */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Hash) { $this->Hash = md5(time() + rand()); } } /** * Return the full link to the hashed url, not the actual link location. * * @return string */ public function Link() { if (!$this->Hash) { $this->write(); } return Controller::join_links('newsletterlinks/'. $this->Hash); } } |