Exemplo n.º 1
0
 /**
  * Render JSON response for forms
  * @param \GO\Base\Db\ActiveRecord $model the AWR to renerated the JSON form data for
  * @param array $remoteComboField List all fields that require a remote text to load for a remote combobox.
  * eg. with a model you want to provide the category name so that that the
  * category combo store does not need to be loaded to show it.
  * 
  * You would list that like this:
  * 
  * 'category_id'=>array('category','name')
  * 
  * The category name would be looked up in the model model ->category->name.
  * A relation for this must be defined. See ActiveRecord->relations.
  * @see AbstractModelController::remoteComboFields()
  * @param array $extraFields the extra fields that should be attached to the data array as key => value
  * @return \GO\Base\Data\JsonResponse Response object
  * @throws \GO\Base\Exception\AccessDenied
  */
 public function renderForm($model, $remoteComboFields = array(), $extraFields = array())
 {
     $response = array('data' => array(), 'success' => true);
     //TODO: check if this can be moved. This methode renders JSON and should not check permissions.
     if (!$model->checkPermissionLevel($model->isNew ? \GO\Base\Model\Acl::CREATE_PERMISSION : \GO\Base\Model\Acl::WRITE_PERMISSION)) {
         throw new \GO\Base\Exception\AccessDenied();
     }
     //Init data array
     $response['data'] = array_merge($model->getAttributes(), $extraFields);
     $response['data']['permission_level'] = $model->getPermissionLevel();
     $response['data']['write_permission'] = true;
     //Add the customerfields to the data array
     if (\GO::user()->getModulePermissionLevel('customfields') && $model->customfieldsRecord) {
         $response['data'] = array_merge($response['data'], $model->customfieldsRecord->getAttributes());
     }
     if (!empty($remoteComboFields)) {
         $response = $this->_loadComboTexts($model, $remoteComboFields, $response);
     }
     $this->fireEvent('form', array(&$this, &$response, &$model, &$remoteComboFields));
     return new \GO\Base\Data\JsonResponse($response);
 }