From f9e3431d4853701c0deda41bbfdf4ac889d7abdf Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Thu, 24 Jan 2019 11:52:22 +0100
Subject: [PATCH] Port indexation::setArticleDebut to Linse

---
 Linse.php           | 23 +++++++++++++++++++++++
 tests/LinseTest.php |  6 ++++++
 2 files changed, 29 insertions(+)

diff --git a/Linse.php b/Linse.php
index 6137655..3146ca8 100644
--- a/Linse.php
+++ b/Linse.php
@@ -599,4 +599,27 @@ class Linse {
       }
     else return '';
   }
+
+
+  public function putArticleToFront($title) {
+		if(substr($title,-1) !=")")
+      return $title;
+
+		foreach($this->exclu as $article) {
+			$compare = "(" . trim($article) . ")";
+			$lg = strlen($compare);
+			if(strtoUpper(substr($title,-$lg)) == $compare) {
+				$deb = substr($title,- $lg);
+				$deb = str_replace("(","",$article);
+				$deb = str_replace(")","",$article);
+				if (substr($deb,-1)!="'")
+          $deb .= " ";
+				$new = $deb . trim(substr($title, 0, (strlen($title) - $lg)));
+
+				return $new;
+			}
+		}
+
+		return $title;
+	}
 }
\ No newline at end of file
diff --git a/tests/LinseTest.php b/tests/LinseTest.php
index e6b1291..ec1c9ae 100644
--- a/tests/LinseTest.php
+++ b/tests/LinseTest.php
@@ -72,6 +72,12 @@ class LinseTest extends PHPUnit_Framework_TestCase {
   }
 
 
+  /** @test */
+  public function putArticleToFrontForPianoLeShouldReturnLePiano() {
+    $this->assertEquals('LE Piano', $this->_model->putArticleToFront('Piano (le)'));
+  }
+
+
   public function titlesAndAlpha() {
     return [
             [ 'Norvege, Islande', 'NORVEGE ISLANDE' ],
-- 
GitLab