Introduced toggable objects

This commit is contained in:
2019-06-01 12:31:10 +02:00
parent c9ef6f1e72
commit 027a81c170
7 changed files with 122 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ namespace Magdev\Dossier\Model\CurriculumVitae;
use Magdev\Dossier\Model\AbstractModel;
use Magdev\Dossier\Model\Traits\PhotoTrait;
use Magdev\Dossier\Model\Traits\ToggableTrait;
use Mni\FrontYAML\Document;
use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Analyzer\Base\AnalyzableInterface;
@@ -46,6 +47,7 @@ use Magdev\Dossier\Model\Base\PhotoInterface;
final class Entry extends BaseModel implements PhotoInterface, AnalyzableInterface
{
use PhotoTrait;
use ToggableTrait;
/**
* Start date

View File

@@ -371,7 +371,10 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
foreach ($value as $type => $address) {
if ($type == 'accounts' && is_array($address)) {
foreach ($address as $a) {
$this->contacts->append(new Contact($a['address'], $a['type']));
$contact = new Contact($a['address'], $a['type'], $a['active']);
if ($contact->isActive()) {
$this->contacts->append($contact);
}
}
} else {
$this->contacts->append(new Contact($address, $type));
@@ -379,7 +382,10 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
}
} else if ($key == 'references') {
foreach ($value as $reference) {
$this->references->append(new Reference($reference));
$ref = new Reference($reference);
if ($ref->isActive()) {
$this->references->append($ref);
}
}
} else {
$this->setProperty($key, $value);

View File

@@ -30,6 +30,8 @@
namespace Magdev\Dossier\Model\Person;
use Magdev\Dossier\Model\Traits\ToggableTrait;
/**
* Contact model
*
@@ -37,6 +39,8 @@ namespace Magdev\Dossier\Model\Person;
*/
class Contact
{
use ToggableTrait;
/**
* Contact address
* @var string
@@ -55,11 +59,13 @@ class Contact
*
* @param string $address
* @param string $type
* @param bool $active
*/
public function __construct(string $address, string $type)
public function __construct(string $address, string $type, ?bool $active = true)
{
$this->address = $address;
$this->type = $type;
$this->active = $active;
}

View File

@@ -31,6 +31,7 @@
namespace Magdev\Dossier\Model\Person;
use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Model\Traits\ToggableTrait;
/**
* Model for job references
@@ -39,6 +40,8 @@ use Magdev\Dossier\Model\Base\BaseModel;
*/
class Reference extends BaseModel
{
use ToggableTrait;
/**
* Reference description
* @var string

View File

@@ -31,6 +31,7 @@
namespace Magdev\Dossier\Model;
use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Model\Traits\ToggableTrait;
use Mni\FrontYAML\Document;
/**
@@ -40,6 +41,8 @@ use Mni\FrontYAML\Document;
*/
class Project extends BaseModel
{
use ToggableTrait;
/**
* Project name
* @var string

View File

@@ -0,0 +1,91 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2019 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Model\Traits;
/**
* Trait for objects which can be de-/activated
*
* @author magdev
*/
trait ToggableTrait
{
/**
* @var bool
*/
protected $active = true;
/**
* Activate object
*
* @return self
*/
public function activate(): self
{
$this->active = true;
return self;
}
/**
* Deactivate object
*
* @return self
*/
public function deactivate(): self
{
$this->active = false;
return $this;
}
/**
* Toggle current activation status
*
* @return self
*/
public function toggle(): self
{
$this->active = !$this->active;
return $this;
}
/**
* Check if object is activated
*
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
}

View File

@@ -108,7 +108,10 @@ class MarkdownService
foreach ($files as $file) {
/* @var $file \SplFileInfo */
$document = $this->getDocument($file->getPathname());
$cv->append(new CurriculumVitae\Entry($document));
$entry = new CurriculumVitae\Entry($document);
if ($entry->isActive()) {
$cv->append($entry);
}
}
$cv->setSortDirection($sort)->sort();
@@ -117,7 +120,10 @@ class MarkdownService
foreach ($files as $file) {
/* @var $file \SplFileInfo */
$document = $this->getDocument($file->getPathname());
$projects->append(new Project($document));
$project = new Project($document);
if ($project->isActive()) {
$projects->append($project);
}
}