Connect the child contacts with the parent contacts
authorLaury GvR <laury@gaslightmedia.com>
Fri, 29 Sep 2017 20:11:08 +0000 (16:11 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 29 Sep 2017 20:11:08 +0000 (16:11 -0400)
Added new code on the contact list, and a filter in functions.php,
which work together to look at all contacts which are a primary
contact, and by those contacts list all the contacts associated
with the same member which aren't primary contacts (the 'child'
contacts). Also added most of the fields that were not already
showing up for member contacts, on their list.

functions.php
glm-member-db-contacts/views/front/contacts/list.html [new file with mode: 0644]

index 0e9e88b..b944ef6 100644 (file)
@@ -704,4 +704,27 @@ function template_chooser($template)
 }
 add_filter('template_include', 'template_chooser');
 
+add_filter('get_contacts_with_subs', function( $contacts ) {
+    foreach ($contacts as $contact) {
+        if ($contact["primary_contact"]["value"] == "1") {
+            $filtered_contacts[$contact["ref_dest"]] = $contact;
+        }    
+    }
+    foreach ($contacts as $contact) {
+        $member_id = $contact["ref_dest"];
+        if ($contact["primary_contact"]["value"] == "0" && !empty($filtered_contacts)) {
+            foreach ($filtered_contacts as $filtered_contact) { // <-- I especially don't like this one
+                if ($member_id == $filtered_contact["ref_dest"]) {
+                    $filtered_contacts[$member_id]["subs"][] = $contact;
+                }
+            }
+        }
+    }
+    if (!empty($filtered_contacts)) {
+        return $filtered_contacts;
+    } else {
+        return false;
+    }
+});
+
 ?>
diff --git a/glm-member-db-contacts/views/front/contacts/list.html b/glm-member-db-contacts/views/front/contacts/list.html
new file mode 100644 (file)
index 0000000..ccc5394
--- /dev/null
@@ -0,0 +1,161 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+    <head>
+        <title>Contacts List</title>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    </head>
+    <body class="glm-contact-front">
+{include file='front/contacts/header.html'}
+
+    <form action="{$thisUrl}" method="post" id="searchForm">
+        <input type="hidden" name="prevStart" value="{$prevStart}">
+        <input type="hidden" name="nextStart" value="{$nextStart}">
+        <input type="hidden" name="limit" value="{$limit}">
+
+        <div>
+            <div class="row glmContactsSearchWrapper">
+                <div id="glmContactsSearchContainer" class="small-12 large-5">
+                    <b>Text Search: </b><input  id="glmContactsSearch" name="filterText" type="text" id="autoTest" value="{$filterText}">
+                </div>
+                {if $haveCounties}
+                <div id="glmContactsCountySearchContainer" class="small-12 large-5">
+                    <b>County Search: </b>
+                    <select  id="glmContactsCountySearch" name="countySearch" type="text" value="{$countySearch}">
+                        <option value=""></option>
+                        {foreach $countyList as $county}
+                            <option value="{$county}">{$county} County</option>
+                        {/foreach}
+                    </select>
+                </div>
+                {/if}
+                <div class="small-12 large-2" id="glmContactsSearchSubmit">
+                    <input type="submit" value="Submit" class="glm-button button">
+                </div>
+            </div>
+        </div>
+
+        <br clear="all">
+
+        <p><b>Total found:</b> {$numbContacts}&nbsp;&nbsp;</p>
+
+
+        {if $settings.list_show_search_alpha}
+            <div class="glm-alpha-links">
+                <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&alpha=" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
+          {foreach $alphaList as $a}
+                <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&alpha={$a.alpha}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
+          {/foreach}
+            </div>
+        {/if}
+
+
+        {if $paging}
+
+            <br>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+            <br>
+            showing {$start} through {$lastDisplayed} of {$filteredContactsFound}
+        {/if}
+
+        
+        {$contacts_with_subs = apply_filters("get_contacts_with_subs", $contacts)}
+        
+
+        {if $haveContacts}
+            
+            {foreach $contacts as $contact}
+                
+                {if $contact.active.value == 1}
+
+            <div class="glm-member-list-container glm-member-container small-12 columns">
+                <div class="glm-member-list-data small-12 columns">
+                    {if $contact.image}
+                    <div class="glm-member-list-active-info small-9 columns">
+                    {else}
+                    <div class="glm-member-list-active-info small-12 columns">
+                    {/if}
+
+                        <h4 class="glm-member-title">
+                            {$contact.lname}, {$contact.fname}
+                        </h4>
+                        <div class="row glm-contact-info">
+                            <div class="small-12 medium-6 columns">
+                                {if $contact.primary_contact.value == true} 
+                                    
+                                    {if $contact.title}<div class="glm-contact-info-title">{$contact.title}</div>{/if}
+                                    {if $contacts_with_subs !== false}
+                                        {foreach $contacts_with_subs as $contact_with_subs}
+
+                                            {foreach $contact_with_subs["subs"] as $contact_sub}
+                                                <div><span>{$contact_sub["title"]}{$contact_sub["fname"]}</span></div>
+                                            {/foreach}
+                                            
+                                        {/foreach}
+                                    {/if}
+                                {/if}
+                                {if $contact.ref_type.name}
+                                <div class="glm-contact-info-member">
+                                    {if $contact.ref_dest_name}
+                                        {$contact.ref_dest_name}
+                                    {/if}
+                                </div>
+                                {/if}
+                                {if $contact.addr1}<div class="glm-contact-info-address1">{$contact.addr1}</div>{/if}
+                                {if $contact.addr2}<div class="glm-contact-info-address2">{$contact.addr2}</div>{/if}
+                                {if $contact.zip or $contact.city.name or $contact.state.name}
+                                <div>
+                                    {if $contact.city.name}<span class="glm-contact-info-city">{$contact.city.name},</span>{/if}
+                                    {if $contact.state.name}<span class="glm-contact-info-state">{$contact.state.name}</span>{/if}
+                                    {if $contact.zip}<span class="glm-contact-info-zip">{$contact.zip}</span>{/if}
+                                </div>{/if}
+                                {if $contact.county}<div class="glm-contact-info-county">{$contact.county} County</div>{/if}
+                                
+                            </div>
+                            <div class="small-12 medium-6 columns">
+                                {if $contact.office_phone}<div class="glm-contact-info-work-phone"><span class="field-title">Work: </span>{$contact.office_phone}</div>{/if}
+                                {if $contact.home_phone}<div class="glm-contact-info-home-phone"><span class="field-title">Home: </span>{$contact.home_phone}</div>{/if}
+                                {if $contact.mobile_phone}<div class="glm-contact-info-mobile-phone"><span class="field-title">Mobile: </span>{$contact.mobile_phone}</div>{/if}
+                                {if $contact.alt_phone}<div class="glm-contact-info-alt-phone"><span class="field-title">Alternate: </span>{$contact.alt_phone}</div>{/if}
+                                {if $contact.fax}<div class="glm-contact-info-fax"><span class="field-title">Fax: </span>{$contact.fax}</div>{/if}
+                                {if $contact.email}<div class="glm-contact-info-email">Email: <a href="mailto:{$contact.email}" target="_top">{$contact.email}</a></div>{/if}
+                                {if $contact.alt_email}<div class="glm-contact-info-alt-email"><span class="field-title">Alt Email: </span><a href="mailto:{$contact.alt_email}" target="_top">{$contact.alt_email}</a></div>{/if}
+                                {if $contact.url}<div class="glm-contact-info-url"><span class="field-title">Website: </span></span><a href="{$contact.url}" target="_top">{$contact.url}</a></div>{/if}
+                            </div>                 
+                            <div class="small-12 columns">
+                                {if $contact.org}<div class="glm-contact-info-org"><span class="field-title">Organization: </span>{$contact.org}</div>{/if}
+                                {if $contact.descr}<div class="glm-contact-info-descr"><span class="field-title">Position & Responsibilities: </span>{$contact.descr}</div>{/if}
+                            </div>
+                        </div>
+                    </div>
+
+                    <div class="glm-contact-list-image small-3 columns">
+                        <img src="{$glmPluginMediaUrl}/images/{$settings.list_logo_size}/{$contact.image}">
+                    </div>
+                </div>
+            </div>
+                {/if}
+            {/foreach}
+        {else}
+                <tr class="alternate"><td colspan="7">(no contacts listed)</td></tr>
+        {/if}
+        {if $paging}
+
+            <br>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+            <br>
+            showing {$start} through {$lastDisplayed} of {$filteredContactsFound}
+        {/if}
+    </form>
+
+{include file='front/footer.html'}
+
+    </body>
+</html>
\ No newline at end of file