[+BUGFIX] Extbase (Persistence): Fixed a problem with empty $fieldValue causing an...
authorJochen Rau <j.rau@web.de>
Tue, 15 Sep 2009 11:22:59 +0000 (11:22 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 15 Sep 2009 11:22:59 +0000 (11:22 +0000)
[!!!][+BUGFIX] Extbase (Domain): Fixed support for usergroups and subgroups. Renamed properties subgroup to subgroups and usergroup to usergroups as they can hold multiple instances. Added mapping configuration. Resolves #4620.

typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php
typo3/sysext/extbase/Classes/Domain/Model/FrontendUserGroup.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/ext_typoscript_setup.txt

index 9dae178..1dfbcfc 100644 (file)
@@ -44,9 +44,9 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        protected $password;
 
        /**
-        * @var Tx_Extbase_Domain_Model_FrontendUserGroup
+        * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup>
         */
-       protected $usergroup;
+       protected $usergroups;
 
        /**
         * @var string
@@ -131,6 +131,7 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        public function __construct($username = '', $password = '') {
                $this->username = $username;
                $this->password = $password;
+               $this->usergroups = new Tx_Extbase_Persistence_ObjectStorage();
        }
 
        /**
@@ -176,24 +177,46 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        }
 
        /**
-        * Sets the usergroup value
+        * Sets the usergroups
+        *
+        * @param Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup> $usergroups An object storage containing the usergroups to add
+        * @return void
+        * @api
+        */
+       public function setUsergroups(Tx_Extbase_Persistence_ObjectStorage $usergroups) {
+               $this->usergroups = $usergroups;
+       }
+
+       /**
+        * Adds a usergroup to the frontend user
+        *
+        * @param Tx_Extbase_Domain_Model_FrontendUserGroup $usergroup
+        * @return void
+        * @api
+        */
+       public function addUsergroup(Tx_Extbase_Domain_Model_FrontendUserGroup $usergroup) {
+               $this->usergroups->attach($usergroup);
+       }
+
+       /**
+        * Removes a usergroup from the frontend user
         *
         * @param Tx_Extbase_Domain_Model_FrontendUserGroup $usergroup
         * @return void
         * @api
         */
-       public function setUsergroup(Tx_Extbase_Domain_Model_FrontendUserGroup $usergroup) {
-               $this->usergroup = $usergroup;
+       public function removeUsergroup(Tx_Extbase_Domain_Model_FrontendUserGroup $usergroup) {
+               $this->usergroups->detach($usergroup);
        }
 
        /**
-        * Returns the usergroup value
+        * Returns the usergroups
         *
-        * @return Tx_Extbase_Domain_Model_FrontendUserGroup
+        * @return Tx_Extbase_Persistence_ObjectStorage An object storage containing the usergroups
         * @api
         */
-       public function getUsergroup() {
-               return $this->usergroup;
+       public function getUsergroups() {
+               return $this->usergroups;
        }
 
        /**
index 8b4ec84..baec2aa 100644 (file)
@@ -49,16 +49,16 @@ class Tx_Extbase_Domain_Model_FrontendUserGroup extends Tx_Extbase_DomainObject_
        protected $description;
 
        /**
-        * @var string
+        * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup>
         */
-       // FIXME Support for subgroups
-       //protected $subgroup;
+       protected $subgroups;
 
        /**
         * Constructs a new Frontend User Group
         *
         */
        public function __construct($title) {
+               $this->subgroups = new Tx_Extbase_Persistence_ObjectStorage();
        }
 
        /**
@@ -125,24 +125,47 @@ class Tx_Extbase_Domain_Model_FrontendUserGroup extends Tx_Extbase_DomainObject_
        }
 
        /**
-        * Sets the subgroup value
+        * Sets the subgroups
+        *
+        * @param Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup> $subgroups An object storage containing the subgroups to add
+        * @return void
+        * @api
+        */
+       public function setSubgroups(Tx_Extbase_Persistence_ObjectStorage $subgroups) {
+               $this->subgroups = $subgroups;
+       }
+
+       /**
+        * Adds a subgroup to the frontend user
         *
         * @param Tx_Extbase_Domain_Model_FrontendUserGroup $subgroup
         * @return void
         * @api
         */
-       public function setSubgroup($subgroup) {
-               $this->subgroup = $subgroup;
+       public function addSubgroup(Tx_Extbase_Domain_Model_FrontendUserGroup $subgroup) {
+               $this->subgroups->attach($subgroup);
        }
 
        /**
-        * Returns the subgroup value
+        * Removes a subgroup from the frontend user group
         *
-        * @return Tx_Extbase_Domain_Model_FrontendUserGroup
+        * @param Tx_Extbase_Domain_Model_FrontendUserGroup $subgroup
+        * @return void
+        * @api
+        */
+       public function removeSubgroup(Tx_Extbase_Domain_Model_FrontendUserGroup $subgroup) {
+               $this->subgroups->detach($subgroup);
+       }
+
+       /**
+        * Returns the subgroups
+        *
+        * @return Tx_Extbase_Persistence_ObjectStorage An object storage containing the subgroups
         * @api
         */
-       public function getSubgroup() {
-               return $this->subgroup;
+       public function getSubgroups() {
+               return $this->subgroups;
        }
+
 }
 ?>
\ No newline at end of file
index 218651a..45c0680 100644 (file)
@@ -232,10 +232,12 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                                if ($columnMap->getLoadingStrategy() === Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_LAZY_STORAGE) {
                                        $objectStorage = new Tx_Extbase_Persistence_LazyObjectStorage($parentObject, $propertyName, $fieldValue, $columnMap);
                                } else {
-                                       $objects = $this->fetchRelatedObjects($parentObject, $propertyName, $fieldValue, $columnMap);
                                        $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
-                                       foreach ($objects as $object) {
-                                               $objectStorage->attach($object);
+                                       if (!empty($fieldValue)) {
+                                               $objects = $this->fetchRelatedObjects($parentObject, $propertyName, $fieldValue, $columnMap);
+                                               foreach ($objects as $object) {
+                                                       $objectStorage->attach($object);
+                                               }
                                        }
                                }
                                $result = $objectStorage;
index 8f31ee5..f9a44e6 100644 (file)
@@ -6,6 +6,7 @@ config.tx_extbase {
                                        tableName = fe_users
                                        columns {
                                                usergroup.foreignClass = Tx_Extbase_Domain_Model_FrontendUserGroup
+                                               usergroup.mapOnProperty = usergroups
                                                lockToDomain.mapOnProperty = lockToDomain
                                        }
                                }
@@ -15,6 +16,7 @@ config.tx_extbase {
                                        tableName = fe_groups
                                        columns {
                                                subgroup.foreignClass = Tx_Extbase_Domain_Model_FrontendUserGroup
+                                               subgroup.mapOnProperty = subgroups
                                                lockToDomain.mapOnProperty = lockToDomain
                                        }
                                }