Author: sevein
Date: Sat Oct 30 07:00:43 2010
New Revision: 8713

Log:
Use $resoure and DefaultEditAction class. Cosmetic changes.

Modified:
   trunk/apps/qubit/modules/user/actions/editActorAclAction.class.php
   trunk/apps/qubit/modules/user/templates/editActorAclSuccess.php

Modified: trunk/apps/qubit/modules/user/actions/editActorAclAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/user/actions/editActorAclAction.class.php  Sat Oct 
30 06:59:40 2010        (r8712)
+++ trunk/apps/qubit/modules/user/actions/editActorAclAction.class.php  Sat Oct 
30 07:00:43 2010        (r8713)
@@ -17,33 +17,28 @@
  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-class UserEditActorAclAction extends sfAction
+class UserEditActorAclAction extends DefaultEditAction
 {
-  public function execute($request)
-  {
-    $this->form = new sfForm;
+  public static
+    $NAMES = array();
 
-    $this->user = new QubitUser;
+  protected function earlyExecute()
+  {
+    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
 
-    if (isset($this->request->id))
+    $this->resource = new QubitUser;
+    if (isset($this->getRoute()->resource))
     {
-      $this->user = QubitUser::getById($this->request->id);
-
-      if (!isset($this->user))
-      {
-        $this->forward404();
-      }
+      $this->resource = $this->getRoute()->resource;
     }
 
-    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
-
     // Always include root actor permissions
     $this->actors = array(QubitActor::ROOT_ID => null);
 
     // Get actor permissions for this group
     $criteria = new Criteria;
     $criteria->addJoin(QubitAclPermission::OBJECT_ID, QubitObject::ID, 
Criteria::LEFT_JOIN);
-    $criteria->add(QubitAclPermission::USER_ID, $this->user->id);
+    $criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
     $c1 = $criteria->getNewCriterion(QubitAclPermission::OBJECT_ID, null, 
Criteria::ISNULL);
     $c2 = $criteria->getNewCriterion(QubitObject::CLASS_NAME, 'QubitActor');
     $c1->addOr($c2);
@@ -51,26 +46,15 @@
 
     if (null !== $permissions = QubitAclPermission::get($criteria))
     {
-      foreach ($permissions as $p)
+      foreach ($permissions as $item)
       {
-        $this->actors[$p->objectId][$p->action] = $p;
+        $this->actors[$item->objectId][$item->action] = $item;
       }
     }
 
     // List of actions without translate
     $this->basicActions = QubitAcl::$ACTIONS;
     unset($this->basicActions['translate']);
-
-    if ($request->isMethod('post'))
-    {
-      $this->form->bind($request->getPostParameters());
-
-      if ($this->form->isValid())
-      {
-        $this->processForm();
-        $this->redirect(array($this->user, 'module' => 'user', 'action' => 
'indexActorAcl'));
-      }
-    }
   }
 
   protected function processForm()
@@ -80,27 +64,18 @@
       // If key has an underscore, then we are creating a new permission
       if (1 == preg_match('/([\w]+)_(.*)/', $key, $matches))
       {
-        $actor = null;
         list ($action, $uri) = array_slice($matches, 1, 2);
         $params = $this->context->routing->parse(Qubit::pathInfo($uri));
-        if (isset($params['id']))
-        {
-          $actor = QubitActor::getById($params['id']);
-        }
-
-        if (null === $actor)
-        {
-          continue;
-        }
+        $resource = $params['_sf_route']->resource;
 
         if (QubitAcl::INHERIT != $value && isset(QubitAcl::$ACTIONS[$action]))
         {
           $aclPermission = new QubitAclPermission;
           $aclPermission->action = $action;
           $aclPermission->grantDeny = (QubitAcl::GRANT == $value) ? 1 : 0;
-          $aclPermission->object = $actor;
+          $aclPermission->object = $resource;
 
-          $this->user->aclPermissions[] = $aclPermission;
+          $this->resource->aclPermissions[] = $aclPermission;
         }
       }
 
@@ -114,14 +89,26 @@
         else
         {
           $aclPermission->grantDeny = (QubitAcl::GRANT == $value) ? 1 : 0;
-          $this->user->aclPermissions[] = $aclPermission;
+          $this->resource->aclPermissions[] = $aclPermission;
         }
       }
     }
+  }
+
+  public function execute($request)
+  {
+    if ($request->isMethod('post'))
+    {
+      $this->form->bind($request->getPostParameters());
 
-    // Save updates
-    $this->user->save();
+      if ($this->form->isValid())
+      {
+        $this->processForm();
+
+        $this->resource->save();
 
-    return $this;
+        $this->redirect(array($this->resource, 'module' => 'user', 'action' => 
'indexActorAcl'));
+      }
+    }
   }
 }

Modified: trunk/apps/qubit/modules/user/templates/editActorAclSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/user/templates/editActorAclSuccess.php     Sat Oct 
30 06:59:40 2010        (r8712)
+++ trunk/apps/qubit/modules/user/templates/editActorAclSuccess.php     Sat Oct 
30 07:00:43 2010        (r8713)
@@ -1,16 +1,16 @@
 <h1><?php echo __('Edit %1% permissions', array('%1%' => 
sfConfig::get('app_ui_label_actor'))) ?></h1>
 
-<h1 class="label"><?php echo $user->__toString() ?></h1>
+<h1 class="label">asdf<?php echo render_title($resource) ?></h1>
 
 <?php echo get_partial('aclGroup/addActorDialog', array('basicActions' => 
$basicActions)) ?>
 
-<form method="post" action="<?php echo url_for(array($user, 'module' => 
'user', 'action' => 'editActorAcl')) ?>" id="editForm">
+<?php echo $form->renderFormTag(url_for(array($resource, 'module' => 'user', 
'action' => 'editActorAcl')), array('id' => 'editForm')) ?>
 
-<?php foreach ($actors as $objectId => $permissions): ?>
-<div class="form-item">
-<?php echo get_component('aclGroup', 'aclTable', array('object' => 
QubitActor::getById($objectId), 'permissions' => $permissions, 'actions' => 
$basicActions)) ?>
-</div>
-<?php endforeach; ?>
+  <?php foreach ($actors as $key => $item): ?>
+    <div class="form-item">
+      <?php echo get_component('aclGroup', 'aclTable', array('object' => 
QubitActor::getById($key), 'permissions' => $item, 'actions' => $basicActions)) 
?>
+    </div>
+  <?php endforeach; ?>
 
   <div class="form-item">
     <label for="addActorLink"><?php echo __('Add permissions by %1%', 
array('%1%' => sfConfig::get('app_ui_label_actor'))) ?></label>
@@ -18,13 +18,16 @@
   </div>
 
   <div class="actions section">
+
     <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
+
     <div class="content">
       <ul class="clearfix links">
         <li><?php echo link_to(__('Cancel'), array($user, 'module' => 'user', 
'action' => 'indexActorAcl')) ?></li>
         <li><input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/></li>
       </ul>
     </div>
+
   </div>
 
 </form>

-- 
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.com/group/qubit-commits?hl=en.

Reply via email to