Skip to content
This repository has been archived by the owner. It is now read-only.

Update to UC People #13

Merged
merged 1 commit into from Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions acf-export.php
Expand Up @@ -92,16 +92,20 @@ if(function_exists("register_field_group"))
'middle_name' => 'Middle Name',
'last_name' => 'Last Name',
'title' => 'Title',
'department' => 'Department',
'about' => 'About',
'file' => 'Link to File',
//'filelabel' => 'File Label',
'email' => 'Email',
'phone' => 'Phone',
'phone_(alternate)' => 'Phone (Alternate)',
'fax' => 'Fax',
'mailing_address' => 'Mailing Address',
'office_location' => 'Office Location',
'campus' => 'Campus',
'office_hours' => 'Office Hours',
'courses' => 'Courses',
'url' => 'URL',
),
'default_value' => array('photo','first_name','last_name','email'),
'layout' => 'vertical',
Expand Down Expand Up @@ -192,6 +196,18 @@ if(function_exists("register_field_group"))
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_department',
'label' => 'Department',
'name' => 'department',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_about',
'label' => 'About',
Expand All @@ -209,6 +225,16 @@ if(function_exists("register_field_group"))
'save_format' => 'object',
'library' => 'all',
),
array (
'key' => 'field_filelabel',
'label' => 'File Label',
'name' => 'filelabel',
'type' => 'text',
'default_value' => 'File',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
array (
'key' => 'field_email',
'label' => 'Email',
Expand Down Expand Up @@ -279,6 +305,18 @@ if(function_exists("register_field_group"))
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_campus',
'label' => 'Campus',
'name' => 'campus',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_office_hours',
'label' => 'Office Hours',
Expand Down
24 changes: 21 additions & 3 deletions uc-people-widget.php
@@ -1,7 +1,7 @@
<?php

Class UC_People_Widget extends WP_Widget {
private $fields = array('title','about','file','email','phone','phone_(alternate)','fax','mailing_address','office_location','office_hours','courses');
private $fields = array('title','department','about','file','email','phone','phone_(alternate)','fax','mailing_address','office_location','campus','office_hours','courses','url');

public function __construct(){
parent::__construct( 'uc_people_widget', 'UC People', array( 'classname' => __CLASS__, 'description' => 'A widget to display People' ) );
Expand Down Expand Up @@ -52,7 +52,7 @@ Class UC_People_Widget extends WP_Widget {
usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') );

foreach( $people as $id ){
$out .= '<div class="col-sm-6 personcount-'.$person_count.'" id="person-'.$id.'">';
$out .= '<div class="col-sm-3 personcount-'.$person_count.'" id="person-'.$id.'">';
$out .= '<div class="person">';

$out .= '<a href="'.get_the_permalink( $id ).'" class="person-permalink">';
Expand Down Expand Up @@ -87,8 +87,17 @@ Class UC_People_Widget extends WP_Widget {
$out .= ( !empty($t) ? "<em>{$t}</em><br>": "" );
}
$out .= '</p>';
} else if( $f == 'department' && in_array( 'department', $information_to_display ) ){
$out .= '<p class="person-department">';
$departmentPieces = explode(";", get_field('department', $id ));
foreach( $departmentPieces as $d ){
$out .= ( !empty($d) ? "<em>{$d}</em><br>": "" );
}
$out .= '</p>';
} else if( $f == 'mailing_address' && in_array( 'mailing_address', $information_to_display ) ){
$out .= '<p class="person-'.$f.'">'.str_replace(';','<br>',get_field($f, $id )).'</p>';
} elseif( $f == 'url' && in_array( 'url', $information_to_display ) ){
$out .= '<p class="person-url"><a href="'.get_field('url', $id ).'">'.get_field('url', $id ).'</a>'.'</p>';
} else {
if ( in_array($f, $information_to_display) ) {
$out .= '<p class="person-'.$f.'">'.get_field($f, $id ).'</p>';
Expand Down Expand Up @@ -178,9 +187,18 @@ Class UC_People_Widget extends WP_Widget {
$out .= ( !empty($t) ? "<strong>{$t}</strong><br>": "" );
}
$out .= '</td>';
} else if( $f == 'department' && in_array('department', $information_to_display) ){
$out .= '<td class="person-department">';
$departmentPieces = explode(";", get_field('department', $id ));
foreach( $departmentPieces as $d ){
$out .= ( !empty($d) ? "<strong>{$d}</strong><br>": "" );
}
$out .= '</td>';
} else if( $f == 'mailing_address' && in_array('mailing_address', $information_to_display) ){
$out .= '<td class="person-'.$f.'">'.str_replace(';','<br>',get_field($f, $id )).'</td>';
} else {
} elseif( $f == 'url' && in_array( 'url', $information_to_display ) ){
$out .= '<td class="person-url"><a href="'.get_field('url', $id ).'">'.get_field('url', $id ).'</a>'.'</td>';
} else {
$out .= $this->createTextCell($f, $information_to_display, $id );
}
}
Expand Down
22 changes: 12 additions & 10 deletions uc-people.php
Expand Up @@ -197,19 +197,21 @@ function importFile( $filename ){
'courses' => 'Courses',
'about' => 'About',
'url' => 'Website',
'author' => 'Author',
);

foreach( $data as $k => $v ){
$user = username_exists( $v['NetID'] );
$postAuthorFlag = false;
if( $user != false && is_user_member_of_blog($user, get_current_blog_id() ) ){
$postAuthorFlag = true;
$role = $v['Role'];
if( $role == 'profile_user' ){
$userObject = new WP_User( $user );
//$postAuthorFlag = false;
if( $user != false && is_user_member_of_blog($v['Author'], get_current_blog_id() ) ){
//$postAuthorFlag = true;
//$role = $v['Role'];
//if( $role == 'profile_user' ){
$userObject = new WP_User( $v['Author'] );
$userObject->remove_role('subscriber');
$userObject->remove_role('profile_user');
$userObject->add_role('contributor');
}
$userObject->add_role('contributornomedia');
//}
}
$title = $v['First Name'].' '.$v['Last Name'];
$args = array(
Expand All @@ -218,13 +220,13 @@ function importFile( $filename ){
'post_status' => 'publish',
'post_type' => 'person',
'menu_order' => ( !empty($v['Order']) ? $v['Order'] : 0 ),
'post_author' => ( $postAuthorFlag == true ? $user: get_current_user_id() ),
'post_author' => ( !empty($v['Author']) ? $v['Author']: get_current_user_id() ),
);
$id = wp_insert_post( $args, true );
wp_set_object_terms( $id, explode(' ', $v['Tags']), 'tag' );
set_post_thumbnail( $id, intval($v['Profile Image']) );
foreach ($fields as $l => $w) {
if( $l == 'netid' || $l == 'role' ){
if( $l == 'netid' || $l == 'role' || $l == 'author' ){
continue;
}
update_field($l, $v[$w], $id);
Expand Down