tmgmt.controller.translator.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Contains the translator controller class.
  5. */
  6. /**
  7. * Controller class for the job entity.
  8. *
  9. * @ingroup tmgmt_translator
  10. */
  11. class TMGMTTranslatorController extends EntityAPIControllerExportable {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
  16. $query = parent::buildQuery($ids, $conditions, $revision_id);
  17. if ($plugins = tmgmt_translator_plugin_info()) {
  18. $query->condition('plugin', array_keys($plugins));
  19. }
  20. else {
  21. // Don't return any translators if no plugin exists.
  22. $query->where('1 = 0');
  23. }
  24. // Sort by the weight of the translator.
  25. $query->orderBy('weight');
  26. return $query;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function delete($ids, DatabaseTransaction $transaction = NULL) {
  32. $cids = array();
  33. // We are never going to have many entities here, so we can risk a loop.
  34. foreach ($ids as $key => $name) {
  35. if (tmgmt_translator_busy($key)) {
  36. // The translator can't be deleted because it is currently busy. Remove
  37. // it from the ids so it wont get deleted in the parent implementation.
  38. unset($ids[$key]);
  39. }
  40. else {
  41. $cids[$key] = 'language:' . $key;
  42. }
  43. }
  44. // Clear the language cache for the deleted translators.
  45. cache_clear_all($cids, 'cache_tmgmt');
  46. parent::delete($ids, $transaction);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function save($entity, DatabaseTransaction $transaction = NULL) {
  52. $return = parent::save($entity, $transaction);
  53. // Clear the languages cache.
  54. cache_clear_all('language:' . $entity->name, 'cache_tmgmt');
  55. return $return;
  56. }
  57. }