ajout control title
This commit is contained in:
parent
49e312b397
commit
111a87bc3b
|
@ -67,7 +67,7 @@ Application::run(new class extends Application {
|
|||
$channel = new $channelClass;
|
||||
} elseif ($this->tableName !== null) {
|
||||
$channel = new class($this->tableName) extends CapacitorChannel {
|
||||
public function __construct(?string $name=null) {
|
||||
function __construct(?string $name=null) {
|
||||
parent::__construct($name);
|
||||
$this->tableName = $name;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ Application::run(new class extends Application {
|
|||
$channel = new $channelClass;
|
||||
} elseif ($this->tableName !== null) {
|
||||
$channel = new class($this->tableName) extends CapacitorChannel {
|
||||
public function __construct(?string $name=null) {
|
||||
function __construct(?string $name=null) {
|
||||
parent::__construct($name);
|
||||
$this->tableName = $name;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace nur\v\bs3\fo;
|
||||
|
||||
use nur\A;
|
||||
use nur\b\params\Tparametrable;
|
||||
|
||||
class ControlTitle extends ControlVisual {
|
||||
use Tparametrable;
|
||||
|
||||
const PARAMETRABLE_PARAMS_SCHEMA = [
|
||||
"title" => ["?content", null, "texte du titre"],
|
||||
];
|
||||
|
||||
/** @var array|string */
|
||||
protected $ppTitle;
|
||||
|
||||
function getLayout(array $control): array {
|
||||
return $this->getFgsLayout($control, true);
|
||||
}
|
||||
|
||||
function getControl(): array {
|
||||
$control = A::with(q($this->ppTitle));
|
||||
if ($this->ppNaked) return $control;
|
||||
else return $this->getLayout($control);
|
||||
}
|
||||
}
|
|
@ -743,6 +743,24 @@ class Form extends ComponentPrintable implements IParametrable, ArrayAccess, Cou
|
|||
function endGroup(): void {
|
||||
}
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# title
|
||||
|
||||
function title($title, ?array $params=null): ControlTitle {
|
||||
A::set_nz($params, "title", $title);
|
||||
$this->fixControlParams($params);
|
||||
return new ControlTitle($this, $params);
|
||||
}
|
||||
|
||||
function addTitle($title, ?array $params=null): self {
|
||||
$this->addControl($this->title($title, $params));
|
||||
return $this;
|
||||
}
|
||||
|
||||
function printTitle($title, ?array $params=null): void {
|
||||
vo::write($this->title($title, $params));
|
||||
}
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# hidden
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ class CapacitorChannel {
|
|||
|
||||
const PRIMARY_KEYS = null;
|
||||
|
||||
const MANAGE_TRANSACTIONS = true;
|
||||
|
||||
const EACH_COMMIT_THRESHOLD = 100;
|
||||
|
||||
static function verifix_name(?string $name): string {
|
||||
|
@ -23,10 +25,17 @@ class CapacitorChannel {
|
|||
return strtolower($name);
|
||||
}
|
||||
|
||||
function __construct(?string $name=null, ?int $eachCommitThreshold=null) {
|
||||
protected static function verifix_eachCommitThreshold(?int $eachCommitThreshold): ?int {
|
||||
$eachCommitThreshold ??= static::EACH_COMMIT_THRESHOLD;
|
||||
if ($eachCommitThreshold < 0) $eachCommitThreshold = null;
|
||||
return $eachCommitThreshold;
|
||||
}
|
||||
|
||||
function __construct(?string $name=null, ?int $eachCommitThreshold=null, ?bool $manageTransactions=null) {
|
||||
$this->name = self::verifix_name($name ?? static::NAME);
|
||||
$this->tableName = static::TABLE_NAME ?? ($this->name."_channel");
|
||||
$this->eachCommitThreshold = $eachCommitThreshold ?? static::EACH_COMMIT_THRESHOLD;
|
||||
$this->manageTransactions = $manageTransactions ?? static::MANAGE_TRANSACTIONS;
|
||||
$this->eachCommitThreshold = self::verifix_eachCommitThreshold($eachCommitThreshold);
|
||||
$this->setup = false;
|
||||
$this->created = false;
|
||||
$columnDefinitions = cl::withn(static::COLUMN_DEFINITIONS);
|
||||
|
@ -50,37 +59,59 @@ class CapacitorChannel {
|
|||
$this->primaryKeys = $primaryKeys;
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
protected $name;
|
||||
protected string $name;
|
||||
|
||||
function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
protected $tableName;
|
||||
protected string $tableName;
|
||||
|
||||
function getTableName(): string {
|
||||
return $this->tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool indiquer si les modifications de each doivent être gérées dans
|
||||
* une transaction. si false, l'utilisateur doit lui même gérer la
|
||||
* transaction.
|
||||
*/
|
||||
protected bool $manageTransactions;
|
||||
|
||||
function isManageTransactions(): bool {
|
||||
return $this->manageTransactions;
|
||||
}
|
||||
|
||||
function setManageTransactions(bool $manageTransactions=true): self {
|
||||
$this->manageTransactions = $manageTransactions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var ?int nombre maximum de modifications dans une transaction avant un
|
||||
* commit automatique dans {@link Capacitor::each()}. Utiliser null pour
|
||||
* désactiver la fonctionnalité.
|
||||
*
|
||||
* ce paramètre n'a d'effet que si $manageTransactions==true
|
||||
*/
|
||||
protected $eachCommitThreshold;
|
||||
protected ?int $eachCommitThreshold;
|
||||
|
||||
function getEachCommitThreshold(): ?int {
|
||||
return $this->eachCommitThreshold;
|
||||
}
|
||||
|
||||
function setEachCommitThreshold(?int $eachCommitThreshold=null): self {
|
||||
$this->eachCommitThreshold = self::verifix_eachCommitThreshold($eachCommitThreshold);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialiser ce channel avant sa première utilisation.
|
||||
*/
|
||||
protected function setup(): void {
|
||||
}
|
||||
|
||||
protected $setup;
|
||||
protected bool $setup;
|
||||
|
||||
function ensureSetup() {
|
||||
if (!$this->setup) {
|
||||
|
@ -89,7 +120,7 @@ class CapacitorChannel {
|
|||
}
|
||||
}
|
||||
|
||||
protected $created;
|
||||
protected bool $created;
|
||||
|
||||
function isCreated(): bool {
|
||||
return $this->created;
|
||||
|
|
|
@ -362,10 +362,13 @@ EOT;
|
|||
$onEach = func::_prepare($func);
|
||||
$db = $this->db();
|
||||
$tableName = $channel->getTableName();
|
||||
$commited = false;
|
||||
$manageTransactions = $channel->isManageTransactions();
|
||||
$count = 0;
|
||||
if ($manageTransactions) {
|
||||
$commited = false;
|
||||
$db->beginTransaction();
|
||||
$commitThreshold = $channel->getEachCommitThreshold();
|
||||
}
|
||||
try {
|
||||
$args ??= [];
|
||||
foreach ($this->_all($channel, $filter) as $rowValues) {
|
||||
|
@ -381,7 +384,7 @@ EOT;
|
|||
"values" => $this->serialize($channel, $updates),
|
||||
"where" => $rowIds,
|
||||
]);
|
||||
if ($commitThreshold !== null) {
|
||||
if ($manageTransactions && $commitThreshold !== null) {
|
||||
$commitThreshold--;
|
||||
if ($commitThreshold == 0) {
|
||||
$db->commit();
|
||||
|
@ -392,11 +395,13 @@ EOT;
|
|||
}
|
||||
$count++;
|
||||
}
|
||||
if ($manageTransactions) {
|
||||
$db->commit();
|
||||
$commited = true;
|
||||
}
|
||||
return $count;
|
||||
} finally {
|
||||
if (!$commited) $db->rollback();
|
||||
if ($manageTransactions && !$commited) $db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,10 +427,13 @@ EOT;
|
|||
$onEach = func::_prepare($func);
|
||||
$db = $this->db();
|
||||
$tableName = $channel->getTableName();
|
||||
$commited = false;
|
||||
$manageTransactions = $channel->isManageTransactions();
|
||||
$count = 0;
|
||||
if ($manageTransactions) {
|
||||
$commited = false;
|
||||
$db->beginTransaction();
|
||||
$commitThreshold = $channel->getEachCommitThreshold();
|
||||
}
|
||||
try {
|
||||
$args ??= [];
|
||||
foreach ($this->_all($channel, $filter) as $rowValues) {
|
||||
|
@ -437,7 +445,7 @@ EOT;
|
|||
"from" => $tableName,
|
||||
"where" => $rowIds,
|
||||
]);
|
||||
if ($commitThreshold !== null) {
|
||||
if ($manageTransactions && $commitThreshold !== null) {
|
||||
$commitThreshold--;
|
||||
if ($commitThreshold == 0) {
|
||||
$db->commit();
|
||||
|
@ -448,11 +456,13 @@ EOT;
|
|||
}
|
||||
$count++;
|
||||
}
|
||||
if ($manageTransactions) {
|
||||
$db->commit();
|
||||
$commited = true;
|
||||
}
|
||||
return $count;
|
||||
} finally {
|
||||
if (!$commited) $db->rollback();
|
||||
if ($manageTransactions && !$commited) $db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue