Exemplo n.º 1
0
 /**
  * cycles thru all fields of a contribution and prepares the field data
  *
  * @param string $c 
  * @param string $compact 
  * @return void
  * @author Urs Hofer
  */
 function prepareApiContributionData($c, $compact, $request = null, $recursion = true)
 {
     /* Checks */
     if (!$c) {
         return false;
     }
     if (!$c->getId()) {
         return false;
     }
     $d = [];
     $_fids = [];
     $criteria = null;
     static $_oldtemplate = false;
     // Prepare Criteria if a selection of fields needs to be processed
     if ($request !== null && $request->getQueryParams()['data']) {
         // Reset fids on template change
         if ($c->getFortemplate() != $_oldtemplate) {
             $_fids = [];
         }
         // Populate Field Ids on the first call
         if (count($_fids) == 0) {
             foreach (explode('|', $request->getQueryParams()['data']) as $fieldname) {
                 $_f = $this->container->db->getTemplatefields()->filterByFieldname($fieldname)->filterByFortemplate($c->getFortemplate())->findOne();
                 if ($_f) {
                     $_fids[] = $_f->getId();
                 }
             }
         }
         $criteria = new \Propel\Runtime\ActiveQuery\Criteria();
         $criteria->add('_fortemplatefield', $_fids, \Propel\Runtime\ActiveQuery\Criteria::IN);
     }
     // Populate Data if called with populate true, if requests are omitted or a criteria is not null
     if ($request === null || $criteria !== null || $request->getQueryParams()['populate'] == "true") {
         foreach ($c->getDatas($criteria) as $field) {
             // Creating Fieldlist for further API Calls: Default: Do not resolve
             $_fieldlist = [];
             if ($request !== null) {
                 // If fields are defined: Select Fields also for recursive calls
                 if ($request->getQueryParams()['data']) {
                     $_fieldlist = explode('|', $request->getQueryParams()['data']);
                 } else {
                     if ($request->getQueryParams()['populate'] == "true") {
                         $_fieldlist = false;
                     }
                 }
             }
             $d[$field->getTemplates()->getFieldname()] = $this->prepareApiData($field, $compact, [], $_fieldlist, $recursion);
         }
     }
     return $d;
 }
Exemplo n.º 2
0
     // Get Template Id: Mostly it is the reference to forTemplate of Templatefield $args['id'],
     // only when adding, it's directly a template reference
     $templateId = $args['action'] == "sort" ? $args['id'] : $this->db->getTemplatefields()->findPk($args['id'])->getFortemplate();
     // Load Template
     $this->helpers->prepareTemplatesTemplate($args, $templateId);
     // Return json on update / rename
     $r = $response->withHeader('Content-type', 'application/json');
     $json = $this->view->offsetGet('csrf');
     // Template for various info
     $json['template'] = $args['template'];
     // Schema for the configuration editor
     // Nasty: schema is sent already as json. decode and add to array
     $json['schema'] = json_decode($args['schema'], true);
     // Fields array to overrule the enums for lengthInfluence in the schema.
     // Done via javascript on load in rf.templates.js
     $criteria = new \Propel\Runtime\ActiveQuery\Criteria();
     $criteria->addAscendingOrderByColumn(__sort__);
     $fields_in_template = [];
     foreach ($args['template']->getTemplatess($criteria) as $field) {
         $fields_in_template["id"][] = $field->getId();
         $fields_in_template["label"][] = $field->getFieldname();
         if ($field->getId() == $args['id']) {
             $json['newconfig'] = $field->GetFilteredConfigsys();
         }
     }
     $json['fieldinfo'] = $fields_in_template;
     $r->getBody()->write(json_encode($json));
     return $r;
 });
 /* Exporters
  *