flag_lists.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Implements flag lists.
  5. */
  6. class flag_lists extends flag_flag {
  7. function save(&$flag) {
  8. krumo('here');
  9. $flag->flag_lists_save($flag);
  10. }
  11. /**
  12. * Saves a flag to the database. It is a wrapper around update($flag) and insert($flag).
  13. */
  14. function flag_lists_save(&$flag) {
  15. if (isset($flag->fid)) {
  16. flag_lists_update($flag);
  17. $flag->is_new = FALSE;
  18. }
  19. else {
  20. flag_lists_insert($flag);
  21. $flag->is_new = TRUE;
  22. }
  23. // Clear the page cache for anonymous users.
  24. // cache_clear_all('*', 'cache_page', TRUE);
  25. }
  26. /**
  27. * Saves an existing flag to the database. Better use save($flag).
  28. */
  29. function flag_lists_update($flag) {
  30. db_query("UPDATE {flag_lists_flags} SET title = '%s', name = '%s' WHERE fid = %d", $flag->title, $flag->name, $flag->fid);
  31. }
  32. /**
  33. * Saves a new flag to the database. Better use save($flag).
  34. */
  35. function flag_lists_insert($flag) {
  36. db_query("INSERT INTO {flag_lists_flags} (pfid, uid, content_type, name, title, options) VALUES (%d, %d, '%s', '%s', '%s', '%s')", $flag->pfid, $flag->uid, $flag->content_type, $flag->name, $flag->title, $flag->get_serialized_options($flag));
  37. $flag->fid = db_last_insert_id('flags', 'fid');
  38. $flag->name = 'flag_lists_'. $flag->uid .'_'. $flag->fid;
  39. $flag->flag_lists_update($flag);
  40. foreach ($flag->types as $type) {
  41. db_query("INSERT INTO {flag_types} (fid, type) VALUES (%d, '%s')", $flag->fid, $type);
  42. }
  43. }
  44. }