| 34 | |
| 35 | Experiments: |
| 36 | |
| 37 | Added a new 'extends' concept called 'Relation' in $_customGroupExtends, and by editing CRM/Core/BAO/CustomQuery.php in the $extendsMap array, I added a mapping for 'Relation' => 'civicrm_relation' (which isn't a table, but is aliased and thus should be accessible when the search is run. This doesn't help, because the gp_surgery_data_13 data is known by CiviCRM to extend 'Organization' data objects, not 'Relation' ones. |
| 38 | |
| 39 | Tried a variant of the above, which points 'Organization' in the $extendsMap to civicrm_relation instead of civicrm_contact - this isn't a sustainable solution, as it would break other reports, but it is useful for experimentation. IT WORKS! |
| 40 | |
| 41 | So the question is how to get $this->_columns (which is run through a foreach() to generate a $table => $prop relationship, which in turn is used to find the table to be extended (i.e. keyed against) by looking in $mapper[$prop['extends']], which could reference a virtual object type (e.g. 'Relation') in the $extendsMap array, rather than the one it really extends, without wrecking the core code functionality. |
| 42 | |
| 43 | What is currently being passed in $this->_columns must be a key and an array. The key maps to $table, so is the table name, and the array contains at least one mapping for 'extends' to map to the object being extended. |
| 44 | |
| 45 | Key function is addCustomDataToColumns() in CRM/Report/Form.php - it creates a $customDAO by executing a query to obtain custom group and custom field data, and then populates the $this->_columns array with an array of entries keyed on the table_name, including ['dao'] (which is fixed to CRM_Contact_DAO_Contact), ['extends'] which is set to the value of $customDAO->extends (i.e. the entry in the database for 'cg.extends' and also ['groupings'] and ['group_title']. So whatever is in the database for 'cg.extends' gets passed ultimately through the $extendsMap and results in |
| 46 | |
| 47 | What I think we need is the capability in a form to set an 'over-ride' for the 'extends' value of $this->_columns, and a catch at line 2688 that looks up in the extendsMap UNLESS the over-ride is set, in which case, the over-ride value is used instead. But how to do that, when the custom data isn't directly referenced in the recruitmentreport.php - only the $customGroupExtends array is set. After that, everything is done in core code. |
| 48 | |
| 49 | Process is addCustomDataToColumns() happens when form is built (triggered by the __construct() function call) , but customDataFrom() happens when query is run, triggered by buildQuery(), called by postProcess() - so maybe something could be slotted in to the postProcess() function ahead of the call to buildQuery() which over-rules the 'extends' attribute for certain data? |
| 50 | |
| 51 | Let's do a fixed one to test it: |
| 52 | |
| 53 | What we would want would be to over-rule |
| 54 | THIS: |
| 55 | $this->_columns['civicrm_value_gp_surgery_data_13']['extends'] = 'Organization' |
| 56 | WITH: |
| 57 | $this->_columns['civicrm_value_gp_surgery_data_13']['extends'] = 'Relation' |
| 58 | |
| 59 | AND ALSO INSERT INTO CRM_Core_BAO_CustomQuery::$extendsMap if we can, thus: |
| 60 | |
| 61 | CRM_Core_BAO_CustomQuery::$extendsMap['Relation'] = 'civicrm_relation' |
| 62 | |
| 63 | This appears to work! |