diff --git a/acf-export.php b/acf-export.php index 9806066..f4b6433 100644 --- a/acf-export.php +++ b/acf-export.php @@ -1,346 +1,343 @@ - 'acf_people-page', - 'title' => 'People Page', - 'fields' => array ( - array ( - 'key' => 'field_55c37831dccb9', - 'label' => 'Layout', - 'name' => 'layout', - 'type' => 'select', - 'required' => 1, - 'choices' => array ( - 'grid' => 'Grid', - 'table' => 'Table', - '' => '', - ), - 'default_value' => 'grid', - 'allow_null' => 0, - 'multiple' => 0, - ), - array ( - 'key' => 'field_55c3a7424451c', - 'label' => 'Specific People', - 'name' => 'specific_people', - 'type' => 'relationship', - 'instructions' => 'Choose specific people to display. Leave right side blank to display all People.', - 'return_format' => 'id', - 'post_type' => array ( - 0 => 'person', - ), - 'taxonomy' => array ( - 0 => 'all', - ), - 'filters' => array ( - 0 => 'search', - ), - 'result_elements' => array ( - 0 => 'featured_image', - 1 => 'post_type', - 2 => 'post_title', - ), - 'max' => '', - ), - array ( - 'key' => 'field_55c3a8d1071bf', - 'label' => 'Specific Groups', - 'name' => 'specific_groups', - 'type' => 'taxonomy', - 'instructions' => 'Selecting one or more groups will only display people that belong to those groups. ', - 'taxonomy' => 'group', - 'field_type' => 'checkbox', - 'allow_null' => 0, - 'load_save_terms' => 0, - 'return_format' => 'id', - 'multiple' => 0, - ), - array ( - 'key' => 'field_55c3a91e071c0', - 'label' => 'Specific Tags', - 'name' => 'specific_tags', - 'type' => 'taxonomy', - 'instructions' => 'Selecting one or more tags will only display people with those tags. ', - 'taxonomy' => 'persontag', - 'field_type' => 'checkbox', - 'allow_null' => 0, - 'load_save_terms' => 0, - 'return_format' => 'id', - 'multiple' => 0, - ), - array ( - 'key' => 'field_55c3ab294705d', - 'label' => 'Break into Groups', - 'name' => 'break_into_groups', - 'type' => 'true_false', - 'instructions' => 'When selected, people will be displayed in multiple lists, grids, or tables based on their group. ', - 'message' => '', - 'default_value' => 0, - ), - array ( - 'key' => 'field_55c3abb4e4e6b', - 'label' => 'Information to Display', - 'name' => 'information_to_display', - 'type' => 'checkbox', - 'instructions' => 'All checked fields will display in the output. ', - 'choices' => array ( - 'photo' => 'Photo', - 'first_name' => 'First Name', - 'middle_name' => 'Middle Name', - 'last_name' => 'Last Name', - 'title' => 'Title', - 'about' => 'About', - 'file' => 'Link to File', - 'email' => 'Email', - 'phone' => 'Phone', - 'phone_(alternate)' => 'Phone (Alternate)', - 'fax' => 'Fax', - 'mailing_address' => 'Mailing Address', - 'office_location' => 'Office Location', - 'office_hours' => 'Office Hours', - 'courses' => 'Courses', - ), - 'default_value' => 'photo - first - last - email', - 'layout' => 'vertical', - ), - ), - 'location' => array ( - array ( - array ( - 'param' => 'page_template', - 'operator' => '==', - 'value' => 'user-people.php', - 'order_no' => 0, - 'group_no' => 0, - ), - ), - array ( - array ( - 'param' => 'widget', - 'operator' => '==', - 'value' => 'uc_people_widget', - ), - ), - ), - 'options' => array ( - 'position' => 'normal', - 'layout' => 'default', - 'hide_on_screen' => array ( - ), - ), - 'menu_order' => 0, - )); -} - -//adds boxes to the "People" pages. -if(function_exists("register_field_group")) -{ - register_field_group(array ( - 'id' => 'acf_person', - 'title' => 'Person', - 'fields' => array ( - array ( - 'key' => 'field_first_name', - 'label' => 'First Name', - 'name' => 'first_name', - 'type' => 'text', - 'required' => 1, - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_middle_name', - 'label' => 'Middle Name', - 'name' => 'middle_name', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_last_name', - 'label' => 'Last Name', - 'name' => 'last_name', - 'type' => 'text', - 'required' => 1, - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_title', - 'label' => 'Title', - 'name' => 'title', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_about', - 'label' => 'About', - 'name' => 'about', - 'type' => 'wysiwyg', - 'default_value' => '', - 'toolbar' => 'full', - 'media_upload' => 'yes', - ), - array ( - 'key' => 'field_file', - 'label' => 'File', - 'name' => 'file', - 'type' => 'file', - 'save_format' => 'object', - 'library' => 'all', - ), - array ( - 'key' => 'field_email', - 'label' => 'Email', - 'name' => 'email', - 'type' => 'email', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - ), - array ( - 'key' => 'field_phone', - 'label' => 'Phone', - 'name' => 'phone', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_phone_(alternate)', - 'label' => 'Phone (alternate)', - 'name' => 'phone_(alternate)', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_fax', - 'label' => 'Fax', - 'name' => 'fax', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_mailing_address', - 'label' => 'Mailing Address', - 'name' => 'mailing_address', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_office_location', - 'label' => 'Office Location', - 'name' => 'office_location', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_office_hours', - 'label' => 'Office Hours', - 'name' => 'office_hours', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_courses', - 'label' => 'Courses', - 'name' => 'courses', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_url', - 'label' => 'URL', - 'name' => 'url', - 'type' => 'url', - 'instructions' => '', - 'required' => 0, - 'conditional_logic' => 0, - 'wrapper' => array ( - 'width' => '', - 'class' => '', - 'id' => '', - ), - 'default_value' => '', - 'placeholder' => '', - ), - ), - 'location' => array ( - array ( - array ( - 'param' => 'post_type', - 'operator' => '==', - 'value' => 'person', - 'order_no' => 0, - 'group_no' => 0, - ), - ), - ), - 'options' => array ( - 'position' => 'normal', - 'layout' => 'no_box', - 'hide_on_screen' => array ( - ), - ), - 'menu_order' => 0, - )); -} + 'acf_people-page', + 'title' => 'People Page', + 'fields' => array ( + array ( + 'key' => 'field_55c37831dccb9', + 'label' => 'Layout', + 'name' => 'layout', + 'type' => 'select', + 'required' => 1, + 'choices' => array ( + 'grid' => 'Grid', + 'table' => 'Table', + '' => '', + ), + 'default_value' => 'grid', + 'allow_null' => 0, + 'multiple' => 0, + ), + array ( + 'key' => 'field_55c3a7424451c', + 'label' => 'Specific People', + 'name' => 'specific_people', + 'type' => 'relationship', + 'instructions' => 'Choose specific people to display. Leave right side blank to display all People.', + 'return_format' => 'id', + 'post_type' => array ( + 0 => 'person', + ), + 'taxonomy' => array ( + 0 => 'all', + ), + 'filters' => array ( + 0 => 'search', + ), + 'result_elements' => array ( + 0 => 'featured_image', + 1 => 'post_type', + 2 => 'post_title', + ), + 'max' => '', + ), + array ( + 'key' => 'field_55c3a8d1071bf', + 'label' => 'Specific Groups', + 'name' => 'specific_groups', + 'type' => 'taxonomy', + 'instructions' => 'Selecting one or more groups will only display people that belong to those groups. ', + 'taxonomy' => 'group', + 'field_type' => 'checkbox', + 'allow_null' => 0, + 'load_save_terms' => 0, + 'return_format' => 'id', + 'multiple' => 0, + ), + array ( + 'key' => 'field_55c3a91e071c0', + 'label' => 'Specific Tags', + 'name' => 'specific_tags', + 'type' => 'taxonomy', + 'instructions' => 'Selecting one or more tags will only display people with those tags. ', + 'taxonomy' => 'persontag', + 'field_type' => 'checkbox', + 'allow_null' => 0, + 'load_save_terms' => 0, + 'return_format' => 'id', + 'multiple' => 0, + ), + array ( + 'key' => 'field_55c3ab294705d', + 'label' => 'Break into Groups', + 'name' => 'break_into_groups', + 'type' => 'true_false', + 'instructions' => 'When selected, people will be displayed in multiple lists, grids, or tables based on their group. ', + 'message' => '', + 'default_value' => 0, + ), + array ( + 'key' => 'field_55c3abb4e4e6b', + 'label' => 'Information to Display', + 'name' => 'information_to_display', + 'type' => 'checkbox', + 'instructions' => 'All checked fields will display in the output. ', + 'choices' => array ( + 'photo' => 'Photo', + 'first_name' => 'First Name', + 'middle_name' => 'Middle Name', + 'last_name' => 'Last Name', + 'title' => 'Title', + 'about' => 'About', + 'file' => 'Link to File', + 'email' => 'Email', + 'phone' => 'Phone', + 'phone_(alternate)' => 'Phone (Alternate)', + 'fax' => 'Fax', + 'mailing_address' => 'Mailing Address', + 'office_location' => 'Office Location', + 'office_hours' => 'Office Hours', + 'courses' => 'Courses', + ), + 'default_value' => array('photo','first_name','last_name','email'), + 'layout' => 'vertical', + ), + ), + 'location' => array ( + array ( + array ( + 'param' => 'page_template', + 'operator' => '==', + 'value' => 'user-people.php', + 'order_no' => 0, + 'group_no' => 0, + ), + ), + array ( + array ( + 'param' => 'widget', + 'operator' => '==', + 'value' => 'uc_people_widget', + ), + ), + ), + 'options' => array ( + 'position' => 'normal', + 'layout' => 'default', + 'hide_on_screen' => array ( + ), + ), + 'menu_order' => 0, + )); +} + +//adds boxes to the "People" pages. +if(function_exists("register_field_group")) +{ + register_field_group(array ( + 'id' => 'acf_person', + 'title' => 'Person', + 'fields' => array ( + array ( + 'key' => 'field_first_name', + 'label' => 'First Name', + 'name' => 'first_name', + 'type' => 'text', + 'required' => 1, + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_middle_name', + 'label' => 'Middle Name', + 'name' => 'middle_name', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_last_name', + 'label' => 'Last Name', + 'name' => 'last_name', + 'type' => 'text', + 'required' => 1, + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_title', + 'label' => 'Title', + 'name' => 'title', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_about', + 'label' => 'About', + 'name' => 'about', + 'type' => 'wysiwyg', + 'default_value' => '', + 'toolbar' => 'full', + 'media_upload' => 'yes', + ), + array ( + 'key' => 'field_file', + 'label' => 'File', + 'name' => 'file', + 'type' => 'file', + 'save_format' => 'object', + 'library' => 'all', + ), + array ( + 'key' => 'field_email', + 'label' => 'Email', + 'name' => 'email', + 'type' => 'email', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + ), + array ( + 'key' => 'field_phone', + 'label' => 'Phone', + 'name' => 'phone', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_phone_(alternate)', + 'label' => 'Phone (alternate)', + 'name' => 'phone_(alternate)', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_fax', + 'label' => 'Fax', + 'name' => 'fax', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_mailing_address', + 'label' => 'Mailing Address', + 'name' => 'mailing_address', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_office_location', + 'label' => 'Office Location', + 'name' => 'office_location', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_office_hours', + 'label' => 'Office Hours', + 'name' => 'office_hours', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_courses', + 'label' => 'Courses', + 'name' => 'courses', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_url', + 'label' => 'URL', + 'name' => 'url', + 'type' => 'url', + 'instructions' => '', + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => array ( + 'width' => '', + 'class' => '', + 'id' => '', + ), + 'default_value' => '', + 'placeholder' => '', + ), + ), + 'location' => array ( + array ( + array ( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'person', + 'order_no' => 0, + 'group_no' => 0, + ), + ), + ), + 'options' => array ( + 'position' => 'normal', + 'layout' => 'no_box', + 'hide_on_screen' => array ( + ), + ), + 'menu_order' => 0, + )); +} ?> \ No newline at end of file diff --git a/uc-people-widget.php b/uc-people-widget.php index 3748fbd..0b038d1 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -1,314 +1,318 @@ - __CLASS__, 'description' => 'A widget to display People' ) ); - } - - private static function sort_by_last_then_first($a,$b) { - setlocale(LC_CTYPE, 'en_US.UTF8'); // Using setlocale and iconv incase a name has an accent or other similar characters in them - $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) ); - if( $r === 0 ){ - $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) ); - } - return $r; - } - - private static function sort_group_by_order( $a, $b ){ - // Getting the order for groups $a and $b - $groupA = get_term_by('slug', $a, 'group')->term_id; - $array_orderGroupA = get_option( "taxonomy_{$groupA}" ); - $orderGroupA = $array_orderGroupA['group_order']; - - $groupB = get_term_by('slug', $b, 'group')->term_id; - $array_orderGroupB = get_option( "taxonomy_{$groupB}" ); - $orderGroupB = $array_orderGroupB['group_order']; - - $r = strnatcasecmp( $orderGroupA, $orderGroupB ); - if( $r === 0 ){ - $r = strnatcasecmp( $a, $b ); - } - return $r; - } - - private function createTextCell( $field, $information_to_display, $id ){ - $cell = ''; - if (in_array($field, $information_to_display)) { - $cell .= ''.get_field($field, $id ).''; - } - return $cell; - } - - private function get_people_grid( $args, $information_to_display ){ - $the_query = new WP_Query( $args ); - $out = ''; - if( $the_query->have_posts() ){ - $out = '
'; - $person_count = 1; - - $people = $the_query->get_posts(); - usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); - - foreach( $people as $id ){ - $out .= '
'; - $out .= '
'; - - $out .= ''; - if (in_array('photo', $information_to_display)) { - $out .= '
'.get_the_post_thumbnail( $id, 'large').'
'; - }; - if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ - $out .= '

'; - if (in_array('first_name', $information_to_display)) { - $out .= get_field('first_name', $id ).' '; - }; - if (in_array('middle_name', $information_to_display)) { - $out .= get_field('middle_name', $id ).' '; - }; - if (in_array('last_name', $information_to_display)) { - $out .= get_field('last_name', $id ); - }; - $out .= '

'; - }; - $out .= '
'; - - foreach( $this->fields as $f ){ - if( $f == 'file' && in_array('file', $information_to_display) ){ - $file = get_field('file', $id ); - $out .= '

'.$file[title].''.'

'; - } elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){ - $out .= '

'.get_field('email', $id ).''.'

'; - } else if( $f == 'title' && in_array( 'title', $information_to_display ) ){ - $out .= '

'; - $titlePieces = explode(";", get_field('title', $id )); - foreach( $titlePieces as $t ){ - $out .= ( !empty($t) ? "{$t}
": "" ); - } - $out .= '

'; - } else { - if ( in_array($f, $information_to_display) ) { - $out .= '

'.get_field($f, $id ).'

'; - }; - } - } - $out .= '
'; // div.person and div.col-sm-3 - - // check to see if we need to close this row... - if ($person_count % 4 == 0){ - // if this is the 4th, 8th, 16th, etc person... - echo '
'; - } - $person_count++; - } - $out .= '
'; // div.row - } else { - - } //end of if posts - - return $out; - } - - private function get_people_table( $args, $information_to_display ){ - $the_query = new WP_Query( $args ); - - $out = ''; - if ( $the_query->have_posts() ) { - $people = $the_query->get_posts(); - usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); - - // how many columns? Based on what they chose to display. - $num_cols = count($information_to_display); - - $out .= ''; - $out.= 'List of People'; - $out .= ''; - - $nameCell = false; - foreach($information_to_display as $value){ - if ($value == 'first_name' || $value == 'middle_name' || $value == 'last_name'){ - if ($nameCell == false){ - $out .= ''; - $nameCell = true; - }; - } elseif ($value == 'photo') { - $out .= ''; - } else { - $arr = get_field_object('field_'.$value); - $label = $arr['label']; - $out .= ''; - } - } - $out .= ''; - $out .= ''; - - foreach( $people as $id ){ - $out .= ''; - if (in_array('photo', $information_to_display)) { - $out .= ''; - } - if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ - $out .= ''; - } - - foreach( $this->fields as $f ){ - if( $f == 'file' && in_array('file', $information_to_display) ){ - $file = get_field('file', $id ); - $out .= ''; - } else if( $f == 'email' && in_array('email', $information_to_display) ){ - $out .= ''; - } else if( $f == 'title' && in_array('title', $information_to_display) ){ - $out .= ''; - } else { - $out .= $this->createTextCell($f, $information_to_display, $id ); - } - } - $out .= ''; - } - $out .= ''; - $out .= '
Name '.$label.'
'.get_the_post_thumbnail($id, array('65', '65')).''; - if (in_array('first_name', $information_to_display)) { - $out .= get_field('first_name', $id ); - $out .= ' '; - }; - if (in_array('middle_name', $information_to_display)) { - $out .= get_field('middle_name', $id ); - $out .= ' '; - }; - if (in_array('last_name', $information_to_display)) { - $out .= get_field('last_name', $id ); - }; - $out .= ''.$file[title].''.get_field('email', $id ).''; - $titlePieces = explode(";", get_field('title', $id )); - foreach( $titlePieces as $t ){ - $out .= ( !empty($t) ? "{$t}
": "" ); - } - $out .= '
'; - } else { - // no posts found - } - return $out; - } - - public function widget( $args, $instance ){ - $settings = array( 'layout' => '', 'specific_people' => '', 'specific_groups' => '', 'specific_tags' => '', 'break_into_groups' => '', 'information_to_display' => ''); - foreach( $settings as $k => $v ){ - $settings[$k] = get_field( $k, 'widget_' . $args['widget_id'] ); - } - - $wpQueryArgs = array( - 'posts_per_page' => -1, - 'post_type' => 'person', - //'orderby' => 'menu_order title', - //'order' => 'ASC', - //'order' => 'post__in', - 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ), - 'fields' => 'ids' - ); - - if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){ - $tax_query = array(); - $isGroupSet = false; - $isTagSet = false; - - if ( $settings['specific_groups'] != false ) { - $isGroupSet = true; - $taxGroupArray = array( - 'taxonomy' => 'group', - 'field' => 'term_id', - 'terms' => $settings['specific_groups'] - ); - $tax_query[] = $taxGroupArray; - } - if ( $settings['specific_tags'] != false ) { - $isTagSet = true; - $taxTagArray = array( - 'taxonomy' => 'persontag', - 'field' => 'term_id', - 'terms' => $settings['specific_tags'] - ); - $tax_query[] = $taxTagArray; - } - $wpQueryArgs['tax_query'] = $tax_query; - } - - if( $settings['break_into_groups'] != false ){ - // get all the people - $the_query = new WP_Query( $wpQueryArgs ); - - // focusing on just the people, not the rest of the query. - $people = $the_query->posts; - - // look at each person, and see each group used, use that to create a list of terms. - $groups_in_use = array(); - - foreach($people as $value){ - //$id = $value->ID; - $id = $value; - $terms = get_the_terms($id, 'group'); - if (is_array($terms)){ - foreach($terms as $key => $v){ - //duplicates will overwrite themselves... - $slug = $v->slug; - $groups_in_use[$slug]= $slug; - } - }; - } - - // sort the groups in use alphabetically - //sort($groups_in_use); - usort($groups_in_use, array('UC_People_Widget', 'sort_group_by_order') ); - - // for each item in the list of terms, do a new query, but this time we're going to limit it to ONLY items from that one group. - foreach($groups_in_use as $value){ - - // this sets up the query we'll need, and will overwrite any group queries from the original settings. - $tax_query = array(); - $group_query = array( - 'taxonomy' => 'group', - 'field' => 'slug', - 'terms' => $value - ); - array_push($tax_query, $group_query); - /*if( $isGroupSet != false ){ - array_push($tax_query, $taxGroupArray); - }*/ - if( $isTagSet != false ){ - array_push($tax_query, $taxTagArray); - } - $wpQueryArgs['tax_query'] = $tax_query; - - // with $arg updated, let's do a new query. - echo '

'.get_term_by('slug', $value, 'group')->name.'

'; - - if( $settings['layout'] == 'grid' ){ - echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); - } else if( $settings['layout'] == 'table' ){ - echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); - } - } - } else { - if( $settings['layout'] == 'grid' ){ - echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); - } else if( $settings['layout'] == 'table' ){ - echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); - } - } - } - - public function form( $instance ){ - //Form is handled by ACF, code can be found in wp-content/plugins/uc-people/acf-export.php - } - - public function update( $new_instance, $old_instance ){ - //Update is handled by ACF - } -} - -function register_uc_people_widget(){ - register_widget( 'UC_People_Widget' ); -} -add_action( 'widgets_init', 'register_uc_people_widget' ); - + __CLASS__, 'description' => 'A widget to display People' ) ); + } + + private static function sort_by_last_then_first($a,$b) { + setlocale(LC_CTYPE, 'en_US.UTF8'); // Using setlocale and iconv incase a name has an accent or other similar characters in them + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) ); + if( $r === 0 ){ + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) ); + } + return $r; + } + + private static function sort_group_by_order( $a, $b ){ + // Getting the order for groups $a and $b + $groupA = get_term_by('slug', $a, 'group')->term_id; + $array_orderGroupA = get_option( "taxonomy_{$groupA}" ); + $orderGroupA = $array_orderGroupA['group_order']; + + $groupB = get_term_by('slug', $b, 'group')->term_id; + $array_orderGroupB = get_option( "taxonomy_{$groupB}" ); + $orderGroupB = $array_orderGroupB['group_order']; + + $r = strnatcasecmp( $orderGroupA, $orderGroupB ); + if( $r === 0 ){ + $r = strnatcasecmp( $a, $b ); + } + return $r; + } + + private function createTextCell( $field, $information_to_display, $id ){ + $cell = ''; + if (in_array($field, $information_to_display)) { + $cell .= ''.get_field($field, $id ).''; + } + return $cell; + } + + private function get_people_grid( $args, $information_to_display ){ + $the_query = new WP_Query( $args ); + $out = ''; + if( $the_query->have_posts() ){ + $out = '
'; + $person_count = 1; + + $people = $the_query->get_posts(); + usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); + + foreach( $people as $id ){ + $out .= '
'; + $out .= '
'; + + $out .= ''; + if (in_array('photo', $information_to_display)) { + $out .= '
'.get_the_post_thumbnail( $id, 'large').'
'; + }; + if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ + $out .= '

'; + if (in_array('first_name', $information_to_display)) { + $out .= get_field('first_name', $id ).' '; + }; + if (in_array('middle_name', $information_to_display)) { + $out .= get_field('middle_name', $id ).' '; + }; + if (in_array('last_name', $information_to_display)) { + $out .= get_field('last_name', $id ); + }; + $out .= '

'; + }; + $out .= '
'; + + foreach( $this->fields as $f ){ + if( $f == 'file' && in_array('file', $information_to_display) ){ + $file = get_field('file', $id ); + $out .= '

'.$file[title].''.'

'; + } elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){ + $out .= '

'.get_field('email', $id ).''.'

'; + } else if( $f == 'title' && in_array( 'title', $information_to_display ) ){ + $out .= '

'; + $titlePieces = explode(";", get_field('title', $id )); + foreach( $titlePieces as $t ){ + $out .= ( !empty($t) ? "{$t}
": "" ); + } + $out .= '

'; + } else if( $f == 'mailing_address' && in_array( 'mailing_address', $information_to_display ) ){ + $out .= '

'.str_replace(';','
',get_field($f, $id )).'

'; + } else { + if ( in_array($f, $information_to_display) ) { + $out .= '

'.get_field($f, $id ).'

'; + }; + } + } + $out .= '
'; // div.person and div.col-sm-3 + // check to see if we need to close this row... + if ($person_count % 4 == 0){ + // if this is the 4th, 8th, 16th, etc person... + $out .= '
'; + } + $person_count++; + } + $out .= '
'; // div.row + } else { + + } //end of if posts + + return $out; + } + + private function get_people_table( $args, $information_to_display ){ + $the_query = new WP_Query( $args ); + + $out = ''; + if ( $the_query->have_posts() ) { + $people = $the_query->get_posts(); + usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); + + // how many columns? Based on what they chose to display. + $num_cols = count($information_to_display); + + $out .= ''; + $out.= 'List of People'; + $out .= ''; + + $nameCell = false; + foreach($information_to_display as $value){ + if ($value == 'first_name' || $value == 'middle_name' || $value == 'last_name'){ + if ($nameCell == false){ + $out .= ''; + $nameCell = true; + }; + } elseif ($value == 'photo') { + $out .= ''; + } else { + $arr = get_field_object('field_'.$value); + $label = $arr['label']; + $out .= ''; + } + } + $out .= ''; + $out .= ''; + + foreach( $people as $id ){ + $out .= ''; + if (in_array('photo', $information_to_display)) { + $out .= ''; + } + if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ + $out .= ''; + } + + foreach( $this->fields as $f ){ + if( $f == 'file' && in_array('file', $information_to_display) ){ + $file = get_field('file', $id ); + $out .= ''; + } else if( $f == 'email' && in_array('email', $information_to_display) ){ + $out .= ''; + } else if( $f == 'title' && in_array('title', $information_to_display) ){ + $out .= ''; + } else if( $f == 'mailing_address' && in_array('mailing_address', $information_to_display) ){ + $out .= ''; + } else { + $out .= $this->createTextCell($f, $information_to_display, $id ); + } + } + $out .= ''; + } + $out .= ''; + $out .= '
Name '.$label.'
'.get_the_post_thumbnail($id, array('65', '65')).''; + if (in_array('first_name', $information_to_display)) { + $out .= get_field('first_name', $id ); + $out .= ' '; + }; + if (in_array('middle_name', $information_to_display)) { + $out .= get_field('middle_name', $id ); + $out .= ' '; + }; + if (in_array('last_name', $information_to_display)) { + $out .= get_field('last_name', $id ); + }; + $out .= ''.$file[title].''.get_field('email', $id ).''; + $titlePieces = explode(";", get_field('title', $id )); + foreach( $titlePieces as $t ){ + $out .= ( !empty($t) ? "{$t}
": "" ); + } + $out .= '
'.str_replace(';','
',get_field($f, $id )).'
'; + } else { + // no posts found + } + return $out; + } + + public function widget( $args, $instance ){ + $settings = array( 'layout' => '', 'specific_people' => '', 'specific_groups' => '', 'specific_tags' => '', 'break_into_groups' => '', 'information_to_display' => ''); + foreach( $settings as $k => $v ){ + $settings[$k] = get_field( $k, 'widget_' . $args['widget_id'] ); + } + + $wpQueryArgs = array( + 'posts_per_page' => -1, + 'post_type' => 'person', + //'orderby' => 'menu_order title', + //'order' => 'ASC', + //'order' => 'post__in', + 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ), + 'fields' => 'ids' + ); + + if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){ + $tax_query = array(); + $isGroupSet = false; + $isTagSet = false; + + if ( $settings['specific_groups'] != false ) { + $isGroupSet = true; + $taxGroupArray = array( + 'taxonomy' => 'group', + 'field' => 'term_id', + 'terms' => $settings['specific_groups'] + ); + $tax_query[] = $taxGroupArray; + } + if ( $settings['specific_tags'] != false ) { + $isTagSet = true; + $taxTagArray = array( + 'taxonomy' => 'persontag', + 'field' => 'term_id', + 'terms' => $settings['specific_tags'] + ); + $tax_query[] = $taxTagArray; + } + $wpQueryArgs['tax_query'] = $tax_query; + } + echo '
'; + if( $settings['break_into_groups'] != false ){ + // get all the people + $the_query = new WP_Query( $wpQueryArgs ); + + // focusing on just the people, not the rest of the query. + $people = $the_query->posts; + + // look at each person, and see each group used, use that to create a list of terms. + $groups_in_use = array(); + + foreach($people as $value){ + //$id = $value->ID; + $id = $value; + $terms = get_the_terms($id, 'group'); + if (is_array($terms)){ + foreach($terms as $key => $v){ + //duplicates will overwrite themselves... + $slug = $v->slug; + $groups_in_use[$slug]= $slug; + } + }; + } + + // sort the groups in use alphabetically + //sort($groups_in_use); + usort($groups_in_use, array('UC_People_Widget', 'sort_group_by_order') ); + + // for each item in the list of terms, do a new query, but this time we're going to limit it to ONLY items from that one group. + foreach($groups_in_use as $value){ + + // this sets up the query we'll need, and will overwrite any group queries from the original settings. + $tax_query = array(); + $group_query = array( + 'taxonomy' => 'group', + 'field' => 'slug', + 'terms' => $value + ); + array_push($tax_query, $group_query); + /*if( $isGroupSet != false ){ + array_push($tax_query, $taxGroupArray); + }*/ + if( $isTagSet != false ){ + array_push($tax_query, $taxTagArray); + } + $wpQueryArgs['tax_query'] = $tax_query; + + // with $arg updated, let's do a new query. + echo '

'.get_term_by('slug', $value, 'group')->name.'

'; + + if( $settings['layout'] == 'grid' ){ + echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); + } else if( $settings['layout'] == 'table' ){ + echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); + } + } + } else { + if( $settings['layout'] == 'grid' ){ + echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); + } else if( $settings['layout'] == 'table' ){ + echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); + } + } + echo '
'; + } + + public function form( $instance ){ + //Form is handled by ACF, code can be found in wp-content/plugins/uc-people/acf-export.php + } + + public function update( $new_instance, $old_instance ){ + //Update is handled by ACF + } +} + +function register_uc_people_widget(){ + register_widget( 'UC_People_Widget' ); +} +add_action( 'widgets_init', 'register_uc_people_widget' ); + ?> \ No newline at end of file diff --git a/uc-people.php b/uc-people.php index c36ca08..a2b4db3 100644 --- a/uc-people.php +++ b/uc-people.php @@ -2,7 +2,7 @@ /** * Plugin Name: UC People * Description: Displays information about people, a replacement for UUP. - * Version: 1.1 + * Version: 1.2 * Author: Andrew Bacon and Salman Kaleem of UITS Web Dev */ @@ -86,7 +86,7 @@ function uc_people_new_group_order_field(){

Enter a value for this field or leave it blank

- + ">

Enter a value for this field or leave it blank

- +

Please upload a CSV file

'; return; } - + $uploadedFile = wp_handle_upload( $_FILES[$filename], array( 'test_form' => false ) ); if( $uploadedFile && !isset($uploadedFile['error']) ){ @@ -186,6 +186,7 @@ function importFile( $filename ){ 'first_name' => 'First Name', 'last_name' => 'Last Name', 'title' => 'Title', + //'about' => 'Biographical Info', 'email' => 'Email Address', 'phone' => 'Phone 1', 'phone_(alternate)' => 'Phone 2',