Development

Changeset 21798

You must first sign up to be able to contribute.

Changeset 21798

Show
Ignore:
Timestamp:
09/08/09 23:04:06 (4 years ago)
Author:
boutell
Message:

It is now possible to edit an aspect of the CRUD object that is actually stored by a relation specific to the user
(example: EventUser? for user-specific information about the event, such as an RSVP) as a pkSubCrud chunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/pkToolkitPlugin/trunk/lib/helper/pkSubCrudHelper.php

    r21709 r21798  
    1515// $publishedColumn is the name of the boolean column that indicates this subform is ready for publication. 
    1616 
    17 function pk_sub_crud_chunk($label, $type, $subtype, $object, $publishedColumn = false
     17function pk_sub_crud_chunk($label, $type, $subtype, $object, $publishedColumn = false, $canEditMethod = 'userCanEdit'
    1818{ 
    1919  $s = ''; 
     
    2929  } 
    3030  // If the user can edit then they have to have access whether it's published or not! 
    31   $canEdit = $object->userCanEdit(); 
     31   
     32  $canEdit = $object->$canEditMethod(); 
    3233  if ($canEdit) 
    3334  { 
     
    7273{ 
    7374  list($type, $subtype, $displayData) = _pk_sub_crud_form_info($form); 
    74   $oid = $form->getObject()->getId(); 
     75   
     76  // Necessary when we're editing a relation (EventUser) rather than the thing itself (Event) 
     77  if (method_exists($form, 'getCrudObjectId')) 
     78  { 
     79    $oid = $form->getCrudObjectId(); 
     80  } 
     81  else 
     82  { 
     83    $oid = $form->getObject()->getId(); 
     84  } 
    7585 
    7686  $s = jq_form_remote_tag(array( 
  • plugins/pkToolkitPlugin/trunk/lib/pkSubCrudActions.class.php

    r21709 r21798  
    109109    if ($request->hasParameter('form')) 
    110110    { 
    111       $class = $this->model . ucfirst($request->getParameter('form')) . 'Form'; 
    112       $this->form = new $class($this->getRoute()->getObject()); 
    113     } 
     111      $class = pkSubCrudTools::getFormClass($this->model, $request->getParameter('form')); 
     112       
     113      // Custom form getters in the subform classes allow for dependency objection in a way  
     114      // that permits a chunk to operate on a relation class (like EventUser) 
     115      // rather than directly on the object itself (like Event) 
     116 
     117      if (method_exists($class, 'getForm')) 
     118      { 
     119        $this->form = call_user_func(array($class, 'getForm'), $this->getRoute()->getObject(), $request); 
     120      } 
     121      else 
     122      { 
     123        $this->form = new $class($this->getRoute()->getObject()); 
     124      } 
     125      if (method_exists($this->form, 'userCanEdit') && (!$this->form->userCanEdit())) 
     126      { 
     127        throw new sfException('insufficient privileges'); 
     128      } 
     129      return; 
     130    } 
     131    throw new sfException('no form parameter'); 
    114132  } 
    115133 
  • plugins/pkToolkitPlugin/trunk/lib/pkSubCrudTools.class.php

    r21632 r21798  
    33class pkSubCrudTools 
    44{ 
    5   static public function getCurrentRelationForms($object, $type
     5  static public function getCurrentRelationForms($object, $type, $formClass = false
    66  { 
    77    $cobject = get_class($object); 
    88    $relationClass = $cobject . 'User'; 
    9     $formClass = $cobject . 'UserForm'; 
     9    if ($formClass === false) 
     10    { 
     11      $formClass = $cobject . 'UserForm';       
     12    } 
    1013    // TODO: a way to impose an order on this list. Allowing the specification of 
    1114    // extra ORDER BYs ought to be enough 
     
    6265    return $matches; 
    6366  } 
     67   
     68  static public function getFormClass($model, $subtype) 
     69  { 
     70    return $model . ucfirst($subtype) . 'Form'; 
     71  } 
    6472} 
    6573