Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add URL field to Person and sort groups by order
* Allow users to add a URL that can also be imported via the UC People
Importer
* Sort groups by order
  • Loading branch information
szk11001 committed Nov 30, 2015
1 parent 4e98304 commit d0b11a6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 18 deletions.
16 changes: 16 additions & 0 deletions acf-export.php
Expand Up @@ -306,6 +306,22 @@ if(function_exists("register_field_group"))
'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 (
Expand Down
54 changes: 36 additions & 18 deletions uc-people-widget.php
Expand Up @@ -7,6 +7,40 @@ Class UC_People_Widget extends WP_Widget {
parent::__construct( 'uc_people_widget', 'UC People', array( 'classname' => __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 ); // If groups have the same order, group them by name alphabetically
}
return $r;
}

private function createTextCell( $field, $information_to_display, $id ){
$cell = '';
if (in_array($field, $information_to_display)) {
$cell .= '<td class="person-'.$field.'">'.get_field($field, $id ).'</td>';
}
return $cell;
}

private function get_people_grid( $args, $information_to_display ){
$the_query = new WP_Query( $args );
$out = '';
Expand Down Expand Up @@ -71,23 +105,6 @@ Class UC_People_Widget extends WP_Widget {
return $out;
}

private static function sort_by_last_then_first($a,$b) {
setlocale(LC_CTYPE, 'en_US.UTF8');
$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 function createTextCell( $field, $information_to_display, $id ){
$cell = '';
if (in_array($field, $information_to_display)) {
$cell .= '<td class="person-'.$field.'">'.get_field($field, $id ).'</td>';
}
return $cell;
}

private function get_people_table( $args, $information_to_display ){
$the_query = new WP_Query( $args );

Expand Down Expand Up @@ -228,7 +245,8 @@ Class UC_People_Widget extends WP_Widget {
}

// sort the groups in use alphabetically
sort($groups_in_use);
//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){
Expand Down
46 changes: 46 additions & 0 deletions uc-people.php
Expand Up @@ -79,6 +79,51 @@ function create_custom_custom_post_type(){
}
add_action( 'init', 'create_custom_custom_post_type', 0 );

// Add Order field to Add New Group Page
function uc_people_new_group_order_field(){
?>
<div class="form-field">
<label for="term_meta[group_order]">Order</label>
<input name="term_meta[group_order]" id="term_meta[group_order]" type="number" value="0">
<p class="description">Enter a value for this field or leave it blank</p>
</div>
<?php
}
add_action( 'group_add_form_fields', 'uc_people_new_group_order_field', 10, 2 );

// Add Order field to Edit Group page
function uc_people_edit_group_order_field( $term ){
$term_meta = get_option( "taxonomy_{$term->term_id}" );
$order = $term_meta['group_order'];
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[group_order]">Order</label></th>
<td>
<input type="number" name="term_meta[group_order]" id="term_meta[group_order]" value="<?php echo esc_attr( $order ) ? esc_attr( $order ) : 0; ?>">
<p class="description">Enter a value for this field or leave it blank</p>
</td>
</tr>
<?php
}
add_action( 'group_edit_form_fields', 'uc_people_edit_group_order_field', 10, 2 );

// Save Order field when editing or creating a new Group
function uc_people_save_group_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$term_meta = get_option( "taxonomy_{$term_id}" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_option( "taxonomy_{$term_id}", $term_meta );
}
}
add_action( 'edited_group', 'uc_people_save_group_custom_meta', 10, 2 );
add_action( 'create_group', 'uc_people_save_group_custom_meta', 10, 2 );

add_filter('title_save_pre', 'save_title');
function save_title($my_post_title) {
if ($_POST['post_type'] == 'person') :
Expand Down Expand Up @@ -148,6 +193,7 @@ function importFile( $filename ){
'office_hours' => 'Office Hours',
'courses' => 'Courses',
'about' => 'About',
'url' => 'Website',
);

foreach( $data as $k => $v ){
Expand Down

0 comments on commit d0b11a6

Please sign in to comment.