Просмотр исходного кода

Refactory sql select query en AuditDataService

Guillermo Espinoza 8 лет назад
Родитель
Сommit
fd1bb02577
2 измененных файлов с 11 добавлено и 3 удалено
  1. 2 2
      Resources/views/Audit/index.html.twig
  2. 9 1
      Services/AuditDataService.php

+ 2 - 2
Resources/views/Audit/index.html.twig

@@ -72,11 +72,11 @@
         }
     </style>    
     <div class="col-xs-12 col-md-12">   
-        <div class="box">   
+        <div class="box">
             <form id="filter_form" action="{{ url('entity_audit') }}" method="POST">
                 <fieldset class="filter_legend">
                     <legend class="filter_legend"> <i id="filter-icon" class="glyphicon glyphicon-chevron-up btn-xs"></i> {{ 'FILTROS'|trans({}, 'AuditBundle') }}</legend>
-                    <div class="filter_container {% if data|length == 0 %}inactive{% endif %}" style="padding: 0 15px 15px 15px;">
+                    <div class="filter_container {% if data|length == 0 and not form.vars.submitted %}inactive{% endif %}" style="padding: 0 15px 15px 15px;">
                         <table class="bordered-table">
                             <tbody>
                                 <tr class="filter">

+ 9 - 1
Services/AuditDataService.php

@@ -179,7 +179,15 @@ class AuditDataService
      */
     private function buildSelect($entity, $count = false)
     {
-        $select = 'SELECT C.rev, C.id, C.revtype, R.username, R.timestamp ';
+        $entities = $this->getEntities();
+        $primaryKeyQuery = "SHOW KEYS FROM `{$entities[$entity]}` WHERE Key_name = 'PRIMARY';";
+        $primaryKey = $this->connection->fetchAll($primaryKeyQuery);
+        $id = 'id';
+        if (isset($primaryKey[0])) {
+            $id = $primaryKey[0]['Column_name'];
+        }
+
+        $select = "SELECT C.rev, C.{$id} as id, C.revtype, R.username, R.timestamp ";
         if ($count) {
             $select = 'SELECT COUNT(*) as total ';
         }