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

Release/2.1.2 #291

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function actionCreateExportZip()

if ($order->status !== ($newStatus = Translations::$plugin->orderRepository->getNewStatus($order))) {
$order->status = $newStatus;
$order->logActivity(sprintf('Order status changed to %s', $order->getStatusLabel()));
$order->logActivity(sprintf('Order status changed to \'%s\'', $order->getStatusLabel()));
}
}

Expand Down
20 changes: 6 additions & 14 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ public function actionOrderDetail(array $variables = array())
$order->targetSites = json_encode($orderTargetSites);
}

if (! empty(json_decode($order->tags, true))) {
$variables['tags'] = [];

foreach (json_decode($order->tags, true) as $tagId) {
$variables['tags'][] = Craft::$app->getTags()->getTagById($tagId);
}
}

if ($orderTags= Craft::$app->getRequest()->getQueryParam('tags') ?? Craft::$app->getRequest()->getParam('tags')) {
if (! is_array($orderTags)) {
$orderTags = explode(',', $orderTags);
Expand Down Expand Up @@ -386,11 +378,11 @@ public function actionSaveOrder()
// This is for draft converting to order.
$order = $this->service->getOrderById($orderId);

$order->logActivity(Translations::$plugin->translator->translate('app', 'Order Created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Order created'));
} else {
$order = $this->service->makeNewOrder($sourceSite);

$order->logActivity(Translations::$plugin->translator->translate('app', 'Order Created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Order created'));
}

$job = '';
Expand Down Expand Up @@ -597,7 +589,7 @@ public function actionSaveOrder()
}

$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order Submitted to %s'),
Translations::$plugin->translator->translate('app', 'Order submitted to %s'),
$order->translator->getName()
));
}
Expand Down Expand Up @@ -1430,7 +1422,7 @@ public function actionUpdateOrderFilesSource()
if ($isDefaultTranslator && !$order->isModified()) {
$order->status = Constants::ORDER_STATUS_MODIFIED;
$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order status changed to %s'),
Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''),
$order->getStatusLabel()
));
}
Expand All @@ -1448,7 +1440,7 @@ public function actionUpdateOrderFilesSource()
$order->status = Translations::$plugin->orderRepository->getNewStatus($order);

$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order status changed to %s'),
Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''),
$order->getStatusLabel()
));

Expand All @@ -1468,7 +1460,7 @@ public function actionUpdateOrderFilesSource()
Craft::$app->getSession()->setNotice('Entries Updated.');
} catch (\Exception $e) {
$transaction->rollBack();
Craft::debug($e, 'bhu123');

return $this->asJson(['success' => false, 'message' => 'Error updating source. Error: ' . $e->getMessage()]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ public function getOwner()
return $owner;
}

public function getTags()
{
return Translations::$plugin->tagRepository->getOrderTags($this);
}

public function getTargetSitesArray()
{
return $this->targetSites ? json_decode($this->targetSites, true) : array();
Expand Down
10 changes: 7 additions & 3 deletions src/services/repository/DraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ public function createOrderDrafts($orderId, $wordCounts, $publish, $fileIds, $qu
}
}

$order->status = Translations::$plugin->orderRepository->getNewStatus($order);

if ($isNewDraft)
$order->logActivity(Translations::$plugin->translator->translate('app', 'Drafts created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Drafts created'));

$newStatus = Translations::$plugin->orderRepository->getNewStatus($order);
if ($order->status != $newStatus) {
$order->status = $newStatus;
$order->logActivity(sprintf('Order status changed to \'%s\'', $order->getStatusLabel()));
}

Translations::$plugin->orderRepository->saveOrder($order);
}
Expand Down
10 changes: 4 additions & 6 deletions src/services/repository/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use acclaro\translations\services\api\CraftApiClient;

class SiteRepository
{
{
protected $supportedSites = array();
protected $isoMapping;

Expand All @@ -27,9 +27,9 @@ public function getSiteLanguage($siteId)
}

$language = $site->language;

$language = $this->normalizeLanguage($site);

return $language;
}

Expand All @@ -53,8 +53,6 @@ public function getSiteLanguageDisplayName($siteId)

public function normalizeLanguage($language)
{
$language = mb_strtolower($language);

$language = str_replace('_', '-', $language);

if (! $this->isoMapping) {
Expand Down Expand Up @@ -90,7 +88,7 @@ public function getAllSitesHandle()
{
$allSitesHandle = [];
$allSites = Craft::$app->getSites()->getAllSites();

foreach($allSites as $site)
{
$allSitesHandle[$site->id] = $site->handle;
Expand Down
21 changes: 20 additions & 1 deletion src/services/repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Craft;
use craft\elements\Tag;
use acclaro\translations\elements\Order;

class TagRepository
{
Expand All @@ -31,4 +32,22 @@ public function saveTag(Tag $tag)
Craft::error( '['. __METHOD__ .'] Couldn’t save the tag "'.$tag->title.'"', 'translations' );
}
}
}

/**
* Get Tags Object for an order
*
* @param Order $order
* @return array
*/
public function getOrderTags(Order $order)
{
$orderTags = [];
if ($order->tags) {
foreach (json_decode($order->tags, true) as $tagId) {
$orderTags[$tagId] = Craft::$app->getTags()->getTagById($tagId);
}
}

return $orderTags;
}
}
4 changes: 3 additions & 1 deletion src/services/translator/AcclaroTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Craft;
use craft\elements\Asset;
use craft\elements\GlobalSet;
use craft\helpers\ElementHelper;

use acclaro\translations\Constants;
use acclaro\translations\Translations;
Expand Down Expand Up @@ -96,8 +97,9 @@ public function updateOrder(Order $order)
$orderStatus = Translations::$plugin->orderRepository->getNewStatus($order);

if ($order->status !== $orderStatus) {
$order->status = $orderStatus;
$order->logActivity(
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to %s'), $orderStatus)
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''), $order->getStatusLabel())
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/services/translator/Export_ImportTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public function updateOrder(Order $order)
{
$newStatus = Translations::$plugin->orderRepository->getNewStatus($order);
if ($order->status !== $newStatus) {
$order->status = $newStatus;
$order->logActivity(
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to %s'), $newStatus)
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''), $order->getStatusLabel())
);

}
Expand Down Expand Up @@ -120,7 +121,7 @@ public function updateDraft($element, $draft, $translatedContent, $sourceSite, $
$errorMessage .= implode('; ', $r);
}
$order->logActivity(
Translations::$plugin->translator->translate('app', 'error saving drafts content. Error: '.$errorMessage)
Translations::$plugin->translator->translate('app', 'Error saving drafts content. Error: '.$errorMessage)
);
} else {
$order->logActivity(
Expand Down
4 changes: 2 additions & 2 deletions src/templates/_components/orders/settings-tab.twig
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
<div class="input ltr">
<div id="fields-tags" class="elementselect tagselect">
<div id="elementTags" class="elements">
{% if tags is defined %}
{% for tag in tags %}
{% if not order.getTags is empty %}
{% for tag in order.getTags %}
<div class="element small removable" data-editable="1" data-id="{{ tag.id }}" data-label="{{ tag.title }}">
<input type="hidden" name="tags[]" value="{{ tag.id }}"/>
<a class="delete icon custom-tag" data-label="{{ tag.title }}" data-id="{{ tag.id }}" title="Remove"></a>
Expand Down