modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-10 16:46:28 +04:00
parent 3461d2eec8
commit 372780d454
2 changed files with 96 additions and 8 deletions

View File

@ -0,0 +1,86 @@
<?php
namespace nur\v\plugins;
use nur\v\BasePlugin;
use nur\v\v;
use nur\v\vo;
class showmorePlugin extends BasePlugin {
const HAVE_JQUERY = true;
/** @var string classe du conteneur */
const CONTAINER_CLASS = "showmore-container";
/** @var string classe de l'invite à en savoir plus */
const INVITE_CLASS = "showmore-invite";
/** @var string classe du panneau caché par défaut */
const INVITE_CONTENT = "En savoir plus...";
const PANEL_CLASS = "showmore-panel";
function startc(): array {
return v::sdiv(["class" => self::CONTAINER_CLASS]);
}
function invite($vs=null): array {
if ($vs === null) $vs = self::INVITE_CONTENT;
return v::a([
"class" => self::INVITE_CLASS,
"href" => "#",
$vs,
]);
}
function startp(): array {
return v::sdiv(["class" => [self::PANEL_CLASS, "hidden"]]);
}
function endp(): array {
return ["</div>"];
}
function endc(): array {
return ["</div>"];
}
function end(): array {
return ["</div></div>"];
}
function printStartc(): void {
vo::print($this->startc());
}
function printInvite($vs=null): void {
vo::print($this->invite($vs));
}
function printStartp(): void {
vo::print($this->startp());
}
function printEndp(): void {
vo::print($this->endp());
}
function printEndc(): void {
vo::print($this->endc());
}
function printEnd(): void {
vo::print($this->end());
}
function printJquery(): void {
?>
<script type="text/javascript">
jQuery.noConflict()(function($) {
$(".<?=self::INVITE_CLASS?>").click(function() {
let $this = $(this);
$this.addClass("hidden");
$this.closest(".<?=self::CONTAINER_CLASS?>").find(".<?=self::PANEL_CLASS?>").removeClass("hidden");
return false;
});
});
</script>
<?php
}
}

View File

@ -35,7 +35,9 @@ class CsvBuilder extends TempStream {
$this->csvFlavour = csv_flavours::verifix($csvFlavour); $this->csvFlavour = csv_flavours::verifix($csvFlavour);
$this->schema = $params["schema"] ?? static::SCHEMA; $this->schema = $params["schema"] ?? static::SCHEMA;
$this->headers = $params["headers"] ?? static::HEADERS; $this->headers = $params["headers"] ?? static::HEADERS;
$this->rows = $params["rows"] ?? null; $rows = $params["rows"] ?? null;
if (is_callable($rows)) $rows = $rows();
$this->rows = $rows;
$cookFunc = $params["cook_func"] ?? null; $cookFunc = $params["cook_func"] ?? null;
$cookCtx = $cookArgs = null; $cookCtx = $cookArgs = null;
if ($cookFunc !== null) { if ($cookFunc !== null) {
@ -70,14 +72,14 @@ class CsvBuilder extends TempStream {
$this->headers = $headers; $this->headers = $headers;
} }
protected bool $csvHeadersSent = false; protected bool $wroteHeaders = false;
function writeHeaders(?array $headers=null): void { function writeHeaders(?array $headers=null): void {
if ($this->csvHeadersSent) return; if ($this->wroteHeaders) return;
if ($headers !== null) $this->headers = $headers; if ($headers !== null) $this->headers = $headers;
else $this->ensureHeaders(); else $this->ensureHeaders();
if ($this->headers !== null) $this->fputcsv($this->headers); if ($this->headers !== null) $this->fputcsv($this->headers);
$this->csvHeadersSent = true; $this->wroteHeaders = true;
} }
protected function cookRow(?array $row): ?array { protected function cookRow(?array $row): ?array {
@ -101,7 +103,7 @@ class CsvBuilder extends TempStream {
function write(?array $row): void { function write(?array $row): void {
$row = $this->cookRow($row); $row = $this->cookRow($row);
if ($row === null) return; if ($row === null) return;
$this->ensureHeaders($row); $this->writeHeaders(array_keys($row));
$this->fputcsv($row); $this->fputcsv($row);
} }
@ -119,14 +121,14 @@ class CsvBuilder extends TempStream {
if ($unsetRows) $this->rows = null; if ($unsetRows) $this->rows = null;
} }
protected bool $httpHeadersSent = false; protected bool $sentHeaders = false;
function sendHeaders(): void { function sendHeaders(): void {
if ($this->httpHeadersSent) return; if ($this->sentHeaders) return;
http::content_type("text/csv"); http::content_type("text/csv");
$output = $this->output; $output = $this->output;
if ($output !== null) http::download_as($output); if ($output !== null) http::download_as($output);
$this->httpHeadersSent = true; $this->sentHeaders = true;
} }
function sendFile(?iterable $rows=null): int { function sendFile(?iterable $rows=null): int {