Browse Source

Alpha version of new namespace design

Giancarlo Voci 8 years ago
parent
commit
2715fbe0a7

+ 1 - 1
config.ini

@@ -1,5 +1,5 @@
 [globals]
 [globals]
-AUTOLOAD="src/"
+;AUTOLOAD="src/"
 ;CACHE = "folder=cache/"
 ;CACHE = "folder=cache/"
 CACHE = false
 CACHE = false
 CACHE_TTL=1
 CACHE_TTL=1

+ 13 - 9
index.php

@@ -12,7 +12,9 @@ require_once 'lib/f3/base.php';
 $f3 = \Base::instance();
 $f3 = \Base::instance();
 $f3->set("AUTOLOAD", 'src/');
 $f3->set("AUTOLOAD", 'src/');
 
 
-\OMUtils::Instance()->LoadEncryptedConfig('config.bin');
+$config = new \OpenMind\Utils\Configuration();
+
+\OpenMind\Utils\OMUtils::getInstance()->LoadEncryptedConfig('config.bin');
 
 
 $f3->config('labels.ini', true);
 $f3->config('labels.ini', true);
 
 
@@ -24,16 +26,18 @@ $f3->set('DB',
     array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => TRUE))
     array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => TRUE))
 );
 );
 
 
+$d = new \Customers\Lamborghini\Distinta($f3);
+
 // Pages
 // Pages
-$f3->route('GET /', "Modules\Pages->Login", $f3->get('CACHE_TTL'));
-$f3->route('GET /homemenu', "Modules\Pages->HomeMenu", $f3->get('CACHE_TTL'));
-$f3->route('GET|POST /pick2light/@step', "Modules\Pages->Pick2Light", $f3->get('CACHE_TTL'));
-$f3->route("GET|POST /bind/@step", 'Modules\Pages->Bind', $f3->get('CACHE_TTL'));
-$f3->route("GET|POST /unbind/@step", 'Modules\Pages->UnBind', $f3->get('CACHE_TTL'));
-$f3->route('GET /elencodistinta', "Modules\Pages->ElencoDistinta", $f3->get('CACHE_TTL'));
+$f3->route('GET /', "Customers\Lamborghini\Pages->Login", $f3->get('CACHE_TTL'));
+$f3->route('GET /homemenu', "Customers\Lamborghini\Pages->HomeMenu", $f3->get('CACHE_TTL'));
+$f3->route('GET|POST /pick2light/@step', "Customers\Lamborghini\Pages->Pick2Light", $f3->get('CACHE_TTL'));
+$f3->route("GET|POST /bind/@step", 'Customers\Lamborghini\Pages->Bind', $f3->get('CACHE_TTL'));
+$f3->route("GET|POST /unbind/@step", 'Customers\Lamborghini\Pages->UnBind', $f3->get('CACHE_TTL'));
+$f3->route('GET /elencodistinta', "Customers\Lamborghini\Pages->ElencoDistinta", $f3->get('CACHE_TTL'));
 
 
 // Services
 // Services
-$f3->route("POST /login", 'Modules\BaseController->Login');
-$f3->route("GET /logout", 'Modules\BaseController->Logout');
+$f3->route("POST /login", 'OpenMind\Web\BaseController\BaseController->Login');
+$f3->route("GET /logout", 'OpenMind\Web\BaseController\BaseController->Logout');
 
 
 $f3->run();
 $f3->run();

+ 9 - 5
src/Distinta.php → src/Customers/Lamborghini/Distinta.php

@@ -5,6 +5,10 @@
  * @time 11:43
  * @time 11:43
  */
  */
 
 
+namespace Customers\Lamborghini;
+
+use OpenMind\Labeling\FindBoxCoreSystem;
+
 class Distinta
 class Distinta
 {
 {
   private $dbHandle;
   private $dbHandle;
@@ -53,7 +57,7 @@ EOF;
   public function SaveProductsToFindBox(string $maxArticles, bool $blink, int $iterations = 20)
   public function SaveProductsToFindBox(string $maxArticles, bool $blink, int $iterations = 20)
   {
   {
     $CORE_SETTINGS = \F3::get('CORE.fb');
     $CORE_SETTINGS = \F3::get('CORE.fb');
-    $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+    $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
 
 
     $datiDistinta = $this->getDistinta($maxArticles);
     $datiDistinta = $this->getDistinta($maxArticles);
     foreach($datiDistinta as $row) {
     foreach($datiDistinta as $row) {
@@ -105,7 +109,7 @@ EOF;
   public function MarkBarcodeAsAnomalia(string $barcode)
   public function MarkBarcodeAsAnomalia(string $barcode)
   {
   {
     $CORE_SETTINGS = \F3::get('CORE.fb');
     $CORE_SETTINGS = \F3::get('CORE.fb');
-    $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+    $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
     $lblId = $this->GetLabelIdFromBarcode($barcode);
     $lblId = $this->GetLabelIdFromBarcode($barcode);
     $label = new \SmartESL($findBoxCore, [$lblId]);
     $label = new \SmartESL($findBoxCore, [$lblId]);
     $label->BlinkSpecial(3, 1, 1000, 10);
     $label->BlinkSpecial(3, 1, 1000, 10);
@@ -153,7 +157,7 @@ EOF;
   public function ResetLabelCarrello(string $labelId)
   public function ResetLabelCarrello(string $labelId)
   {
   {
     $CORE_SETTINGS = \F3::get('CORE.fb');
     $CORE_SETTINGS = \F3::get('CORE.fb');
-    $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+    $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
 
 
     $label = new \SmartESL($findBoxCore, [$labelId]);
     $label = new \SmartESL($findBoxCore, [$labelId]);
     $label->BlinkSpecial(0, 1, 1000, 8, 0);
     $label->BlinkSpecial(0, 1, 1000, 8, 0);
@@ -182,7 +186,7 @@ EOF;
   public function SaveLabelCarrello(string $labelId, string $barcode, string $consegna)
   public function SaveLabelCarrello(string $labelId, string $barcode, string $consegna)
   {
   {
     $CORE_SETTINGS = \F3::get('CORE.fb');
     $CORE_SETTINGS = \F3::get('CORE.fb');
-    $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+    $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
 
 
     $sqlCommesse = "SELECT DISTINCT origine, commessa, ordine_produzione, data_creazione, time_creazione, destinazione_merci FROM `distinte` WHERE consegna = '{$consegna}'";
     $sqlCommesse = "SELECT DISTINCT origine, commessa, ordine_produzione, data_creazione, time_creazione, destinazione_merci FROM `distinte` WHERE consegna = '{$consegna}'";
     $dataFields = $this->dbHandle->exec($sqlCommesse);
     $dataFields = $this->dbHandle->exec($sqlCommesse);
@@ -220,7 +224,7 @@ EOF;
     $dataset = $this->dbHandle->exec($sql);
     $dataset = $this->dbHandle->exec($sql);
 
 
     $CORE_SETTINGS = \F3::get('CORE.fb');
     $CORE_SETTINGS = \F3::get('CORE.fb');
-    $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+    $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
 
 
     foreach($dataset as $row) {
     foreach($dataset as $row) {
       $dataFields = array(
       $dataFields = array(

+ 26 - 0
src/Customers/Lamborghini/Lamborghini.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * @author Open Mind
+ * @date 13/06/2018
+ * @time 15:11
+ */
+
+namespace Customers\Lamborghini;
+
+use OpenMind\Labeling\FindBoxCoreSystem as FBCS;
+
+class FindBoxCoreSystem extends FBCS
+{
+  public function __construct()
+  {
+    parent::__construct(...array_values(\F3::get('CORE.fb')));
+  }
+}
+
+class Lamborghini
+{
+  public function __construct()
+  {
+  }
+}
+

+ 0 - 16
src/Data/Modulo.php

@@ -1,16 +0,0 @@
-<?php
-/**
- * @author Open Mind
- * @date 12/06/2018
- * @time 11:41
- */
-
-class Modulo
-{
-  /**
-   * Modulo constructor.
-   */
-  public function __construct()
-  {
-  }
-}

+ 0 - 16
src/Data/ModuloParts.php

@@ -1,16 +0,0 @@
-<?php
-/**
- * @author Open Mind
- * @date 12/06/2018
- * @time 11:43
- */
-
-class ModuloParts
-{
-  /**
-   * ModuloParts constructor.
-   */
-  public function __construct()
-  {
-  }
-}

+ 0 - 89
src/Modules/BaseController.php

@@ -1,89 +0,0 @@
-<?php
-
-namespace Modules;
-/**
- * @author Open Mind
- * @date 09/04/2018
- * @time 16:15
- */
-
-class BaseController
-{
-  protected $dbHandle;
-  protected $userId;
-  private $sanitizedPostRequest;
-
-  /**
-   * @return mixed
-   */
-  public function getSanitizedPostRequest()
-  {
-    return $this->sanitizedPostRequest;
-  }
-
-  public function __construct($f3)
-  {
-    $this->sanitizedPostRequest = $f3->clean($f3->get('POST'));
-
-    $this->dbHandle = $f3->get('DB');
-
-    $this->userId = $this->checkLogin($f3->get('COOKIE.username'), $f3->get('COOKIE.password'));
-    $f3->set('USERID', $this->userId);
-
-    if (!is_null($this->userId))
-      return;
-
-    $f3->clear('COOKIE.username');
-    $f3->clear('COOKIE.password');
-    $f3->clear('COOKIE.id');
-
-    if (!in_array($f3->get('PATTERN'), ['/login', '/']))
-      $f3->reroute('/');
-
-    return;
-  }
-
-  /**
-   * Check if login is valid
-   * @param $username
-   * @param $password
-   * @return int|null
-   */
-  private function checkLogin($username, $password): ?int
-  {
-    $accounts = \F3::get('users.PASSWORD');
-    foreach($accounts as $index => $account) {
-      $exist = password_verify("{$username}|{$password}", $account);
-      if ($exist)
-        return $index;
-    }
-    return null;
-  }
-
-  public function Login($f3)
-  {
-    $accountData = $this->getSanitizedPostRequest();
-
-    $userId = $this->checkLogin($accountData['username'], $accountData['password']);
-
-    if (is_null($userId)) {
-      http_response_code(500);
-      echo "Dati di accesso non corretti";
-      return;
-    }
-
-    $f3->set('COOKIE.username', $accountData['username']);
-    $f3->set('COOKIE.password', $accountData['password']);
-    $f3->set('COOKIE.id', $userId);
-    //http_response_code(200);
-    $f3->reroute('/homemenu');
-  }
-
-  public function Logout($f3)
-  {
-    $f3->clear('COOKIE.username');
-    $f3->clear('COOKIE.password');
-    $f3->clear('COOKIE.id');
-    $f3->reroute('/');
-  }
-}

+ 0 - 233
src/Modules/Pages.php

@@ -1,233 +0,0 @@
-<?php
-/**
- * @author Open Mind
- * @date 10/04/2018
- * @time 09:43
- */
-
-namespace Modules;
-
-class Pages extends BaseController
-{
-  private $CORE_SETTINGS;
-  private $findBoxCore;
-
-  public function __construct($f3)
-  {
-    parent::__construct($f3);
-    $this->CORE_SETTINGS = $f3->get('CORE.fb');
-    $this->findBoxCore = new \FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
-  }
-
-  public function Login($f3)
-  {
-    if (!is_null($this->userId)) {
-      $f3->reroute('/homemenu');
-      return;
-    } else
-      $f3->set('CONTENT', 'login.tpl');
-
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-
-  public function HomeMenu($f3)
-  {
-    $f3->set('CONTENT', 'homemenu.tpl');
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-
-  public function Pick2Light(object $f3, array $args)
-  {
-    $stepValues = [];
-    if ($args['step'] == 1) {
-      $f3->clear('COOKIE.p2l');
-      $f3->clear('COOKIE.consegna');
-      $f3->clear('COOKIE.labelid');
-    } else {
-      $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
-      if (count($stepValues) == 0)
-        $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
-    }
-
-    switch ($args['step']) {
-      case 3:
-        $distinta = new \Distinta($f3);
-        $distinta->CleanDistintaTable();
-        $distinta->CopyDistinta($stepValues['consegna']);
-
-        $label = new \SmartESL($this->findBoxCore, [$stepValues['labelid']]);
-        $label->BlinkSpecial(0, 1, 1000, 8, 0);
-
-        $distinta->SaveProductsToFindBox('3', true, 50); // prende soltanto i primi 3 dalla tabella copia delle distinte
-
-        $f3->set('COOKIE.p2l', json_encode($stepValues));
-        $f3->set('COOKIE.consegna', $stepValues['consegna']);
-        $f3->set('COOKIE.labelid', $stepValues['labelid']);
-        $f3->reroute("/pick2light/4");
-        return;
-        break;
-      case 4:
-        $distinta = new \Distinta($f3);
-        $distinta->SaveProductsToFindBox('3, 2000', false); // LIMIT 3,1000 perchè i primi 3 sono stati fatti nel case 3
-        break;
-      case 5:
-        $datiCommessa['consegna'] = $f3->get('COOKIE.consegna');
-        $datiCommessa['labelid'] = $f3->get('COOKIE.labelid');
-        $distinta = new \Distinta($f3);
-        $pickedBarcode = $f3->get('POST.pickedlabelid');
-        // Decrease quantity and blink label
-        if ($pickedBarcode != null) {
-          // ANOMALIA
-          if ($pickedBarcode == $f3->get('BARCODE_COMMANDS.ANOMALIACODE')) {
-            // <Se è stato ancora passato un codice anomalia, cancella l'operazione di anomalia in corso
-            if (isset($stepValues['anomalia']))
-              unset($stepValues['anomalia']);
-            else
-              $f3->set('ANOMALIA', 'In attesa del codice anomalia');
-            //>
-          } else if ($stepValues['anomalia']) {
-            if ($distinta->MarkBarcodeAsAnomalia($pickedBarcode))
-              unset($stepValues['anomalia']);
-            else
-              $f3->set('ANOMALIA', 'Codice non trovato!');
-          } else { // E' stato passato un codice
-            $codeFromLabelId = $distinta->GetBarcodeFromLabelId($pickedBarcode);
-            $pickedBarcode = $codeFromLabelId ?? $pickedBarcode;
-            if ($distinta->RemoveQuantity($pickedBarcode)) {
-              // SPEGNE LED ETICHETTA DOPO PICKING
-              $label = new \SmartESL($this->findBoxCore, [$distinta->GetLabelIdFromBarcode($pickedBarcode)]);
-              $label->BlinkOff();
-            } else {
-              $f3->set('INFOTEXT', 'Barcode non riconosciuto o non associato ad alcuna etichetta elettronica');
-              file_put_contents('not_found.log', $pickedBarcode . "\r\n", FILE_APPEND);
-            }
-          }
-        }
-
-        $rowsDistinta = $distinta->getDistinta();
-        $f3->set('PRODUCTS', $rowsDistinta);
-        // End Picking List
-        if (count($rowsDistinta) == 0) {
-          //$distinta->ResetDistintaLabels($datiCommessa['consegna'], $datiCommessa['labelid']);
-          $anomalie = $distinta->getAnomalieFromConsegne($datiCommessa['consegna']);
-          $f3->set('LISTANOMALIE', $anomalie);
-
-          $label = new \SmartESL($this->findBoxCore, [$datiCommessa['labelid']]);
-          $distinta->SaveLabelCarrello($datiCommessa['labelid'], $datiCommessa['labelid'], $datiCommessa['consegna']);
-
-          // Se non ci sono anomalie torna alla homepage
-          if (count($anomalie) == 0) {
-            $f3->reroute('/');
-            return;
-          }
-        } else {
-          // Seleziona le prossime tre etichette
-          foreach($rowsDistinta as $rowDist) {
-            $labelId = $distinta->GetLabelIdFromBarcode($rowDist['barcode']);
-            if ($labelId != null) {
-              $label = new \SmartESL($this->findBoxCore, [$labelId]);
-              // Se è lo stesso barcode di quello appena pickato dall'operatore, non lo blinka di nuovo
-              if ($distinta->GetArticleCount($rowDist['barcode']) > 0) {
-                $label->BlinkSpecial(2, 1, 1000, 20);
-              }
-            }
-          }
-        }
-        break;
-    }
-
-    $f3->set('COOKIE.p2l', json_encode($stepValues));
-
-    $f3->set('DISTINTE', $f3->Get('DB')->exec('SELECT DISTINCT consegna, DATE_FORMAT(data_creazione,"%d/%m/%Y") as data_creazione, time_creazione, destinazione_merci FROM `distinte` d JOIN articles a ON a.materiale=d.barcode ORDER BY data_creazione, time_creazione, destinazione_merci'));
-    $f3->set('STEP', $args['step']);
-    $f3->set('PAGEVALUES', $stepValues);
-
-    $f3->set('CONTENT', 'pick2light.tpl');
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-
-  public function Bind($f3, array $args)
-  {
-    $stepValues = [];
-    if ($args['step'] == 1)
-      $f3->clear('COOKIE.bind');
-    else {
-      $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
-      if (count($stepValues) == 0)
-        $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
-    }
-
-    $f3->set('COOKIE.bind', json_encode($stepValues));
-
-    if ($args['step'] == 3) {
-      $this->findBoxCore->Bind($stepValues['labelid'], $stepValues['barcode']);
-      $label = new \SmartESL($this->findBoxCore, [$stepValues['labelid']]);
-
-      if ($stepValues['labelid'] == $stepValues['barcode'])
-        $devType = 79;
-      else
-        $devType = 31;
-      $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT{$devType}");
-
-      $label->Display($labelTemplateId[0], $stepValues['barcode']);
-
-
-      // Reset label carrello if barcode = label id
-      if ($stepValues['labelid'] == $stepValues['barcode']) {
-        $d = new \Distinta($f3);
-        $d->ResetLabelCarrello($stepValues['labelid']);
-      } else {
-        $articles = new \DB\SQL\Mapper($this->dbHandle, 'articles');
-        $articles->load("materiale='{$stepValues['barcode']}'");
-
-        if (!$articles->dry()) {
-          $dataFields = array(
-            'tipo_magazzino' => $articles['tipo_magazzino'],
-            'ubicazione' => $articles['ubicazione'],
-            'incc_intr' => $articles['incc_intr']
-          );
-          $dataFields = array_merge($dataFields, array(
-            'quantita_contenitore' => $articles['qta_contenitore'],
-            'quantita_magazzino' => $articles['qta_riordino']
-          ));
-          $this->findBoxCore->SaveProducts($stepValues['barcode'], $articles['descrizione'], $dataFields);
-          if ($devType == 31 && ($articles['qta_contenitore'] == 'NO' || $articles['qta_riordino'] == 'NO'))
-            $pickTemplateId = $labelTemplateId[1];
-          else
-            $pickTemplateId = $labelTemplateId[2];
-
-          $eslData = json_encode($dataFields);
-          $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$stepValues['labelid']}'");
-          $this->dbHandle->exec("INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields, descrizione) VALUES ('{$stepValues['labelid']}', '{$stepValues['barcode']}', '{$pickTemplateId}', '{$eslData}', '{$articles['descrizione']}')");
-        }
-      }
-    }
-
-    $f3->set('STEP', $args['step']);
-    $f3->set('CONTENT', 'bind.tpl');
-    $f3->set('AUTOFOCUS' . $args['step'], 'autofocus');
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-
-  public function UnBind($f3, array $args)
-  {
-    $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
-    if ($args['step'] == 2) {
-      $success = $this->findBoxCore->UnBind($stepValues['labelid']);
-      if ($success['err'] <> 0) {
-        $f3->set('INFOTEXT', $success['value']);
-      }
-    }
-    $f3->set('STEP', $args['step']);
-    $f3->set('CONTENT', 'unbind.tpl');
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-
-  public function ElencoDistinta($f3)
-  {
-    $distinta = new \Distinta($f3);
-    $f3->set('PRODUCTS', $distinta->getDistinte());
-    $f3->set('CONTENT', 'distinta.tpl');
-    echo \Template::instance()->render('masterpage.tpl');
-  }
-}

+ 2 - 0
src/FindBoxCoreSystem.php → src/OpenMind/Labeling/FindBoxCoreSystem.php

@@ -8,6 +8,8 @@
  * @return array
  * @return array
  */
  */
 
 
+namespace OpenMind\Labeling;
+
 function array_filter_keys(array $array, array $keysToExtract)
 function array_filter_keys(array $array, array $keysToExtract)
 {
 {
   return array_intersect_key($array, array_flip($keysToExtract));
   return array_intersect_key($array, array_flip($keysToExtract));

+ 2 - 0
src/SmartESL.php → src/OpenMind/Labeling/SmartESL.php

@@ -5,6 +5,8 @@
  * @time 09:09
  * @time 09:09
  */
  */
 
 
+namespace OpenMind\Labeling;
+
 class SmartESL
 class SmartESL
 {
 {
   private $core;
   private $core;

+ 2 - 0
src/Configuration.php → src/OpenMind/Utils/Configuration.php

@@ -5,6 +5,8 @@
  * @time 12:10
  * @time 12:10
  */
  */
 
 
+namespace OpenMind\Utils;
+
 class Configuration
 class Configuration
 {
 {
   private $options = [
   private $options = [

+ 8 - 2
src/OMUtils.php → src/OpenMind/Utils/OMUtils.php

@@ -5,11 +5,17 @@
  * @time 11:11
  * @time 11:11
  */
  */
 
 
+namespace OpenMind\Utils;
+
 class OMUtils
 class OMUtils
 {
 {
-  static public function Instance()
+  public static function getInstance()
   {
   {
-    return new \OMUtils();
+    static $instance = null;
+    if($instance===null) {
+      $instance = new static(); // PHP 5+ lazy state building
+    }
+    return $instance;
   }
   }
 
 
   /**
   /**

+ 1 - 1
test.php

@@ -28,7 +28,7 @@ $f3->set('DB',
 );
 );
 
 
 $CORE_SETTINGS = $f3->get('CORE.fb');
 $CORE_SETTINGS = $f3->get('CORE.fb');
-$findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
+$findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
 
 
 $db = $f3->get('DB');
 $db = $f3->get('DB');
 $articles = $db->exec('SELECT * FROM ARTICLES');
 $articles = $db->exec('SELECT * FROM ARTICLES');