jaredcobb/ccb-core

Additional Group Fields

Closed this issue · 3 comments

Not an issue as much as a question: implementing for a church who wants to pull in Assistant leader info. I found where I would do the edit to the code: class-ccb-core-cpts.php ~255.

I don't like edit Plugin code since an update to the plugin will break the code. Any thoughts or recommendations on adding additional fields to the sync?

Great question. My plan is to drop several filters and actions into this plugin before the final stable release (which I'd like to be out no later than the end of this summer). I'd also like to get a lot of this documented. This is exactly the sort of feedback that will help drive that.

What are your thoughts on me adding a filter to the custom_fields_map that allows you to hook into this array and add / edit the mappings?

With regards to the Assistant Leader, that might be another filter. Unfortunately the Assistant Leaders are only returned if the API request includes include_participants=true. I'm currently setting that to false because the XML response can be gigantic for most churches. (It can go from a few hundred KB to 20MB).

So maybe a filter to allow you to return the participants and another filter to customize that mapping?

Jared,

thanks for the quick response. I agree that filters/actions is a good call for this. I am poking around editing the core ~ line 255, to see if I can pull in leaders.

it looks like:
<leaders> <leader id="34"> <first_name>Assistant</first_name> <last_name>Group Leader</last_name> <full_name>Assistant Group Leader</full_name> <email>tsebastian@ccbhq.com</email> <phones> <phone type="contact"></phone> </phones> </leader> </leaders>

is an array of leaders, but you may be right that it takes getting participants. Great plugin so far.

Right, the CCB API documentation isn't super clear on that. When you call group_profiles with include_participants=false you only get a single node for the main leader like so:

<group id="336">
     <name>Group Name</name>
     <description>Group Desc</description>
     <campus id="1">Main Campus</campus>
     <main_leader id="123">
          <first_name>John</first_name>
          <last_name>Doe</last_name>
          <full_name>John Doe</full_name>
          <email>jdoe@email.com</email>
          <phones>
               <phone type="contact"></phone>
          </phones>
     </main_leader>
</group>

So in class-ccb-core-cpts.php get_groups_custom_fields_map() this structure will map that leader's name and email into the custom fields leader_full_name and leader_email.

However if you call group_profiles with include_participants=true you get a <leaders> node (and a ton of participant nodes) like so:

<group id="336">
     <name>Group Name</name>
     <description>Group Desc</description>
     <campus id="1">Main Campus</campus>
     <main_leader id="123">
          <first_name>John</first_name>
          <last_name>Doe</last_name>
          <full_name>John Doe</full_name>
          <email>jdoe@email.com</email>
          <phones>
               <phone type="contact"></phone>
          </phones>
     </main_leader>
     <leaders>
          <leader id="321">
               <first_name>Jane</first_name>
               <last_name>Smith</last_name>
               <full_name>Jane Smith</full_name>
               <email>jsmith@email.com</email>
               <phones>
                    <phone type="contact"></phone>
               </phones>
          </leader>
     </leaders>
     <participants>
          <participant id="246">
               ...
          </participant>
     <participants>
</group>

Once this node is available to the get_groups_custom_fields_map() function (or filter) then the structure might look like this:

...
'leaders' => array(
    'api_mapping' => 'leaders',
    'data_type' => 'object',
    'child_object' => array(
        'leader' => array(
            'api_mapping' => 'leader',
            'data_type' => 'object',
            'child_object' => array(
                'assistant_leader_full_name' => array(
                    'api_mapping' => 'full_name',
                    'data_type' => 'string'
                ),
                'assistant_leader_email' => array(
                    'api_mapping' => 'email',
                    'data_type' => 'string'
                )
            )
        ),
    ),
),
...