CRUD in Drupal

No. Not crud. CRUD. Create, Read, Update, Delete. The basic operations a web app needs to do on database records.

I’ve been working on the Provisionator module, which helps with institutional-scale deployments of Drupal sites on a shared hosting server. The module began life as a separate PHP application, and evolved into a Drupal module wrapping those functions. It essentially managed a table within a Drupal site’s database, adding rows for each website deployed.

I was just working on adding the rest of the CRUD support (it already handled Create and Read OK, but not Update (edit) nor Delete). I was looking for The Drupal Way when it hit me. I don’t know why I didn’t see it before.

I don’t need to manage a table, nor do I need to manually implement CRUD operations.

All I need to do is define a custom content/node type, and let Drupal take care of the basic CRUD operations. The Provisionator module will then simply implement relevant bits of the node API and have it get called when nodes of the appropriate type are inserted, edited, or deleted. I can add whatever “fields” I want as properties of the custom node type, so it should be easier to extend than the current hard-coded table.

I’m going to attempt converting to the Drupal node + hooks + node API pattern ASAP. I think it’s going to be relatively straightforward, and offers some pretty cool benefits. Instead of having an essentially static list of sites in a custom database table, I’ll be able to add sites (as nodes) to various taxonomies, enable comments on the site node, and easily implement various permissions (user can create sites, user can list sites, user can edit all sites, user can edit own sites, user can delete all sites, user can delete own sites, etc…)

Portable Camera Storage on the cheap?

I’m planning a vacation in the spring. The tickets are all in place, and we’re looking forward to it. Can’t say more, because it’s a surprise Christmas present. I’d love to leave the laptop at home, but would currently need to bring it along to dump photos off the camera every day.

Does anyone have any great (and cheap) solution to offload photos from a camera (Canon Digital Rebel xt) without a laptop? I’ve got a 5G iPod (30 Gig), and have looked at the Apple and Belkin media readers – both of which apparently suck the soul out of the battery before finishing the job.

I’ve seen some pretty sweet portable hard drive systems (Epson P-3000, Smartdisk Photobank, XS Drive Super, etc…), but I’m not going to spend $800 for a handy camera offloader, no matter how cool it is.

Lazyweb, help me! What’s the best bang-for-the-buck solution? DIY is OK, too. Oh, and Epson? If you want to send me a P-3000 to review, I’d be more than happy to test it out…

Custom Fields in Drupal Event Signups

We’re using the Event module to list our workshops at the Teaching & Learning Centre, and the Signup module to let people register to attend workshops (or other events). It’s working really quite well, but we needed to add some extra fields to the registration form so we could track Faculties, Status, etc…

“Sure,” I said, “Drupal’s open source, so we should be able to add any fields we want. Worst case scenario? We’d have to fork Signup.module and maintain our own version with our custom fields in it.”

I then proceeded to drag my feet, not looking forward to having to maintain a module for something as simple as adding some custom fields. Maybe I could use the FormsAPI and insert the fields through some custom code?

So, I poked through the signup.module source code to see what would be involved. I’d braced for some rather convoluted and involved hackery. I blocked my schedule for the day so I’d have time to dedicate to the task.

Then, I saw that the module developers had already done the work for me. They implemented the signup form’s fields as a themable method, letting me override it on a per-theme basis. Without having to touch the code for the module itself. Brilliant. Absofrakking brilliant. So, I added this code to our theme’s template.php file (the theme is called “uofc_thisisnow”):

function uofc_thisisnow_signup_user_form() {
	$form['signup_form_data']['#tree'] = TRUE;
	$form['signup_form_data']['Name'] = array(
		'#type' => 'textfield', 
		'#title' => t('Name'), 
		'#size' => 40, 
		'#maxlength' => 64
	);
	$form['signup_form_data']['Phone'] = array(
		'#type' => 'textfield', 
		'#title' => t('Phone'), 
		'#size' => 40, 
		'#maxlength' => 64
	);
	$form['signup_form_data']['Faculty'] = array(
		'#type' => 'textfield', 
		'#title' => t('Faculty or Department'), 
		'#size' => 40, 
		'#maxlength' => 64
	);
	$form['signup_form_data']['Status'] = array(
		'#type' => 'select', 
		'#title' => t('Status'), 
		'#default_value' => t('Faculty Member'), 
		'#options' => array(
			'faculty' => t('Faculty Member'),
			'staff' => t('Staff'), 
			'student' => t('Student'), 
			'other' => t('Other')
		)
	);
  return $form;
}

That results in a signup form that looks like this:

TLC Workshop Signup with Custom FieldsTLC Workshop Signup with Custom Fields

The beauty of this, since it exposes the full FormsAPI, we can add select menus, radio boxes, default values, etc… Without having to touch the code of the Signup module itself. Very cool stuff.

TED Talks are changing how I think

I’ve been slowly working through the TED Talks video podcasts – making time to watch several sessions each week. I can’t even begin to describe what an impact they’re having on me. I’m starting to think differently about many issues – some I hadn’t even considered before, others I thought were outside of my reach.

I watched Majora Carter’s presentation this morning. She is the founder of Sustainable South Bronx – a grassroots movement she started in her community to try to bring it back from the brink of ecological (and social and economic) devastation.

I live in a pretty well-off community, in a pretty well-off city, in a pretty well-off country. I hadn’t given much thought to the connection between ecological, social and economic planning and well-being. Hearing about what happened to the South Bronx as a result of wanton exploitation of a marginalized region’s resources (human and environmental) made me wonder what we’re doing here in Alberta, where our entire province feels like it’s sole purpose is to extract oil from the tar sands. I’m wondering what impacts we’ll be seeing in 60 years…

I also watched Sir Ken Robinson’s session on creativity in the education system. Another absolutely amazing and provocative presentation that’s changed how I think about “non academic” education. If we don’t value and reward creativity in our young people, rather than drilling it out of them through an industrialized worker bee factory, we’re wasting the skills and talents we’ll need to remain flexible as a society.

The session list goes on and on. Al Gore on the environment. Jimmy Wales on Wikipedia. Negroponte on the $100 laptop. Aubrey de Grey on extending or preventing senescence (now THAT’s something that will have a HUGE impact – ethical and moral implications on both sides of his argument). Every single session has sparked something for me. I’m positive I’ll be percolating much of it in my head for years to come.

The CogDogBlog Will Be Back Soon

I got an email from Alan last night mentioning that his blog was actually knocked offline by the overzealous actions of spammers. They were hammering his site so hard that his host had to kill the site. He had been running the CogDogBlog on some graciously donated webspace, so it’s understandable that they weren’t thrilled about the load that spammers can add to a server.

Unfortunately, Alan’s got a Day Job which is currently in conference management mode (i.e., traveling and busy) so he’ll be trying to get things back up and running in the few spare milliseconds he can eke out in the next little while.

Yet another reason why Google needs to step up and show some serious corporate responsibility in helping to actually solve the spam problem created by Adsense. Come ON, Google, what’s it going to take? How many billions of spamments need to be inflicted on blogs, wikis, and other open web spaces before you’ll act?

I’ve outlined some potential ways to solve the problem, but curiously never heard from Larry or Sergey.

Flickr: Public Artwork Hacks

The Conversation - improvedWhile browsing the Flickr photos from Calgary, I came across this one by Sherlock77. It prompted a brief discussion, wondering if there was a group for people to put photos of public artwork that had been hacked (or dressed, or modified, or adorned) – legally and non-destructively. I did some searching, but didn’t find anything. So, I created a public group: Public Artwork Hacks.

If you have (or plan to take) photos of public artwork that has been “improved” – here’s the place to share it. Put a Santa hat on The Thinker. Sunglasses on David. Photos that include modifications – without the use of Photoshop to add things – are welcome!

The group is currently rather empty, but it should be cool to see what (if anything) happens. ‘Tis the season for hacking public artwork

Dreamtube

Dreamhost rocks. I mean, they just keep piling on awesome new features into their hosting package. Recently, it was essentially infinite bandwidth and storage. Yesterday, they added an automatic Flash video transcoder and presenter, ala YouTube. But, within any Dreamhost site.

All I have to do is upload a video file (.avi, .mov, .mp4) to my site, tell Dreamhost I want it converted to Flash video (using the panel.dreamhost.com site that’s used for managing everything else as well), and their magic elves do their work and email me a javascript snippet to embed a flash player in any web page (or blog post). Like, for instance, this one:

[flv:http://www.darcynorman.net/video/banffdaylight_640x320.flv 640 320]

It seems to choke on some video formats (it didn’t like my screencast at all – perhaps it’s not able to deal with the H.264 video encoding or AAC audio encoding…)

Now, if only Dreamhost would solve the intermittent MySQL performance suckage, things would be perfect!

EduGlu = Drupal + Leech.module?

Thanks to a tip from Bill Fitzgerald, I checked out a copy of the Leech module for Drupal. Despite the rather bad name, it sounds like it is (or eventually will be) perfect for what I need.

It lets users add their own feeds, and can associate said feeds and subsequently aggregated items wit any of the user’s Organic Groups. That takes care of the Class/Cohort/etc… concepts. Users just create or join the appropriate Organic Groups within the Drupal site, and add whatever feeds they want to whatever Organic Groups they want. They could add subfeeds of a blog to different OGs (say myfancyblog.com/tags/bio680/feed to the Biology 680 OG, and myfancyblog.com/tags/poli544 to the Political Science 544 OG…)

It’s not firing on all cylinders at the moment – I think it’s failing to add items to the specified OG, and some other minor things. But it’s going to be waaaaaay simpler to just roll up my sleeves and help out on Leech.module than to write anything from scratch.

Combined with stuff like the Views module, this could be an insanely powerful tool to help pull disparate feeds for users, spread across the internets, into a cohesive community site that behaves organically depending on the whims of the users. Very cool.