Skip to content

Commit

Permalink
Merge branch 'feature/grab_portal_drop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-weitz-cross-solutions committed May 27, 2015
2 parents eb61733 + 0294039 commit 034df14
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 32 deletions.
1 change: 1 addition & 0 deletions module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
'Core/Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'Core/ErrorLogger' => 'Core\Log\ErrorLoggerFactory',
'Core/JsonEntityHydrator' => 'Core\Entity\Hydrator\JsonEntityHydratorFactory',
'Core/EntityHydrator' => 'Core\Entity\Hydrator\EntityHydratorFactory',
'Core/Options' => 'Core\Factory\ModuleOptionsFactory',
),
'abstract_factories' => array(
Expand Down
40 changes: 40 additions & 0 deletions module/Core/src/Core/Entity/Hydrator/EntityHydratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
* @author weitz@cross-solution.de
*/

namespace Core\Entity\Hydrator;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class EntityHydratorFactory implements FactoryInterface
{
protected $hydrator;

/**
* Create the Json Entity Hydrator
*
* @param ServiceLocatorInterface $serviceLocator
* @return JsonEntityHydrator
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$this->hydrator = $this->getEntityHydrator();
$this->prepareHydrator();
return $this->hydrator;
}

protected function prepareHydrator() {
}

protected function getEntityHydrator() {
return new EntityHydrator();
}

}
17 changes: 5 additions & 12 deletions module/Core/src/Core/Service/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct($uri, array $config)
'encodecookies' => False,
'outputstream' => False,
'httpversion' => Request::VERSION_11,
'storeresponse' => False
'storeresponse' => False,
'maxredirects' => 2
),
$config);

Expand Down Expand Up @@ -88,16 +89,8 @@ public function getRequest()
* @return mixed
*/
protected function authetificate() {
if (!array_key_exists('PHP_AUTH_USER', $this->config)) {
throw new \RuntimeException('PHP_AUTH_USER missing', 500);
}
if (!array_key_exists('PHP_AUTH_PW', $this->config)) {
throw new \RuntimeException('PHP_AUTH_PW missing', 500);
}

$auth = $this->config['PHP_AUTH_USER'];
$pw = $this->config['PHP_AUTH_PW'];
unset($this->config['PHP_AUTH_USER'], $this->config['PHP_AUTH_PW']);
return $this->setAuth($auth, $pw);
$auth = array_key_exists('user', $this->config)?$this->config['user']:'';
$pass = array_key_exists('pass', $this->config)?$this->config['pass']:'';
return $this->setAuth($auth, $pass);
}
}
27 changes: 27 additions & 0 deletions module/Jobs/src/Jobs/Entity/Hydrator/JobsEntityHydratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
* @author weitz@cross-solution.de
*/

namespace Jobs\Entity\Hydrator;

use Core\Entity\Hydrator\EntityHydratorFactory;

/**
* Class JsonJobsEntityHydratorFactory
* @package Jobs\Entity\Hydrator
*/
class JobsEntityHydratorFactory extends EntityHydratorFactory
{
/**
*
*/
protected function prepareHydrator() {
$this->hydrator->setExcludeMethods(array('user', 'applications', 'termsAccepted', 'atsEnabled', 'permissions'));;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class JsonJobsEntityHydratorFactory extends JsonEntityHydratorFactory
*
*/
protected function prepareHydrator() {
$this->hydrator->setExcludeMethods(array('user', 'applications', 'termsAccepted', 'atsEnabled', 'permissions', 'portals'));;
$this->hydrator->setExcludeMethods(array('user', 'applications', 'termsAccepted', 'atsEnabled', 'permissions'));;
}
}
40 changes: 25 additions & 15 deletions module/Jobs/src/Jobs/Factory/Service/JobsPublisherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,35 @@ class JobsPublisherFactory extends RestClientFactory

protected function getUri() {
$config = $this->getConfig();
if (!array_key_exists('uri', $config)) {
throw new \RuntimeException('uri for Rest-Server YAWIK is missing', 500);
if (!array_key_exists('scheme', $config)) {
throw new \RuntimeException('scheme is missing', 500);
}
return $config['uri'];
if (!array_key_exists('host', $config)) {
throw new \RuntimeException('host is missing', 500);
}
if (!array_key_exists('path', $config)) {
throw new \RuntimeException('path is missing', 500);
}
return $config['scheme'] . '://' . $config['host'] . '/' . $config['path'];
}

/**
*
* 'PHP_AUTH_USER' => $user,
* 'PHP_AUTH_PW' => $password,
*
* @return mixed
*/
protected function getConfig() {
if (!isset($this->config)) {
$config = $this->serviceLocator->get('Config');
if (!array_key_exists('multiposting', $config)) {
throw new \RuntimeException('configuration for multiposting is missing', 500);
}
if (!array_key_exists('target', $config['multiposting'])) {
throw new \RuntimeException('target for multiposting is missing', 500);
}
if (!array_key_exists('restServer', $config['multiposting']['target'])) {
throw new \RuntimeException('configuration restServer for multiposting.target is missing', 500);
}
$this->config = $config['multiposting']['target']['restServer'];
$jobsOptions = $this->serviceLocator->get('Jobs/Options');

if (!isset($this->multipostingTarget) && isset($jobsOptions->multipostingTargetUri)) {
// The Uri has this Form
// scheme://user:pass@host/path
$parseResult = parse_url($jobsOptions->multipostingTargetUri);
$this->config = $parseResult;
//$this->config['PHP_AUTH_USER'] = $parseResult['user'];
//$this->config['PHP_AUTH_PW'] = $parseResult['pass'];
}
return $this->config;
}
Expand Down
35 changes: 32 additions & 3 deletions module/Jobs/src/Jobs/Listener/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,40 @@ public function restPost(JobEvent $e)
if ($serviceManager->has('Jobs/RestClient')) {
try {
$restClient = $serviceManager->get('Jobs/RestClient');
$provider = $serviceManager->get('Jobs/Options/Provider');

$entity = $e->getJobEntity();
$hydrator = $serviceManager->get('Jobs/JsonJobsEntityHydrator');
$json = $hydrator->extract($entity);
$restClient->setRawBody($json);

// all this is very alpha and will be due to several changes

// needed by now are (naming according to the Provider):
// applyId = to identify the job back in the provider
// company = name of the company
// title =
// description =
// location = zip and town-name
// datePublishStart = in a comprehensibly format for \DateTime
// channels = array of externalIds
$data = array(
'applyId' => $entity->applyId,
'company' => $entity->organization->name,
'title' => $entity->title,
'description' => $entity->description,
'location' => $entity->location,
'datePublishStart' => $entity->datePublishStart,
'channels' => array()
);
//$hydrator = $serviceManager->get('Jobs/JobsEntityHydrator');
//$data = $hydrator->extract($entity);

foreach ($entity->portals as $portalName => $portal) {
if (array_key_exists($portal, $provider->channels)) {
$data['channels'][] = $provider->channels[$portal]->externalkey;
}
}

$dataJson = json_encode($data);
$restClient->setRawBody($dataJson);
$response = $restClient->send();
// @TODO: statusCode is not stored, there is simply no mechanism to track external communication.
$StatusCode = $response->getStatusCode();
Expand Down
27 changes: 27 additions & 0 deletions module/Jobs/src/Jobs/Options/ChannelOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ChannelOptions extends AbstractOptions {
*/
protected $key;

/**
* @var
*/
protected $externalkey = 0;

/**
* Price of the channel.
*
Expand Down Expand Up @@ -153,6 +158,28 @@ public function getFormattedPrice($currencyPosition = 'right')
return $price . ' ' . $currency;
}

/**
* Sets the unique key of a channel
*
* @param string $key
* @return ChannelOptions
*/
public function setExternalkey($key)
{
$this->externalkey=$key;
return $this;
}

/**
* Gets the unique key of a channel
*
* @return string
*/
public function getExternalkey()
{
return $this->externalkey;
}

/**
* Gets the price of a channel
*
Expand Down
2 changes: 1 addition & 1 deletion module/Jobs/src/Jobs/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ModuleOptions extends AbstractOptions {
*
* @var string $multipostingTargetUri
*/
protected $multipostingTargetUri;
protected $multipostingTargetUri = 'http://user:pass@host/location?query';

/**
* The default Logo is shown in a job opening and in the application form
Expand Down
10 changes: 10 additions & 0 deletions module/Jobs/src/Jobs/Options/ProviderOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ProviderOptions extends AbstractOptions implements \IteratorAggregate {
public function __construct()
{
$this->channels = array();
//$this->long_label = '';
}

/**
Expand Down Expand Up @@ -62,4 +63,13 @@ public function getChannel($key)
{
return $this->channels[$key];
}

/**
* @return array
*/
public function getChannels()
{
return $this->channels;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ public function getOrganizationName()
return $this->organizationName;
}


public function getName()
{
if (empty($this->organizationName)) {
return '';
}
return $this->organizationName->name;
}

public function getSearchableProperties()
{
return array();
Expand Down

0 comments on commit 034df14

Please sign in to comment.