Skip to content

Commit

Permalink
Merge pull request #19 from uriweb/release-1.5.0
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
alexandragauss authored Jan 8, 2025
2 parents ba2c87c + 23cf872 commit 5649a26
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

A tool that makes it easy to embed dynamic course data from Kuali.

## What's new in v1.4.0
## What's new in v1.5.0

- Adds multiple queries to call up to 300 courses in a given subject at a time.
- Displays the first version of each course, removing duplicates.

## Example Usage

Expand All @@ -15,7 +15,7 @@ A tool that makes it easy to embed dynamic course data from Kuali.
__Contributors:__ [bjcfuller](https://github.com/bjcfuller), [alexandragauss](https://github.com/alexandragauss)
__Tags:__ plugins, shortcodes
__Requires at least:__ 5.0
__Tested up to:__ 6.0.2
__Stable tag:__ 1.4.0
__Tested up to:__ 6.7.1
__Stable tag:__ 1.5.0
__License:__ GPL-3.0
__Licence URI:__ https://www.gnu.org/licenses/gpl-3.0.html
42 changes: 38 additions & 4 deletions inc/uri-kuali-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,33 @@ function uri_kuali_api_get_subject_data( $subject ) {

}

/**
* Return only the newest course versions from a list of all active courses
*/
function uri_kuali_api_return_newest_course_versions( $res, $api_base ) {

$pids = array();
$course_list = array();

foreach( $res as $course ) {

$pid = $course->pid;

// If we've already pushed a course with this PID, we know we already have the latest version
if ( in_array( $pid, $pids ) ) {
continue;
}

// Otherwise, let's log the PID and push the course to the course list
array_push( $pids, $pid );
array_push( $course_list, $course );

}

return $course_list;

}



/**
Expand All @@ -136,17 +163,24 @@ function uri_kuali_api_get_courses( $id, $atts ) {
/* Build URL queries for a list of all courses in intervals of 100 if a course number isn't specified */
if (null === $atts['number']) {

$url_base = $api_base . '/cm/courses/queryAll?subjectCode=' . $id . '&sort=number&limit=100&status=active&fields=number,title,description,_id,pid';

$urls = array(
$api_base . '/cm/courses/queryAll?subjectCode=' . $id . '&sort=number&limit=100&status=active&skip=',
$api_base . '/cm/courses/queryAll?subjectCode=' . $id . '&sort=number&limit=100&status=active&skip=100',
$api_base . '/cm/courses/queryAll?subjectCode=' . $id . '&sort=number&limit=100&status=active&skip=200',
$url_base . '&skip=',
$url_base . '&skip=100',
$url_base . '&skip=200',
);

$getdata1 = uri_kuali_get_data( $urls[0] );
$getdata2 = uri_kuali_get_data( $urls[1] );
$getdata3 = uri_kuali_get_data( $urls[2] );

$course_list = (object)array_merge_recursive((array)$getdata1, (array)$getdata2, (array)$getdata3);
$data = (object)array_merge_recursive((array)$getdata1, (array)$getdata2, (array)$getdata3);

// @todo Contend with caching for this part
$course_list = uri_kuali_api_return_newest_course_versions( $data->res, $api_base );

//var_dump($course_list[0]);

return $course_list;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/uri-kuali-caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function uri_kuali_cache_retrieve( $url ) {

//var_dump($data);

if ( array_key_exists( $hash, $data ) ) {
if (is_array( $data ) && array_key_exists( $hash, $data ) ) {

//echo '<br />cache exists for ' . $hash;
$cache = $data[$hash];
Expand Down
2 changes: 1 addition & 1 deletion inc/uri-kuali-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function uri_kuali_shortcode( $attributes, $content, $shortcode ) {

$course_list = uri_kuali_api_get_courses( $subject_id, $attributes );

$output = uri_kuali_render_course_list( $course_list->res, $attributes );
$output = uri_kuali_render_course_list( $course_list, $attributes );

//var_dump( $course_list->res );

Expand Down
2 changes: 1 addition & 1 deletion uri-kuali.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: URI Kuali
Plugin URI: https://www.uri.edu
Description: Implements a shortcode to display course data from Kuali's API. [courses subject="AAF"]
Version: 1.4.0
Version: 1.5.0
Author: Brandon Fuller
Author: Alexandra Gauss
Author URI:
Expand Down

0 comments on commit 5649a26

Please sign in to comment.