-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
175 additions
and
10 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** ensure when create the database to use utf8mb4_unicode_ci | ||
CREATE DATABASE choufli_7all_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
**/ | ||
|
||
CREATE TABLE actors | ||
( | ||
actors_id SERIAL UNIQUE NOT NULL PRIMARY KEY, | ||
actors_slug VARCHAR(100) NOT NULL, | ||
actors_name VARCHAR(100) NOT NULL | ||
) CHARACTER SET utf8mb4 | ||
COLLATE utf8mb4_unicode_ci; | ||
|
||
CREATE TABLE quotes | ||
( | ||
quotes_id SERIAL UNIQUE NOT NULL PRIMARY KEY, | ||
quotes_text VARCHAR(1000) NOT NULL, | ||
id_author INT NOT NULL REFERENCES actors (authors_id) ON UPDATE CASCADE, | ||
quotes_counter_random INT NOT NULL DEFAULT 0 | ||
) CHARACTER SET utf8mb4 | ||
COLLATE utf8mb4_unicode_ci; | ||
|
||
INSERT INTO actors (actors_slug, actors_name) VALUES ('sboui', 'السبوعي'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('slimene', 'سليمان الأبيض'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('zeineb', 'زينب'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('fadhila', 'لالة فضيلة'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('azza', 'عزّة'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('dalanda', 'دالندا'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('jannet', 'جنّاة'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('fouchika', 'فوشيكا'); | ||
INSERT INTO actors (actors_slug, actors_name) VALUES ('beji', 'الباجي ماتريكس'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
<?php | ||
ini_set('display_errors', 'on'); | ||
error_reporting(E_ALL); | ||
|
||
require_once __DIR__.'/vendor/autoload.php'; | ||
require_once __DIR__.'/config.php'; | ||
|
||
use \Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
$app = new Mabs\Application(); | ||
$app = new App\APIChoufli7allApp(); | ||
$container = $app->getContainer(); | ||
|
||
$app->get('random', function () { | ||
$app->get('random', function () use ($container) { | ||
$quote = []; | ||
$stmt = $container['pdo']->query('SELECT COUNT(*) AS count FROM quotes'); | ||
$count = $stmt->fetch(PDO::FETCH_ASSOC)['count']; | ||
|
||
$data = [ | ||
'quote' => 'المريض عندي، ما يخرجش قبل ما يتحسن', | ||
'auhtor' => 'سليمان الأبيض' | ||
]; | ||
|
||
return new JsonResponse($data); | ||
if ($count > 0) { | ||
// Get a random quote | ||
$randomIndex = rand(0, $count - 1); | ||
$stmt = $container['pdo']->prepare('SELECT quotes.quotes_text, actors.actors_name FROM quotes JOIN actors ON quotes.id_author = actors.actors_id LIMIT 1 OFFSET :offset'); | ||
$stmt->bindValue(':offset', $randomIndex, PDO::PARAM_INT); | ||
$stmt->execute(); | ||
|
||
$row = $stmt->fetch(PDO::FETCH_ASSOC); | ||
|
||
$quote = [ | ||
'quote' => $row['quotes_text'], | ||
'actor' => $row['actors_name'], | ||
]; | ||
} | ||
|
||
return new JsonResponse($quote); | ||
|
||
})->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
require __DIR__.'/../config.php'; | ||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
$quotesDir = __DIR__.'/raw'; | ||
$actorsArray = []; | ||
// Connexion to database and init script | ||
try { | ||
|
||
$dsn = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME . ';charset=utf8mb4'; | ||
$pdo = new PDO($dsn, DB_USER, DB_PASSWORD); | ||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$stmt = $pdo->query('SELECT actors_id, actors_slug FROM actors'); | ||
|
||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$actorsArray[$row['actors_slug']] = $row['actors_id']; | ||
} | ||
|
||
} catch (PDOException $e) { | ||
die('Erreur de connexion : ' . $e->getMessage()); | ||
} | ||
|
||
|
||
|
||
// get all .txt files | ||
$files = glob($quotesDir . '/*.txt'); | ||
|
||
foreach ($files as $file) { | ||
|
||
$slug = basename($file, '.txt'); | ||
|
||
if (isset($actorsArray[$slug])) { | ||
$actorId = $actorsArray[$slug]; | ||
|
||
$quotes = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | ||
|
||
foreach ($quotes as $quote) { | ||
|
||
$stmt = $pdo->prepare('INSERT INTO quotes (quotes_text, id_author) VALUES (:quote, :authorId)'); | ||
$stmt->execute(['quote' => $quote, 'authorId' => $actorId]); | ||
} | ||
|
||
echo "Quotes imported for actor: $slug\n"; | ||
} else { | ||
echo "No actor found for slug: $slug\n"; | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
يا السبوعي، شنوّة هالحالة؟ لازم نبدلوا كل شيء في الدار | ||
ياخي أنا تزوجت باش نعيش في القلة؟ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
أنا ما نضيعش وقتي في كلام فارغ | ||
دكتور، لازمك تاخذ إجازة، شوف روحك كيفاش وليت! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
الجار قبل الدار | ||
الواحد يلزم يكون في حالو وما يتدخلش في شؤون الناس | ||
الواحد يلزموا يعرف كيفاش يعيش، موش الكل فلوس |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
الدنيا هانية، يا سبوعي، الدنيا لعب وفلوس | ||
يا سبوعي، احنا ولاد حومة وحدة، ما فماش اللي يغلبنا |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
كي تبدأ الزهرة في الميزان، الدنيا تهبط وتطلع! | ||
أنا نقولك الحقيقة، الكواكب ما تكذبش | ||
اليوم القمر في برجك! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
نحبك برشا يا دكتووور | ||
الدنيا هانية | ||
والله ما فهمت شيء | ||
دكتور، ما نعرش، برشا حاجات في مخي |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ما تنجمش تعالج مريض وأنت مريض! | ||
أنا طبيب، مش معالج سحري! | ||
يا ربي، أعطني الصبر! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
المرأة اللي ما تحكمش في دارها، ما تحكمش في حتى شيء | ||
كيفاش باش نمشي نقابل الناس بهالحالة؟ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace App; | ||
use Mabs\Application; | ||
|
||
class APIChoufli7allApp extends Application | ||
{ | ||
public function getAdapters() | ||
{ | ||
return array( | ||
new \Mabs\Adapter\SessionServiceAdapter(), | ||
new \App\Service\DbManager, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use Mabs\Container\Container; | ||
use Mabs\ServiceAdapterInterface; | ||
|
||
class DbManager implements ServiceAdapterInterface | ||
{ | ||
|
||
public function load(Container $container) | ||
{ | ||
$container['pdo'] = function () { | ||
|
||
$dsn = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME . ';charset=utf8mb4'; | ||
$pdo = new \PDO($dsn, DB_USER, DB_PASSWORD); | ||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | ||
|
||
return $pdo; | ||
}; | ||
|
||
} | ||
|
||
public function boot(Container $container) | ||
{ | ||
// do nothing | ||
} | ||
|
||
} |