Skip to content

Commit

Permalink
Merge: Destinguish changed jobs in recruiter and admin list.
Browse files Browse the repository at this point in the history
(refs #407)
  • Loading branch information
TiSiE committed Oct 6, 2017
2 parents f5bc459 + c446906 commit 3ea57cd
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 73 deletions.
27 changes: 26 additions & 1 deletion module/Core/src/Core/Entity/AbstractLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ abstract class AbstractLocation extends AbstractEntity implements LocationInterf
public function __construct()
{
}

public function __toString()
{
$coords = $this->getCoordinates();
$postalCode = $this->getPostalCode();
$city = $this->getCity();
$country = $this->getCountry();
$region = $this->getRegion();

$str = '';
if ($postalCode) { $str .= $postalCode . ' '; }
if ($city) { $str .= $city; }
if ($region) { $str .= ', ' . $region; }
if ($country) { $str .= ', ' . $country; }
if ($coords) {
$coords = $coords->getCoordinates();
$str .= ' ( ' . join(', ', $coords) . ' )';
}

return $str;

}

public function toString()
{
Expand Down Expand Up @@ -98,6 +120,9 @@ public function fromString($serialized)
return $this;
}

/**
* @codeCoverageIgnore
*/
public function preUpdate()
{
}
Expand Down Expand Up @@ -193,4 +218,4 @@ public function setRegion($region)
$this->region = $region;
return $this;
}
}
}
2 changes: 2 additions & 0 deletions module/Core/src/Core/Entity/SnapshotInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public function __construct(EntityInterface $source);
*/
public function getSnapshotMeta();

public function getOriginalEntity();

}
28 changes: 0 additions & 28 deletions module/Core/src/Core/Entity/SnapshotMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,4 @@ class SnapshotMeta implements ModificationDateAwareEntityInterface, DraftableEnt
{
use ModificationDateAwareEntityTrait, DraftableEntityTrait;

/**
* @var EntityInterface
* @ODM\ReferenceOne(discriminatorField="_entity", storeAs="dbRef")
*/
protected $entity;

/**
* Sets the entity
*
* @param $entity
* @throws \Core\Exception\ImmutablePropertyException
*/
public function __construct($entity)
{
$this->entity = $entity;
return $this;
}

/**
* Gets the Entity
*
* @return EntityInterface
*/
public function getEntity()
{
return $this->entity;
}

}
36 changes: 27 additions & 9 deletions module/Core/src/Core/Entity/SnapshotTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ trait SnapshotTrait

public function __construct(EntityInterface $source)
{
$this->snapshotMeta = new SnapshotMeta($source);
$this->snapshotMeta = new SnapshotMeta();
$this->snapshotEntity = $source;
}

public function getOriginalEntity()
{
return $this->snapshotEntity;
}

public function getSnapshotMeta()
Expand All @@ -46,13 +52,17 @@ public function getSnapshotAttributes()
return property_exists($this, 'snapshotAttributes') ? $this->snapshotAttributes : [];
}

protected function proxy()
/**
*
*
* @param string $method
* @param mixed[] ...$args Arguments to be passed to proxied method.
*
* @return SnapshotTrait
*/
protected function proxy($method, ...$args)
{
/* @var SnapshotMeta $meta */
$args = func_get_args();
$method = array_shift($args);
$meta = $this->getSnapshotMeta();
$entity = $meta->getEntity();
$entity = $this->getOriginalEntity();
$callback = [$entity, $method];

if (!is_callable($callback)) {
Expand All @@ -62,11 +72,19 @@ protected function proxy()
));
}

$return = call_user_func_array($callback, $args);
$return = $callback(...$args);

return $return === $entity ? $this : $return;
}

protected function proxyClone($method, ...$args)
{
$value = $this->proxy($method, ...$args);
$return = is_object($value) ? clone $value : $value;

return $return;
}

protected function inaccessible($property)
{
throw new \DomainException(sprintf(
Expand All @@ -79,4 +97,4 @@ protected function immutable($property)
{
throw new ImmutablePropertyException($property, $this);
}
}
}
63 changes: 44 additions & 19 deletions module/Core/src/Core/Repository/SnapshotRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Core\Entity\Collection\ArrayCollection;
use Core\Entity\EntityInterface;
use Core\Entity\Hydrator\EntityHydrator;
use Core\Entity\IdentifiableEntityInterface;
use Core\Entity\SnapshotAttributesProviderInterface;
use Core\Entity\SnapshotInterface;
use Doctrine\Common\Collections\Collection;
Expand Down Expand Up @@ -115,8 +116,6 @@ public function getSnapshotAttributes()
return $this->snapshotAttributes;
}



public function create(EntityInterface $source, $persist = true)
{

Expand All @@ -132,38 +131,64 @@ public function create(EntityInterface $source, $persist = true)
return $snapshot;
}

protected function copy($source, $target, $attributes = null)
protected function copy($source, $target, $inverse = false)
{
if (!$attributes) {
if ($source instanceOf SnapshotAttributesProviderInterface) {
$attributes = $source->getSnapshotAttributes();
} else if ($target instanceOf SnapshotAttributesProviderInterface) {
$attributes = $target->getSnapshotAttributes();
} else {
$attributes = $this->getSnapshotAttributes();
}
if ($inverse) {
$attributes = $this->getCopyAttributes($target, $source);
$sourceHydrator = $this->getHydrator();
$targetHydrator = $this->getSourceHydrator();
} else {
$attributes = $this->getCopyAttributes($source, $target);
$sourceHydrator = $this->getSourceHydrator();
$targetHydrator = $this->getHydrator();
$source = clone $source;
}

$data = $this->getSourceHydrator()->extract(clone $source);

$data = $sourceHydrator->extract($source);
$data = array_intersect_key($data, array_flip($attributes));
$this->getHydrator()->hydrate($data, $target);
$targetHydrator->hydrate($data, $target);
}

protected function getCopyAttributes($source, $target)
{
if ($source instanceOf SnapshotAttributesProviderInterface) {
return $source->getSnapshotAttributes();
}

if ($target instanceOf SnapshotAttributesProviderInterface) {
return $target->getSnapshotAttributes();
}

return $this->getSnapshotAttributes();
}

public function merge(SnapshotInterface $snapshot)
public function merge(SnapshotInterface $snapshot, $snapshotDraftStatus = false)
{
$this->checkEntityType($snapshot);

$entity = $snapshot->getSnapshotMeta()->getEntity();
$meta = $snapshot->getSnapshotMeta();
$entity = $snapshot->getOriginalEntity();

$this->copy($snapshot, $entity);
$meta->setIsDraft((bool) $snapshotDraftStatus);

$this->copy($snapshot, $entity, true);

return $entity;
}

public function diff(SnapshotInterface $snapshot)
{
$entity = $snapshot->getEntity();
$attributes = $this->getCopyAttributes($entity, $snapshot);


}

public function findLatest($sourceId, $isDraft = false)
{
return $this->createQueryBuilder()
->field('snapshotMeta.entity.$id')->equals(new \MongoId($sourceId))
->field('snapshotEntity')->equals(new \MongoId($sourceId))
->field('snapshotMeta.isDraft')->equals($isDraft)
->sort('snapshotMeta.dateCreated.date', 'desc')
->limit(1)
Expand All @@ -174,7 +199,7 @@ public function findLatest($sourceId, $isDraft = false)

public function findBySourceId($sourceId, $includeDrafts = false)
{
$criteria = ['snapshotMeta.entity.$id' => $sourceId];
$criteria = ['snapshotEntity' => $sourceId];

if (!$includeDrafts) {
$criteria['snapshotMeta.isDraft'] = false;
Expand Down Expand Up @@ -255,4 +280,4 @@ protected function extract($source, array $attributes = [])

return $hydrate;
}
}
}
51 changes: 50 additions & 1 deletion module/Core/test/CoreTest/Entity/AbstractLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function setup()
$this->target = new ConcreteLocation();
}

private function setTargetLocationAttributes()
{
$this->target
->setPostalCode('9999')
->setCity('XXXX')
->setRegion('YYYY')
->setCountry('ZZZZ')
->setCoordinates(new Point([10,20]));
}

/**
* @testdox Extends \Core\Entity\LocationEntity and implements \Core\Entity\LocationInterface
* @coversNothing
Expand Down Expand Up @@ -105,4 +115,43 @@ public function testSettingAndGettingTheCoordinates()

$this->assertEquals($coordinates, $this->target->getCoordinates());
}
}

public function testStringRepresentation()
{
$this->setTargetLocationAttributes();

$expect = "9999 XXXX, YYYY, ZZZZ ( 10, 20 )";

$this->assertEquals($expect, $this->target->__toString());
}

public function testConvertToAndFromJson()
{
if (false === (@include_once __DIR__ . '/../../../../Geo/src/Geo/Entity/Geometry/Point.php')) {
$this->assertTrue(true);
return;
}
$this->setTargetLocationAttributes();

$expect = json_encode([
'city' => 'XXXX',
'region' => 'YYYY',
'postalCode' => '9999',
'country' => 'ZZZZ',
'coordinates' => [
'type' => 'Point',
'coordinates' => [10, 20],
]

]);
$json = $this->target->toString();
$this->assertEquals($expect, $json, 'Convert to json did not work');

$this->target = new ConcreteLocation();
$this->target->fromString($json);

$expect = "9999 XXXX, YYYY, ZZZZ ( 10, 20 )";

$this->assertEquals($expect, $this->target->__toString(), 'Convert from json did not work');
}
}
4 changes: 2 additions & 2 deletions module/Jobs/src/Jobs/Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function completionAction()
$jobEvents = $this->jobEvents;
$jobEvents->trigger(JobEvent::EVENT_JOB_CREATED, $this, array('job' => $job));
} else if ($job->isActive()) {
$job->getSnapshotMeta()->getEntity()->changeStatus(Status::WAITING_FOR_APPROVAL, 'job was edited.');
$job->getOriginalEntity()->changeStatus(Status::WAITING_FOR_APPROVAL, 'job was edited.');
}

/* @var \Auth\Controller\Plugin\UserSwitcher $switcher */
Expand Down Expand Up @@ -579,7 +579,7 @@ public function approvalAction()
return $this->redirect()->toRoute('lang/admin/jobs', array('lang' => $this->params('lang')));
}

$query = $jobEntity instanceOf JobSnapshot ? ['snapshot' => $jobEntity->getSnapshotId()] : ['id' => $jobEntity->getId()];
$query = /*$jobEntity instanceOf JobSnapshot ? ['snapshot' => $jobEntity->getSnapshotId()] : */['id' => $jobEntity->getId()];
$viewLink = $this->url()->fromRoute(
'lang/jobs/view',
array(),
Expand Down
30 changes: 30 additions & 0 deletions module/Jobs/src/Jobs/Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,36 @@ class Job extends BaseEntity implements JobInterface,
*/
protected $isDeleted = false;

/**
*
* @ODM\ReferenceMany(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", sort={"snapshotMeta.dateCreated"="desc"})
* @var JobSnapshot
*/
protected $snapshots;

/**
* @ODM\ReferenceOne(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", criteria={"snapshotMeta.isDraft":true}, sort={"snapshotMeta.dateCreated"="desc"})
*
* @var
*/
protected $latestSnapshotDraft;


public function getSnapshots()
{
return $this->snapshots;
}

public function getSnapshotDraft()
{
return $this->latestSnapshotDraft;
}

public function hasSnapshotDraft()
{
return (bool) $this->getSnapshotDraft();
}

/**
* @return string
*/
Expand Down
Loading

0 comments on commit 3ea57cd

Please sign in to comment.