Merge branch '2015.11' into 2015.11-develop
[tine20] / tine20 / Tinebase / Relations.php
index 2cb2415..4bff155 100644 (file)
@@ -701,7 +701,7 @@ class Tinebase_Relations
     public function transferRelations($sourceId, $destinationId, $model)
     {
         if (! Tinebase_Core::getUser()->hasRight('Tinebase', Tinebase_Acl_Rights::ADMIN)) {
-            throw new Tinebase_Exception_AccessDenied('Non admins of Tinebase aren\'t allowed to perform his operation!');
+            throw new Tinebase_Exception_AccessDenied('Only Admins are allowed to perform his operation!');
         }
         
         return $this->_backend->transferRelations($sourceId, $destinationId, $model);
@@ -730,4 +730,24 @@ class Tinebase_Relations
     {
         $this->_backend->removeApplication($applicationName);
     }
+
+    public function getRelationsOfRecordByDegree($record, $degree)
+    {
+        // get relations if not yet present OR use relation search here
+        if (empty($record->relations)) {
+            $backendType = 'Sql';
+            $modelName = get_class($record);
+            $record->relations = Tinebase_Relations::getInstance()->getRelations($modelName, $backendType, $record->getId());
+        }
+
+
+        $result = new Tinebase_Record_RecordSet('Tinebase_Model_Relation');
+        foreach ($record->relations as $relation) {
+            if ($relation->related_degree === $degree) {
+                $result->addRecord($relation);
+            }
+        }
+
+        return $result;
+    }
 }