-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement purposes of processing personal data (#6)
- Loading branch information
1 parent
460952d
commit 2900ddb
Showing
7 changed files
with
268 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace SmartEmailing\v3\Request\Import\Holder; | ||
|
||
use SmartEmailing\v3\Models\AbstractMapHolder; | ||
use SmartEmailing\v3\Request\Import\Purpose; | ||
|
||
class Purposes extends AbstractMapHolder | ||
{ | ||
/** | ||
* Inserts purposes into the items. Unique items only. | ||
* | ||
* @param Purpose $list | ||
* | ||
* @return $this | ||
*/ | ||
public function add(Purpose $list) | ||
{ | ||
$this->insertEntry($list); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Creates Purpose entry and inserts it to the array | ||
* | ||
* @param int $id | ||
* @param string|null $valid_from Date and time since processing purpose is valid in YYYY-MM-DD HH:MM:SS format. | ||
* If empty, current date and time will be used. | ||
* @param string|null $valid_to Date and time of processing purpose validity end in YYYY-MM-DD HH:MM:SS format. | ||
* If empty, it will be calculated as valid_from + default duration of particular | ||
* purpose. | ||
* | ||
* @return Purpose | ||
*/ | ||
public function create($id, $valid_from = null, $valid_to = null) | ||
{ | ||
$field = new Purpose($id, $valid_from, $valid_to); | ||
$this->add($field); | ||
return $field; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
namespace SmartEmailing\v3\Request\Import; | ||
|
||
use SmartEmailing\v3\Exceptions\InvalidFormatException; | ||
use SmartEmailing\v3\Models\Model; | ||
|
||
/** | ||
* Processing purposes assigned to contact. Every purpose may be assigned multiple times for different | ||
* time intervals. Exact duplicities will be silently skipped. | ||
* @package SmartEmailing\v3\Request\Import | ||
*/ | ||
class Purpose extends Model | ||
{ | ||
/** | ||
* @var int|null | ||
*/ | ||
public $id; | ||
/** | ||
* Date and time since processing purpose is valid in YYYY-MM-DD HH:MM:SS format. If empty, current date | ||
* and time will be used. | ||
* @var string Default value: null | ||
*/ | ||
public $valid_from = null; | ||
|
||
/** | ||
* Date and time of processing purpose validity end in YYYY-MM-DD HH:MM:SS format. If empty, it will be | ||
* calculated as valid_from + default duration of particular purpose. | ||
* @var string Default value: null | ||
*/ | ||
public $valid_to = null; | ||
|
||
/** | ||
* Purpose constructor. | ||
* | ||
* @param int $id | ||
* @param string|null $valid_from Default value: null | ||
* @param string|null $valid_to Default value: null | ||
*/ | ||
public function __construct($id, $valid_from = null, $valid_to = null) | ||
{ | ||
$this->setId($id); | ||
|
||
if (!is_null($valid_from)) { | ||
$this->setValidFrom($valid_from); | ||
} | ||
|
||
if (!is_null($valid_to)) { | ||
$this->setValidTo($valid_to); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return Purpose | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = intval($id); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Date and time since processing purpose is valid. Allowed format: YYYY-MM-DD HH:MM:SS. | ||
* | ||
* @param string $valid_from | ||
* | ||
* @return Purpose | ||
*/ | ||
public function setValidFrom($valid_from) | ||
{ | ||
if(!preg_match('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', $valid_from)) | ||
throw new InvalidFormatException(sprintf('Invalid date and time format. Format must be YYYY-MM-DD HH:MM:SS, %s given.', $valid_from)); | ||
|
||
$this->valid_from = $valid_from; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Date and time of processing purpose validity end. Allowed format: YYYY-MM-DD HH:MM:SS. | ||
* | ||
* @param string $valid_to | ||
* | ||
* @return Purpose | ||
*/ | ||
public function setValidTo($valid_to) | ||
{ | ||
if(!preg_match('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', $valid_to)) | ||
throw new InvalidFormatException(sprintf('Invalid date and time format. Format must be YYYY-MM-DD HH:MM:SS, %s given.', $valid_to)); | ||
|
||
$this->valid_to = $valid_to; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* Converts data to array | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'valid_from' => $this->valid_from, | ||
'valid_to' => $this->valid_to | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
// Don't remove null/empty values - not needed | ||
return $this->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
namespace SmartEmailing\v3\Tests\Request\Import; | ||
|
||
use SmartEmailing\v3\Request\Import\Purpose; | ||
use SmartEmailing\v3\Tests\TestCase\BaseTestCase; | ||
|
||
class PurposeTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var Purpose | ||
*/ | ||
protected $field; | ||
|
||
protected function setUp() | ||
{ | ||
$this->field = new Purpose(12); | ||
} | ||
|
||
public function testConstruct() | ||
{ | ||
$this->assertEquals(12, $this->field->id); | ||
} | ||
|
||
public function testConstructNumeric() | ||
{ | ||
$this->assertEquals(13, (new Purpose('13'))->id); | ||
} | ||
|
||
public function testSetIdNumeric() | ||
{ | ||
$this->assertEquals(13, $this->field->setId('13')->id); | ||
} | ||
|
||
public function testSetValidFrom() | ||
{ | ||
$this->assertEquals('1991-06-17 00:00:00', $this->field->setValidFrom('1991-06-17 00:00:00')->valid_from); | ||
} | ||
|
||
public function testSetValidTo() | ||
{ | ||
$this->assertEquals('1991-06-17 00:00:00', $this->field->setValidTo('1991-06-17 00:00:00')->valid_to); | ||
} | ||
|
||
public function testDateTimeFormat() | ||
{ | ||
try { | ||
$this->field->setValidFrom('1991-06-17'); | ||
$this->fail('The options should require format YYYY-MM-DD HH:MM:SS'); | ||
} catch (\Exception $exception) { | ||
$this->assertContains('Invalid date and time format', $exception->getMessage()); | ||
} | ||
|
||
try { | ||
$this->field->setValidFrom('test'); | ||
$this->fail('The options should require format YYYY-MM-DD HH:MM:SS'); | ||
} catch (\Exception $exception) { | ||
$this->assertContains('Invalid date and time format', $exception->getMessage()); | ||
} | ||
} | ||
} |