Files
bio-concept-pharma/web/modules/colissimosuivi/models/ColissimoSuiviModel.php
2019-11-17 19:14:07 +01:00

116 lines
3.6 KiB
PHP

<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license.
* Use, copy, modification or distribution of this source file without written
* license agreement is strictly forbidden.
* In order to obtain a license, please contact us: simon@daig.re
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit est expressement interdite.
* Pour obtenir une licence, veuillez nous contacter a l'adresse: simon@daig.re
*
* @package La Poste Colissimo Suivi
* @author Agencya
* @copyright Copyright(c) 2015-2018
* @license See Readme.md
* Contact by Email : simon@daig.re
*/
class ColissimoSuiviModel extends ObjectModel
{
/** @var int */
public $id_order;
/** @var string */
public $tracking;
/** @var string */
public $event_code;
/** @var string */
public $event_libelle;
/** @var string */
public $event_site;
/** @var string */
public $event_date;
/** @var string */
public $error_code;
/** @var DateTime */
public $date_add;
/** @var DateTime */
public $date_upd;
/** @var array */
public static $definition = array(
'table' => 'colissimo_suivi',
'primary' => 'id_colissimo_suivi',
'multilang' => false,
'fields' => array(
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'tracking' => array('type' => self::TYPE_STRING, 'validate' => 'isTrackingNumber', 'required' => true, 'size' => 13),
'event_code' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 6),
'event_libelle' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'event_site' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'event_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'error_code' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
/**
* @return string
*/
public function getTrackingUrl()
{
return 'https://www.laposte.fr/particulier/outils/suivre-vos-envois?code='.$this->tracking;
}
/**
* @return string
*/
public function getTrackingFormatted()
{
return Tools::substr($this->tracking, 0, 2).' '.Tools::substr($this->tracking, 2, 3).' '.Tools::substr($this->tracking, 5, 3).' '.Tools::substr($this->tracking, 8, 4).' '.Tools::substr($this->tracking, 12);
}
/**
* @param int $id_order
* @return mixed
*/
public static function getIdByOrderId($id_order)
{
return Db::getInstance()->getValue('
SELECT cs.`id_colissimo_suivi`
FROM `'._DB_PREFIX_.'colissimo_suivi` cs
WHERE cs.`id_order` = '.(int)$id_order
);
}
/**
* @return array
*/
public static function getAll()
{
$date = new DateTime();
$date->sub(new DateInterval("P1M"));
return Db::getInstance()->executeS('
SELECT cs.`id_colissimo_suivi`
FROM `'._DB_PREFIX_.'colissimo_suivi` cs
WHERE cs.`date_add` > \''.$date->format('Y-m-d H:i:s').'\'
AND SUBSTR(cs.event_code, 0, 3) != \'LIV\''
);
}
}