Il manquait plein de fichiers dans Git

This commit is contained in:
2021-11-05 21:52:08 +01:00
parent ebb1376015
commit 50b55fba14
47 changed files with 3945 additions and 992 deletions

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the module AdminOrderCreation */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace AdminOrderCreation\Util;
class Calc
{
public static function reduction($value, $type, $price, $quantity = 1)
{
$type = (int) $type;
$value = (float) $value;
$quantity = (float) $quantity;
if ($type === 1) {
if ($value < 0 || $value > 100) {
throw new \Exception('Invalid arg reduction');
}
return (($price / 100) * (100 - $value));
} elseif ($type === 2) {
if ($value < 0 || $value > $price * $quantity) {
throw new \Exception('Invalid arg reduction');
}
return ($price * $quantity - $value) / $quantity;
} elseif ($type === 3) {
if ($value < 0 || $value > $price) {
throw new \Exception('Invalid arg reduction');
}
return ($price - $value);
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* This file is part of the module AdminOrderCreation */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace AdminOrderCreation\Util;
use Propel\Runtime\ActiveQuery\ModelCriteria;
trait CriteriaSearchTrait
{
/**
* @param string $q
* @return string
*/
public function getRegex($q)
{
$q = explode(' ', $q);
$words = array();
foreach ($q as $v) {
$v = trim($v);
if (strlen($v) > 2 && preg_match('/^[a-z0-9]+$/i', $v)) {
$words[] = $v;
}
}
if (!count($words)) {
return null;
}
$regex = array();
$regex[] = '.*' . implode('.+', $words) . '.*';
if (count($words) > 1) {
$regex[] = '.*' . implode('.+', array_reverse($words)) . '.*';
}
return implode('|', $regex);
}
/**
* @param ModelCriteria $query
* @param array $columns
* @param string $q
*/
public function whereConcatRegex(ModelCriteria $query, array $columns, $q)
{
$query->where("CONCAT_WS(' ', " . implode(',', $columns). ") REGEXP ?", self::getRegex($q), \PDO::PARAM_STR);
}
}