tmgmt.controller.remote.inc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @file
  4. * Contains the remote controller class.
  5. */
  6. /**
  7. * Controller class for the remote job mapping entity.
  8. *
  9. * @ingroup tmgmt_job
  10. */
  11. class TMGMTRemoteController extends EntityAPIController {
  12. public function load($ids = array(), $conditions = array()) {
  13. $entities = parent::load($ids, $conditions);
  14. foreach ($entities as &$entity) {
  15. if (is_string($entity->remote_data)) {
  16. $entity->remote_data = unserialize($entity->remote_data);
  17. }
  18. }
  19. return $entities;
  20. }
  21. /**
  22. * Loads remote mappings based on local data.
  23. *
  24. * @param int $tjid
  25. * Translation job id.
  26. * @param int $tjiid
  27. * Translation job item id.
  28. * @param int $data_item_key
  29. * Data item key.
  30. *
  31. * @return array
  32. * Array of TMGMTRemote entities.
  33. */
  34. function loadByLocalData($tjid = NULL, $tjiid = NULL, $data_item_key = NULL) {
  35. $data_item_key = tmgmt_ensure_keys_string($data_item_key);
  36. $query = new EntityFieldQuery();
  37. $query->entityCondition('entity_type', 'tmgmt_remote');
  38. if (!empty($tjid)) {
  39. $query->propertyCondition('tjid', $tjid);
  40. }
  41. if (!empty($tjiid)) {
  42. $query->propertyCondition('tjiid', $tjiid);
  43. }
  44. if (!empty($data_item_key)) {
  45. $query->propertyCondition('data_item_key', $data_item_key);
  46. }
  47. $result = $query->execute();
  48. if (isset($result['tmgmt_remote'])) {
  49. return entity_load('tmgmt_remote', array_keys($result['tmgmt_remote']));
  50. }
  51. return array();
  52. }
  53. /**
  54. * Loads remote mapping entities based on remote identifier.
  55. *
  56. * @param int $remote_identifier_1
  57. * @param int $remote_identifier_2
  58. * @param int $remote_identifier_3
  59. *
  60. * @return array
  61. * Array of TMGMTRemote entities.
  62. */
  63. function loadByRemoteIdentifier($remote_identifier_1 = NULL, $remote_identifier_2 = NULL, $remote_identifier_3 = NULL) {
  64. $query = new EntityFieldQuery();
  65. $query->entityCondition('entity_type', 'tmgmt_remote');
  66. if ($remote_identifier_1 !== NULL) {
  67. $query->propertyCondition('remote_identifier_1', $remote_identifier_1);
  68. }
  69. if ($remote_identifier_2 !== NULL) {
  70. $query->propertyCondition('remote_identifier_2', $remote_identifier_2);
  71. }
  72. if ($remote_identifier_3 !== NULL) {
  73. $query->propertyCondition('remote_identifier_3', $remote_identifier_3);
  74. }
  75. $result = $query->execute();
  76. if (isset($result['tmgmt_remote'])) {
  77. return entity_load('tmgmt_remote', array_keys($result['tmgmt_remote']));
  78. }
  79. return array();
  80. }
  81. }