Commit a30dd89d authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

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
Loading
Loading
Loading
Loading
Loading
+51 −17
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@ class SchemaService extends AbstractService
     */
    protected $schema;

    /**
     * @var array
     */
    protected $importColsCache = [];



    /**
@@ -184,12 +189,13 @@ class SchemaService extends AbstractService
     */
    public function getImportCols($tableName)
    {
        if (!array_key_exists($tableName, $this->importColsCache)) {
            $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)
              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_%'
@@ -198,7 +204,35 @@ class SchemaService extends AbstractService
            ORDER BY
              utc.COLUMN_NAME";

        return $this->query($sql, ['tableName' => $tableName], 'COLUMN_NAME');
            $this->importColsCache[$tableName] = $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