Author: david
Date: Sun Sep 13 16:37:40 2009
New Revision: 3254

Log:
Add methods for setting, getting and evaluating repositoryId limits on ACL 
permissions.

Modified:
   trunk/plugins/qbAclPlugin/lib/model/QubitAclPermission.php

Modified: trunk/plugins/qbAclPlugin/lib/model/QubitAclPermission.php
==============================================================================
--- trunk/plugins/qbAclPlugin/lib/model/QubitAclPermission.php  Sun Sep 13 
16:35:24 2009        (r3253)
+++ trunk/plugins/qbAclPlugin/lib/model/QubitAclPermission.php  Sun Sep 13 
16:37:40 2009        (r3254)
@@ -19,8 +19,75 @@
 
 class QubitAclPermission extends BaseAclPermission
 {
+  public function setRepository($repository)
+  {
+    if ($repository instanceof QubitRepository)
+    {
+      $this->conditional = '%p[repositoryId] == %k[repositoryId]';
+      $this->constants = serialize(array('repositoryId' => $repository->id));
+    }
+
+    return $this;
+  }
+
   public function getRepository()
   {
-    return null;
+    $repositoryId = null;
+    $constants = unserialize($this->constants);
+
+    if (isset($constants['repositoryId']))
+    {
+      $repositoryId = $constants['repositoryId'];
+    }
+
+    return QubitRepository::getById($repositoryId);
+  }
+
+  public function accessRepository($repositoryId)
+  {
+    $constants = unserialize($this->constants);
+
+    if (!isset($constants['repositoryId']))
+    {
+
+      // If no repository constant is defined, then all repositories are 
accessible
+      return true;
+    }
+
+    return $this->evaluateConditional($parameters = array('repositoryId' => 
$repositoryId));
+  }
+
+  public function evaluateConditional($parameters)
+  {
+    $conditional = $this->conditional;
+    $constants = unserialize($this->constants);
+
+    // Substitute constants
+    if (preg_match_all('/%k\[(\w+)\]/', $conditional, $matches))
+    {
+      foreach ($matches[1] as $match)
+      {
+        if (isset($constants[$match]))
+        {
+          $conditional = str_replace('%k['.$match.']', 
'\''.$constants[$match].'\'', $conditional);
+        }
+      }
+    }
+
+    // Substitute parameters
+    if (preg_match_all('/%p\[(\w+)\]/', $conditional, $matches))
+    {
+      foreach ($matches[1] as $match)
+      {
+        if (isset($parameters[$match]))
+        {
+          $conditional = str_replace('%p['.$match.']', 
'\''.$parameters[$match].'\'', $conditional);
+        }
+      }
+    }
+
+    var_dump('Conditional: '.$conditional);
+    // evaluate conditional
+    return eval('return ('.$conditional.');');
   }
 }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to