Espinoza Guillermo пре 6 година
родитељ
комит
be9f616e8e
3 измењених фајлова са 42 додато и 16 уклоњено
  1. 9 2
      Controller/AuditController.php
  2. 2 2
      Resources/views/Audit/index.html.twig
  3. 31 12
      Services/AuditDataService.php

+ 9 - 2
Controller/AuditController.php

@@ -104,7 +104,10 @@ class AuditController extends Controller
         $result = $auditDataService->viewRevision($className, $id, $rev);
 
         $data = array(
-            'label' => $this->get('translator')->trans('Detalles de la revisión: %rev%', array('%rev%' => $rev), 'AuditBundle'),
+            'label' => $this->get('translator')->trans(
+                'Detalles de la revisión: %rev%', array(
+                    '%rev%' => $rev
+                ), 'AuditBundle'),
             'className' => $className,
             'classValue' => $classValue,
             'id' => $id,
@@ -144,7 +147,11 @@ class AuditController extends Controller
             $diff = $auditDataService->diff($className, $id, $oldRev, $newRev);
 
             $data = array(
-                'label' => $this->get('translator')->trans('Comparativa entre las revisiones %oldRev% y %newRev%', array('%oldRev%' => $oldRev, '%newRev%' => $newRev), 'AuditBundle'),
+                'label' => $this->get('translator')->trans(
+                    'Comparativa entre las revisiones %oldRev% y %newRev%', array(
+                        '%oldRev%' => $oldRev, 
+                        '%newRev%' => $newRev
+                    ), 'AuditBundle'),
                 'className' => $className,
                 'classValue' => $classValue,
                 'id' => $id,

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

@@ -278,7 +278,7 @@
 
 {% block list_table %}
     <div class="col-xs-12 col-md-12">
-        <div class="box box-primary" style="margin-bottom: 100px; min-height: ">
+        <div class="box box-primary" style="margin-bottom: 100px; overflow: auto;">
             {% if data and is_post %}
                 <div class="box-body no-padding table-responsive">
                     <p style="float: right; margin: 10px">{{ total }} {{ 'resultado(s)'|trans({}, 'AuditBundle') }}</p>
@@ -304,7 +304,7 @@
                                     <td style="font-size: 14px">
                                         <ul>
                                             {% for column in columns[entity] %}
-                                                <li style="float: left; width: 23%; margin-right: 2%; line-height: 1 !important"><strong>{{ column }}:</strong> {{ item[column] }}</li>
+                                                <li style="word-wrap: break-word; float: left; width: 1500px; margin-right: 2%; line-height: 2 !important"><strong>{{ column }}:</strong> {{ item[column] }}</li>
                                             {% endfor %}
                                         </ul>
                                     </td>

+ 31 - 12
Services/AuditDataService.php

@@ -164,24 +164,27 @@ class AuditDataService
         
         $from = $this->buildFrom($entity);
         $where = $this->buildWhere($entity, $users, $types, $idx, $dateFrom, $dateTo, $searchValue);
+        
+        $groupBy = $this->buildGroupBy($entity);
+        
+        $sql_cnt = $this->buildSelect($entity, true) . $from . $where . $groupBy;
+        $fetchAll = $this->connection->query($sql_cnt)->fetchAll();
+        
+        $count = 0;
+        foreach ($fetchAll as $row) {
+            $count += isset($row['total']) ? $row['total'] : 0;
+        }
 
-        $sql_cnt = $this->buildSelect($entity, true) . $from . $where;
-        $count = $this->connection->query($sql_cnt)->fetchAll()[0]['total'];
-
-        $sql = $this->buildSelect($entity) . $from . $where;
-        $sql .= "ORDER BY R.timestamp DESC ";
-
-        // print_r("<pre>");
-        // print_r($sql);
-        // print_r("</pre>");
+        $sql = $this->buildSelect($entity) . $from . $where . $groupBy;
+        $sql .= " ORDER BY R.timestamp DESC ";
 
         if(is_null($resxpage)) $resxpage = 10;
-
+        
         if ($resxpage != "inf") {
             $pages = ceil(($count / floatval($resxpage)));
             $from = ($page - 1) * $resxpage;
             //$to = ($page) * $resxpage;
-            $sql .= "LIMIT {$from},{$resxpage}";
+            $sql .= " LIMIT {$from},{$resxpage} ";
         }
         
         return array(
@@ -290,8 +293,24 @@ class AuditDataService
                 $where .= ') ';
             }
         }
-        
+                
         return $where;
     }
     
+    /**
+     * @return string
+     */
+    private function buildGroupBy($entity)
+    {
+        $columns = $this->getColumns();
+        $groupBy[] = 'C.rev';
+        foreach ($columns[$entity] as $column) {
+            $groupBy[] = "C.{$column}";
+        }
+        $groupBy = implode(', ', $groupBy);
+        $groupBy = " GROUP BY {$groupBy} ";
+    
+        return $groupBy;
+    }
+    
 }