working on text search autocomplete
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 4 Oct 2018 18:37:37 +0000 (14:37 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 4 Oct 2018 18:37:37 +0000 (14:37 -0400)
models/admin/dashboard/contacts.php [new file with mode: 0644]
setup/adminHooks.php

diff --git a/models/admin/dashboard/contacts.php b/models/admin/dashboard/contacts.php
new file mode 100644 (file)
index 0000000..e69de29
index 7c43eed..b274698 100644 (file)
@@ -126,5 +126,109 @@ add_filter( 'glm_contact_is_moderated', function( $user ) {
         return false;
     }
 } );
+add_filter(
+    GLM_MEMBERS_CONTACTS_PLUGIN_SLUG .'-dashboard-widget',
+    function ( $member = null ) {
+        require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php';
+        $Contacts = new GlmDataContacts($this->wpdb, $this->config);
+
+        // Set default values for using getList() later, where the custom set of fields below will be used.
+        $where = '';
+        $order = '';
+        $fieldVals = true;
+        $idField = 'id';
+        $start = false;
+        $limit = false;
+    
+        // Save the current fields array and make a copy. Will be restored before the return.
+        $fSave = $Events->fields;
+    
+        // Remove what we don't want from the copy and get the list
+        $Events->fields = array(
+            'id'            => $fSave['id'],
+            'name'          => $fSave['name'],
+            'name_slug'     => $fSave['name_slug'],
+            'ref_type'      => $fSave['ref_type'],
+            'ref_dest'      => $fSave['ref_dest'],
+            'ref_dest_id'   => $fSave['ref_dest_id'],
+            'status'        => $fSave['status'],
+        );
+    
+        $contactsIndexPage    = GLM_MEMBERS_CONTACTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-contacts-index&glm_action=edit';
+        $contactsTable        = GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts";
+        $contactsEditPage     = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'contacts-index&glm_action=list&option=edit';
+        $contactsListPage     = GLM_MEMBERS_CONTACTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-contacts-list';
+        $contactsRefLink      = GLM_MEMBERS_CONTACTS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member&glm_action=index';
+        $content            = [
+            'title'         => 'Contacts',
+            'components'    => [
+                [
+                    'id'            => 'quickLinks',
+                    'order'         => -1,
+                    'template'      => 'quickLinks',
+                    'quickLinks'    => [
+                        'dashboard' => [
+                            'content'   => 'Dashboard',
+                            'url'       => $contactsIndexPage . "&option=dashboard",
+                        ],
+                        'search' => [
+                            'content'   => 'Advanced Search',
+                            'url'       => $contactsIndexPage . "&option=search",
+                        ],
+                        'settings' => [
+                            'content'   => 'Settings',
+                            'url'       => '#set',
+                        ]
+                    ],
+                ],
+                [
+                    'id' => 'topButtons',
+                    'order'     => 0,
+                    'template'  => 'buttons',
+                    'buttons'   => [
+                        'add-event' => [
+                            'content'       => 'Add Contact',
+                            'url'           => $contactsIndexPage . "&option=create",
+                            'classes'       => '',
+                            'styles'        => '',
+                            'data'          => ''
+                        ],
+                        'export-button' => [
+                            'content'       => 'Export',
+                            'url'           => '#',
+                            'classes'       => 'btn-small widget-export-btn waves-effect waves-light btn modal-trigger',
+                            'styles'        => '',
+                            'data'          => 'contacts'
+                        ],
+                    ],
+                ],
+                [
+                    'id'        => 'entityAmount',
+                    'title'     => 'Number of Contacts',
+                    'order'     => 1,
+                    'template'  => 'entityAmount',
+                    'url'       => $contactsIndexPage . "&option=search",
+                    'result'    => $Contacts->getStats()
+                ],
+                [
+                    'id'        => 'textSearch', 
+                    'order'     => 2,
+                    'template'  => 'textSearch',
+                    'entityID'  => 'event',
+                    'table'     => $contactsTable,
+                    'fields'    => "concat(fname, ' ', lname) as name,id,image,ref_dest",
+                    'resultUrl' => $contactsEditPage.'&contact=',
+                    'where'     => 'fname OR lname'
+                ],
+            ]
+        ];
+
+        // Restore the fields list
+        $Events->fields = $fSave;
 
+        return $content;
+    },
+    13,
+    1
+);
 ?>