Here is what an assignment looks like (today) on the development version for a theme that will ultimately give other people a way to build something like the ds106 Assignment Bank

outspice yourself assignment

This nonsensical example may or may not be here tomorrow, click at your own peril.

A screenshot does not give an indication about what it has slowly taken to get just this far. It;s one thing to hack and whack one’s way at the code to get a site like this to world; it’s another to try and build it in way that will be flexible for future and varied uses. I am not messing much with the layout now, it’s more about what’s under the hood.

I’ve been able to reduce the database calls in half over the original, and removed a big swath of redundant code. A major change is in how each assignment will get a unique tag. On the ds106 site, it was built to create the tags sequentially as they were added to the site, so a new Design Assignment would be give takes DesignAssignments and DesignAssignments1245 if there were 1244 assignments created before. It takes extra effort to find the last tag assigned an increment, and there seems maybe a small chance of some collision if two assignments are created at the same time.

But before I do that, one flexibility I am building in is that not everyone might be creating assignments- they might be lessons, activities, recipes, challenges, so when done right now it is hard coded as a defined variable) is the “kind” of thing in the bank, or in my code:

define('THINGNAME', 'Assignment');

Eventually this will be saved as theme option. This means that every red underline place on the page where it says “Assignment” (or “assignment”) it could be something else, including the tag names:

(click image to see full size)
(click image to see full size)

So it makes sense to me that it is better to name the unique tag for an assignment based on the id number of the item in the database, since that is unique, and the kind of thing it is. So if your site was a bank of Lessons, the tags for my spice activity would be “CookingLesson” and “Lesson14”. This simplifies a few code things since I don;t have to lookup the WordPress terms, I can construct it knowing the post id and the name for the kind of thing.

The general tag for all items, “CookingLesson” comes from the taxonomy assigned for the type of “thing” it is, set in wordpress via a custom teaxonomy.

meta assignmentThe types of assignments will eventually be defined in the theme options, and automatically set when an assignment (I still use name that internally) is created, usually through a submission form (admins will of course be able to create them from scratch in the WordPress editor, as I have been doing to test this out).

Assignment Tags are how we track examples for an assignment (via the unique tag) and a family of assignments, and likewise for tutorials.

If we knoe the Assignment Type, then the other values for Assignment Tags and Tutorial Tags can be automatically generated. So I found a way to have them created automatically (or reset) when an assignment item is saved.

This is all done in the theme’s functions.php

add_action( 'save_post', 'set_assignment_tag');

function set_assignment_tag($post_id) {
	// on saving an assignment make sure it is assigned  unique tags 
	// based on type of assignment and post ID
	// code from http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

	// skip if not an assignment post type or it is a revision
	if  ( $_POST['post_type'] != 'assignments' or wp_is_post_revision( $post_id ) ) return;
	
	// skip if user does not have edit capabilities
    if ( !current_user_can( 'edit_post', $post_id ) ) {
        return;
    }

    /* Request passes all checks; update the things's taxonomy */
    
    // get terms for type of assignment
	$assignmenttype_terms = wp_get_object_terms($post_id, 'assignmenttypes');
		
	// make a tag for the type of assignment, assign to both taxonomies
	// for assignment examples and tutorials
	if ( count( $assignmenttype_terms ) ) {
		$assignment_type = $assignmenttype_terms[0]->name . THINGNAME;
		wp_set_object_terms( $post_id, $assignment_type , 'assignmenttags');
		wp_set_object_terms( $post_id, $assignment_type , 'tutorialtags');
	}	
    
    // create unique tag names based on post ids
    $assignment_tag = THINGNAME . $post_id; 
    $tutorial_tag =  'Tutorial' . $post_id;
     
    if ( term_exists(  $assignment_tag, 'assignments') == 0) {
    	// check if term does not exist, then add to assignment tags
    	wp_insert_term( $assignment_tag, 'assignmenttags' );
    }
    
    if ( term_exists(  $tutorial_tag , 'assignments') == 0) {
    	// check if term does not exist, then add to tutorial tags
    	wp_insert_term( $tutorial_tag , 'tutorialtags' );
    }

    // now assign tags, append to other terms
    wp_set_object_terms( $post_id, $assignment_tag, 'assignmenttags', true);
    wp_set_object_terms( $post_id, $tutorial_tag, 'tutorialtags', true );
}
    

The other thing that comes up is that use of the WP_Ratings plugin for the “stars” difficulty rating means that someone using the site will have to change a few options (the output templates) for the plugin… this might be able to be coded in the theme set up, or I might just provide the documentation. You could use other kinds of rating schemes the plugin offers (a 10 point scale? hearts instead of stars?).

I probably twiddled a bot too much today with different layout options.

(click image to see full size)
(click image to see full size)

Every thing in the boxes is a related chunk of information. With some documentation there is no reason why someone could not re-rig the template to have maybe 3 columns or 1 or re-organize. The Wp-Bootstrap theme is easy to figure out how to grid things- use a class of span4 to have a column 1/3 the width of the whole space (it has 12 units). I’m leaving thar for later, and hoping not to have too many custom classes.

I am not sure if we will be able to use the gravatars for the user examples; it works on ds106 because the assignments bank is part of a multisite with the main aggregator in ds106.us, and that is the only reason (I think) that we get a known author.

The next step is to work on building the means for site visitors to submit new assignments, and examples/tutorials directly to an assignment, which will bypass the need for the Gravity Forms plugin ($$$) used on ds106. And then to try and add a tab for theme options to allow customization.

One of those options will be to provide feeds to syndicate the sources of examples/tutorials, as we do know for ds106. It’s a bit tricky, since what we do on ds106 is syndicate in a feed for each assignment type (a feed for DesignAssignments, one for WritingAssignments, etc). This means we are syndicating from a syndication site!). I am thinking/hoping/guessing is as a site owner adds names for the types of assignments “e.g. Cooking, Gardening, Music” in my test site, the theme can provide form fields for a feed to use to syndicate form… if Feed WordPress is installed, I should be able to add the feed via code, so the syndication part should be automated. This is a huge conjecture!

It will likely be the end of the month before this is really ready for some beta testing. I hope to clean the templates so they use as much as possible of the parent theme CSS.

And son=on, you will be able to submit your examples for this assignment!

overture

The post "ds106 Bank Nuevo: Assignments Now Fully Functional" was originally pushed out of the bottom of a purple jar of Play-Doh at CogDogBlog (http://cogdogblog.com/2013/08/ds106-bank-nuevo-assignments-functional/) on August 22, 2013.

1 Comment

Leave a Comment

All fields are required. Your email address will not be published.