Skip to content
Permalink
Browse files

field notes: fix date is utc, summarize geocache not found errors

  • Loading branch information...
mirsch committed Sep 27, 2016
1 parent bddc71f commit 1dd8b99e64d29697dc80559cde3ec739030fabe1
@@ -1,3 +1,7 @@
array_util:
human_lang_implode:
and: and

field_notes:
btn:
delete: Delete
@@ -10,7 +14,7 @@ field_notes:

error:
# Desc: Geocache "%code%" not found.
geocache_not_found: 'Geocache "%code%" not found.'
geocache_not_found: 'Geocache %code% not found.|Geocaches %code% not found.'

# Desc: Log type "%type%" is not implemented.
log_type_not_implemented: 'Log type "%type%" is not implemented.'
@@ -55,6 +55,7 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
$content = str_replace("\xFF\xFE", '', $content); // remove UTF16(LE) BOM
$content = mb_convert_encoding($content, 'UTF-8', 'UCS-2LE');
$rows = ArrayUtil::trimExplode("\n", $content);
$notFoundGeocacheCodes = [];
foreach ($rows as $row) {
$data = str_getcsv($row, ',', '"', '""');
if (count($data) !== 4) {
@@ -90,9 +91,18 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
$geocache = $this->entityManager->getRepository('AppBundle:Geocache')->findOneBy(['wpOc' => $data[0]]);
}
if (!$geocache) {
$notFoundGeocacheCodes[] = $data[0];
$this->addError(
/** @Desc("Geocache ""%code%"" not found.") */
$this->translator->trans('field_notes.error.geocache_not_found', ['%code%' => $data[0]])
$this->translator->transChoice(
'field_notes.error.geocache_not_found',
count($notFoundGeocacheCodes),
['%code%' => ArrayUtil::humanLangImplode(
$notFoundGeocacheCodes,
$this->translator->trans('array_util.human_lang_implode.and')
)]
),
'geocache-not-found'
);
continue;
}
@@ -177,6 +187,7 @@ protected function getDate($dateString)
$dateString,
new DateTimeZone('UTC')
);
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $date;
}
@@ -11,11 +11,17 @@ trait ErrorTrait
/**
* @param string $text
* @param null|string $context
*
* @return void
*/
protected function addError($text)
protected function addError($text, $context = null)
{
if ($context !== null) {
$this->errors[$context] = $text;
return;
}
$this->errors[] = $text;
}
@@ -23,4 +23,21 @@ public static function trimExplode($delimiter, $string)
return $result;
}
/**
* @param array $pieces
* @param string $conjunction
* @param string $glue
*
* @return mixed|string
*/
public static function humanLangImplode(array $pieces, $conjunction = 'and', $glue = ',')
{
$lastElement = array_pop($pieces);
if ($pieces) {
return implode($glue . ' ', $pieces) . ' ' . $conjunction . ' ' . $lastElement;
}
return $lastElement;
}
}
@@ -7,15 +7,10 @@
namespace Oc\Frontend\Login;
use Behat\Mink\Element\NodeElement;
use Oc\Frontend\AbstractFrontendTest;
class FieldNotesTest extends AbstractFrontendTest
{
private function cleanUpFieldNotesTable()
{
}
/**
* @group frontend
@@ -59,7 +54,7 @@ public function testFieldNotesImport()
$page->pressButton('testing-fieldNotes-submit-button');
$errorMessage = $page->find('css', '.flash-messages');
if ($errorMessage !== null) {
self::assertEquals('Geocache "OC10FC7" not found.', $errorMessage->getText());
self::assertEquals('Geocache OC10FC7 not found.', $errorMessage->getText());
} else {
self::fail(__METHOD__ . ' failed');
}
@@ -75,7 +70,7 @@ public function testFieldNotesImport()
$fieldNotesResult[3] = 'Naafbachtal II DEF 456 2016-06-02 18:05 Not found Log it | Delete';
$fieldNotesResult[4] = 'Testcache111 222 2016-06-02 18:06 Needs maintainance Log it | Delete';
/** @var NodeElement $fieldNote */
/** @var \Behat\Mink\Element\NodeElement $fieldNote */
foreach ($fieldNotesRow as $key => $fieldNote) {
if ($fieldNote !== null) {
self::assertEquals($fieldNotesResult[$key], $fieldNote->getText());

0 comments on commit 1dd8b99

Please sign in to comment.
You can’t perform that action at this time.