607A Yorktown Place, Statesboro, GA 30461
http://www.chrissterling.me — chris@chrissterling.me
770-689-6679

Return to Resume

<?php
//this function takes a list of classes from D2L and creates shortcuts to different
//sections of desire2learn
function createD2LDeepLinks($classes){
    $notActive = array();
    if(isset($classes)){
    	//always show a link to the folio home
        if(!$classes){
            echo '<p><a href="./services/process-D2L-auth.php" target="_blank">Folio Home, News, and Resources</a></p>';
        }
        
        $total = 0;
        //does the user actually have classes
        if(isset($classes->Items)){
            $total = count($classes->Items);
            //we have some of our users who have a large number of classes (one has 180 classes) assigned to them
            //this hides more then 4 classes
            if($total > 4){
                echo '<div class="panel-expandable" data-short-height="250" style="overflow-y:hidden">';
            }
            //start actually looping through the classes
            foreach($classes->Items as $classInfo){
            	//only show active classes at this point
                if($classInfo->CourseInfo->IsActive){
                    $googleLink = 'Course Home';
                    if($classInfo->CourseInfo->Department->Name != 'Training'){
                        ?>
                        <a href="./services/process-D2L-auth.php?oid=<?php echo $classInfo->OrgUnit->Id; ?>&amp;location=home" target="_blank" data-google-link="Course Home" class="list-group-item folio-course-title" style="cursor:pointer;"><?php echo $classInfo->OrgUnit->Name;?></a>
                        <?php
                    }
                }
				//only want to show classes that don't involve the training courses at this time
                if($classInfo->CourseInfo->Department->Name != 'Training'){
                	//dump all the non-active courses down to the bottom
                    if(!$classInfo->CourseInfo->IsActive){
                        $notActive[] = $classInfo;
                    }else{
                    	//role 102 is instructor
                    	//instructor links
                        if($classInfo->Role->Id == 102){
                ?>
                            <span class="list-group-item">
                                <table style="width:100%;">
                                    <tr>
                                        <td><span class="glyphicon glyphicon-stats"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=sgrades" target="_blank">Grades</a></td>
                                        <td><span class="glyphicon glyphicon-cloud-upload"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=sdropbox" target="_blank">Dropbox</a></td>
                                        <td><span class="glyphicon glyphicon-pencil"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=squizzes" target="_blank">Quizzes</a></td>
                                    </tr>
                                </table>   
							</span>
                            <?php
                        //student link
                        }else{
                            ?>
                            <span class="list-group-item">
                                <table style="width:100%;">
                                    <tr>
                                        <td><span class="glyphicon glyphicon-stats"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=grades" target="_blank">Grades</a></td>
                                        <td><span class="glyphicon glyphicon-cloud-upload"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=dropbox" target="_blank">Dropbox</a></td>
                                        <td><span class="glyphicon glyphicon-pencil"></span>&nbsp;<a href="./services/process-D2L-auth.php?oid=<? echo $classInfo->OrgUnit->Id; ?>&amp;location=quizzes" target="_blank">Quizzes</a></td>
                                    </tr>
                                </table>
							</span>
                        <?php
                        }
                    }
                }else{
                	//move the training course to the top of the "non-active" list
                    array_unshift($notActive,$classInfo);
                }
            }
            //only loop through this section if we have "non-active" classes (includes training)           
            if(count($notActive) > 0){
				foreach($notActive as $classInfo){
					if($classInfo->CourseInfo->Department->Name == 'Training'){
						if($classInfo->CourseInfo->IsActive){
							//override the text that is sent to google analytics
							$googleLink = $classInfo->OrgUnit->Name;
						?>
							<a href="./services/process-D2L-auth.php?oid=<?php echo $classInfo->OrgUnit->Id; ?>&amp;location=home" target="_blank" data-google-link="Course Home" class="list-group-item folio-course-title" style="cursor:pointer;"><?php echo $classInfo->OrgUnit->Name;?></a>
							<span class="list-group-item"><span class="glyphicon glyphicon-home"></span><a href="./services/process-D2L-auth.php?oid=<?php echo $classInfo->OrgUnit->Id; ?>&amp;location=home" target="_blank" > Training Home</a></span>
						<?php
						}
					}else{
						if($classInfo->Role->Id == 102 || $classInfo->Role->Id == 104){
							echo '<a class="list-group-item folio-course-title">'.$classInfo->OrgUnit->Name.'</a>';
							echo '<a class="list-group-item list-group-item-info" href="./services/process-D2L-auth.php?oid='.$classInfo->OrgUnit->Id.'&amp;location=activate" target="_blank">Your course is not activated. Click here to activate course</a>';
						}else{
							echo '<a class="list-group-item folio-course-title">'.$classInfo->OrgUnit->Name.'</a>';
							echo '<a class="list-group-item list-group-item-info" href="">Your instructor has not activated this course yet.</a>';
						}
					}
				}
			}
			//course data is loaded in using ajax. D2L is located in Canada and is "slow" depending on the number of courses you have
        }elseif($classes == 'loading'){
            echo '<div class="text-center"><img src="./images/ajax-loader.gif" class="img-responsive center-block"><br /> Loading Desire2Learn Classes</div>';
        }else{
        //can't actually find any classes for the user
            createInfoMessage('We can\'t find any classes for you.');
        }

        if($total > 4){
        ?>
		</div>	
        <ul class="list-group">
			<a href="javascript:void(0)" class="list-group-item panel-expander">Show More (Total Classes: <?php echo $total; ?>)</a>
		</ul>
        <?php
        }    
    }else{
        createInfoMessage('<strong>Notice</strong>: Unable to load classes at this time. Please check back later.');
        //something happened, lets show the developer the error if it happened to them
        if(isset($classes) && $api->GetDebug()){
            createDangerMessage("Error:".$classes->GetResponse->ExceptionInfo->ErrorMessage);
            createDangerMessage("Error:".$classes->GetResponse->ExceptionInfo->ErrorString);
        }
    }
    
}

?>
Return to Resume