浏览代码

[loggable] made some of logEntry properties overridable in order to customize length or type

Gediminas Morkevicius 14 年之前
父节点
当前提交
11b2b6a717

+ 8 - 12
lib/Gedmo/Loggable/Entity/AbstractLogEntry.php

@@ -37,14 +37,14 @@ abstract class AbstractLogEntry
      *
      * @Column(name="object_id", length=32, nullable=true)
      */
-    private $objectId;
+    protected $objectId;
     
     /**
      * @var string $objectClass
      *
      * @Column(name="object_class", type="string", length=255)
      */
-    private $objectClass;
+    protected $objectClass;
     
     /**
      * @var integer $version
@@ -56,16 +56,16 @@ abstract class AbstractLogEntry
     /** 
      * @var text $data
      * 
-     * @Column(type="text", nullable=true) 
+     * @Column(type="array", nullable=true) 
      */
-    private $data;
+    protected $data;
     
     /** 
      * @var text $data
      * 
      * @Column(length=255, nullable=true) 
      */
-    private $username;
+    protected $username;
     
     /**
      * Get action
@@ -170,11 +170,11 @@ abstract class AbstractLogEntry
     /**
      * Get data
      * 
-     * @return array or null
+     * @return array
      */
     public function getData()
     {
-        return is_string($this->data) ? unserialize($this->data) : null;
+        return $this->data;
     }
 
     /**
@@ -184,11 +184,7 @@ abstract class AbstractLogEntry
      */
     public function setData($data)
     {
-        if (is_array($data)) {
-            $this->data = serialize($data);
-        } else {
-            $this->data = $data;
-        }
+        $this->data = $data;
     }
     
     /**

+ 13 - 2
lib/Gedmo/Loggable/Entity/Repository/LogEntryRepository.php

@@ -25,6 +25,18 @@ class LogEntryRepository extends EntityRepository
      * @return array
      */ 
     public function getLogEntries($entity)
+    {
+        $q = $this->getLogEntriesQuery($entity);
+        return $q->getResult();
+    }
+    
+    /**
+     * Get the query for loading of log entries
+     * 
+     * @param object $entity
+     * @return Query
+     */
+    public function getLogEntriesQuery($entity)
     {
         $objectClass = get_class($entity);
         $objectMeta = $this->_em->getClassMetadata($objectClass);
@@ -38,8 +50,7 @@ class LogEntryRepository extends EntityRepository
         $objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($entity);
         $q = $this->_em->createQuery($dql);
         $q->setParameters(compact('objectId', 'objectClass', 'order'));
-        
-        return $q->getResult();
+        return $q;
     }
     
     /**