Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job improved import #443

Merged
merged 3 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class TreeSelectStrategy implements StrategyInterface
*/
private $allowSelectMultipleItems = false;

private $shouldCreateLeafs = false;

/**
* Set the selected leafs.
*
Expand Down Expand Up @@ -121,6 +123,20 @@ public function allowSelectMultipleItems()
return is_callable($flagOrCallback) ? (bool) $flagOrCallback() : (bool) $flagOrCallback;
}

public function setShouldCreateLeafs($flagOrCallback)
{
$this->shouldCreateLeafs = $flagOrCallback;

return $this;
}

public function shouldCreateLeafs()
{
$flagOrCallback = $this->shouldCreateLeafs;

return is_callable($flagOrCallback) ? (bool) $flagOrCallback() : (bool) $flagOrCallback;
}

public function extract($value)
{
if (empty($value)) {
Expand Down Expand Up @@ -197,6 +213,17 @@ private function findLeaf(NodeInterface $leaf, $value)
}
}

if ($this->shouldCreateLeafs()) {
$nodeClass = get_class($leaf);
$node = new $nodeClass($value);
$leaf->addChild($node);
if (count($parts)) {
return $this->findLeaf($node, $parts);
}

return $node;
}

return null;
}
}
}
1 change: 1 addition & 0 deletions module/Jobs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
]],

'Jobs/Events' => [
'service' => 'Core/EventManager',
'event' => '\Jobs\Listener\Events\JobEvent',
],

Expand Down
37 changes: 24 additions & 13 deletions module/Jobs/src/Jobs/Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,34 @@ public function saveAction()
$jobLocations->add($location);
}
}

/* @var \Core\EventManager\EventManager $jobEvents
* @var JobEvent $jobEvent */
$jobEvents = $services->get('Jobs/Events');
$jobEvent = $jobEvents->getEvent(JobEvent::EVENT_IMPORT_DATA, $this);
$jobEvent->setJobEntity($entity);

$extra = [];
foreach (array('channels', 'position', 'branches', 'keywords', 'description') as $paramName) {
$data = $params->get($paramName);
if ($data) {
$data = Json::decode($data, Json::TYPE_ARRAY);
$extra[$paramName] = $data;
$jobEvent->setParam($paramName, $data);
}
}

$jobEvents->triggerEvent($jobEvent);
$repositoriesJob->store($entity);

$id = $entity->getId();
if (!empty($id)) {
$jobEvent = $services->get('Jobs/Event');
$jobEvent = $services->get('Jobs/Event'); // intentinally override
$jobEvent->setJobEntity($entity);

$extra = [];
foreach (array('channels', 'positions', 'branches', 'keywords', 'description') as $paramName) {
$data = $params->get($paramName);
if ($data) {
$data = Json::decode($data, Json::TYPE_ARRAY);
if ('channels' == $paramName) {
foreach (array_keys($data) as $portalName) {
$jobEvent->addPortal($portalName);
}
}

$extra[$paramName] = $data;
if (isset($extra['channels'])) {
foreach ($extra['channels'] as $portalName => $trash) {
$jobEvent->addPortal($portalName);
}
}
$jobEvent->setParam('extraData', $extra);
Expand All @@ -226,6 +236,7 @@ public function saveAction()
$jobEvent->setName(JobEvent::EVENT_JOB_ACCEPTED);
$jobEvent->setTarget($this);
$responses = $jobEvents->triggerEvent($jobEvent);

foreach ($responses as $response) {
// responses from the portals
// @TODO, put this in some conclusion and meaningful messages
Expand Down
7 changes: 5 additions & 2 deletions module/Jobs/src/Jobs/Listener/Events/JobEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ class JobEvent extends Event
/** Event is fired, when the status of an job has changed. */
const EVENT_STATUS_CHANGED = 'job.status-changed';

const EVENT_IMPORT_DATA = 'job.import-data';

/**
* get all available names for publishing
*/
const PORTAL_AVAIL_NAME = 'portal.availname';

/**
* @var portals to be published
* portals to be published
* @var array
*/
protected $portals = array();

Expand All @@ -66,7 +69,7 @@ class JobEvent extends Event
* Sets the job entity
*
* @param Job $jobEntity
* @return MvcEvent
* @return self
*/
public function setJobEntity(Job $jobEntity)
{
Expand Down