Atualizando Documents.class.php

This commit is contained in:
Kenio 2025-08-25 10:42:39 -03:00
parent 2c1956f6a0
commit 295bcbfaa0
2 changed files with 34 additions and 4 deletions

View file

@ -107,7 +107,7 @@ class Documents
}
/** Lista todos os egistros do banco com ou sem paginação*/
public function All(? int $start, ? int $max, ? int $documentsCategorysId, ? string $tag, ? string $label)
public function All(? int $start, ? int $max, ? int $documentsCategorysId, ? string $tag, ? string $label, ? int $companyId)
{
/** Parametros de entrada */
$this->start = $start;
@ -115,6 +115,7 @@ class Documents
$this->documentsCategorysId = $documentsCategorysId;
$this->tag = $tag;
$this->label = $label;
$this->companyId = $companyId;
$this->and = "";
/** Se houver categoria informada, crio o filtro de consulta*/
@ -122,6 +123,12 @@ class Documents
$this->and = " and d.documents_categorys_id = {$this->documentsCategorysId}";
//$this->and .= " and json_search(tag, 'all', '".$this->tag."', null, '$.".$this->label."') is not null";
}
/** Verifica se o company_id foi informado */
if($this->companyId > 0){
$this->and .= " and company_id = : company_id";
}
/** Verifico se há paginação */
@ -154,7 +161,15 @@ class Documents
$this->sql .= $this->limit;
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Verifica se o company_id foi informado */
if($this->companyId > 0){
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('documents_id', $this->documentsId);
}
/** Executo o SQL */
$this->stmt->execute();
@ -165,12 +180,13 @@ class Documents
}
/** Conta a quantidades de registros */
public function Count(? int $documentsCategorysId, ? string $tag, ? string $label)
public function Count(? int $documentsCategorysId, ? string $tag, ? string $label, ? int $companyId)
{
/** Parametros de entraa */
$this->documentsCategorysId = $documentsCategorysId;
$this->tag = $tag;
$this->label = $label;
$this->companyId = $companyId;
$this->and = "";
/** Se houver categoria informada, crio o filtro de consulta*/
@ -180,6 +196,12 @@ class Documents
//$this->and .= " and json_search(tag, 'all', '".$this->tag."', null, '$.".$this->label."') is not null";
}
/** Verifica se o company_id foi informado */
if($this->companyId > 0){
$this->and .= " and company_id = : company_id";
}
/** Consulta SQL */
$this->sql = 'select count(documents_id) as qtde
from documents
@ -189,6 +211,14 @@ class Documents
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Verifica se o company_id foi informado */
if($this->companyId > 0){
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('documents_id', $this->documentsId);
}
/** Executo o SQL */
$this->stmt->execute();

View file

@ -77,7 +77,7 @@ try{
<?php
/** Consulta os usuário cadastrados*/
$DocumentsResult = $Documents->All($start, $max, (int)$documentsCategorysId, (string)$tag, (string)$label, $companyId);
$DocumentsResult = $Documents->All($start, $max, (int)$documentsCategorysId, (string)$tag, (string)$label, (int)$companyId);
foreach($DocumentsResult as $DocumentsKey => $Result){
?>