Creating your own Drupal entity. http://www.istos.it/blog/drupal-entities/drupal-entities-part-3-programm...