Changeset 21798
- Timestamp:
- 09/08/09 23:04:06 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/pkToolkitPlugin/trunk/lib/helper/pkSubCrudHelper.php
r21709 r21798 15 15 // $publishedColumn is the name of the boolean column that indicates this subform is ready for publication. 16 16 17 function pk_sub_crud_chunk($label, $type, $subtype, $object, $publishedColumn = false )17 function pk_sub_crud_chunk($label, $type, $subtype, $object, $publishedColumn = false, $canEditMethod = 'userCanEdit') 18 18 { 19 19 $s = ''; … … 29 29 } 30 30 // 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(); 32 33 if ($canEdit) 33 34 { … … 72 73 { 73 74 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 } 75 85 76 86 $s = jq_form_remote_tag(array( plugins/pkToolkitPlugin/trunk/lib/pkSubCrudActions.class.php
r21709 r21798 109 109 if ($request->hasParameter('form')) 110 110 { 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'); 114 132 } 115 133 plugins/pkToolkitPlugin/trunk/lib/pkSubCrudTools.class.php
r21632 r21798 3 3 class pkSubCrudTools 4 4 { 5 static public function getCurrentRelationForms($object, $type )5 static public function getCurrentRelationForms($object, $type, $formClass = false) 6 6 { 7 7 $cobject = get_class($object); 8 8 $relationClass = $cobject . 'User'; 9 $formClass = $cobject . 'UserForm'; 9 if ($formClass === false) 10 { 11 $formClass = $cobject . 'UserForm'; 12 } 10 13 // TODO: a way to impose an order on this list. Allowing the specification of 11 14 // extra ORDER BYs ought to be enough … … 62 65 return $matches; 63 66 } 67 68 static public function getFormClass($model, $subtype) 69 { 70 return $model . ucfirst($subtype) . 'Form'; 71 } 64 72 } 65 73