Commit a30dd89d authored by Laurent Lécluse's avatar Laurent Lécluse

Ajout d'une méthode pour savoir si une propriété d'une entité est synchronisée...

Ajout d'une méthode pour savoir si une propriété d'une entité est synchronisée ou non (utile pour mettre des champs de formulaires en lecture seule si les données sont synchronisées).
parent b3c14cad
Pipeline #7687 failed with stage
in 13 seconds
......@@ -19,6 +19,11 @@ class SchemaService extends AbstractService
*/
protected $schema;
/**
* @var array
*/
protected $importColsCache = [];
/**
......@@ -143,11 +148,11 @@ class SchemaService extends AbstractService
*/
public function getImportViews()
{
$sql = "SELECT view_name FROM USER_VIEWS WHERE view_name LIKE 'SRC_%'";
$stmt = $this->getEntityManager()->getConnection()->query($sql);
$sql = "SELECT view_name FROM USER_VIEWS WHERE view_name LIKE 'SRC_%'";
$stmt = $this->getEntityManager()->getConnection()->query($sql);
$views = [];
while ($d = $stmt->fetch()) {
$mvn = substr($d['VIEW_NAME'], 4);
$mvn = substr($d['VIEW_NAME'], 4);
$views[] = $mvn;
}
......@@ -184,21 +189,50 @@ class SchemaService extends AbstractService
*/
public function getImportCols($tableName)
{
$sql = "
SELECT
utc.COLUMN_NAME
FROM
USER_TAB_COLS utc
JOIN ALL_TAB_COLS atc ON (atc.table_name = 'SRC_' || utc.table_name AND atc.column_name = utc.column_name)
WHERE
utc.COLUMN_NAME NOT IN ('ID')
AND utc.COLUMN_NAME NOT LIKE 'HISTO_%'
AND utc.COLUMN_NAME NOT LIKE 'SOURCE_%'
AND utc.table_name = :tableName
ORDER BY
utc.COLUMN_NAME";
if (!array_key_exists($tableName, $this->importColsCache)) {
$sql = "
SELECT
utc.COLUMN_NAME
FROM
USER_TAB_COLS utc
JOIN USER_TAB_COLS atc ON (atc.table_name = 'SRC_' || utc.table_name AND atc.column_name = utc.column_name)
WHERE
utc.COLUMN_NAME NOT IN ('ID')
AND utc.COLUMN_NAME NOT LIKE 'HISTO_%'
AND utc.COLUMN_NAME NOT LIKE 'SOURCE_%'
AND utc.table_name = :tableName
ORDER BY
utc.COLUMN_NAME";
$this->importColsCache[$tableName] = $this->query($sql, ['tableName' => $tableName], 'COLUMN_NAME');
}
return $this->query($sql, ['tableName' => $tableName], 'COLUMN_NAME');
return $this->importColsCache[$tableName];
}
/**
* Détecte si une propriété d'une classe est importable ou non
*
* @param string|\stdClass $className
* @param string $fieldName
*
* @return bool
*/
public function isImportedProperty($className, string $fieldName): bool
{
if (is_object($className)){
$className = get_class($className);
}
$metadata = $this->getEntityManager()->getClassMetadata($className);
$tableName = $metadata->getTableName();
$columnName = $metadata->getColumnName($fieldName);
$importCols = $this->getImportCols($tableName);
return in_array($columnName, $importCols);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment