EntityType.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Drupal\janrain_views;
  3. class EntityType {
  4. /**
  5. *
  6. * @var Api
  7. */
  8. public static $api;
  9. public static function bind(Api $api) {
  10. static::$api = $api;
  11. }
  12. /**
  13. * Janrain entityType/list
  14. *
  15. * Cannot use the "list" name as it is a PHP keyword.
  16. */
  17. public static function getList() {
  18. $api = static::$api;
  19. $ret = $api('entityType.list');
  20. return $ret;
  21. }
  22. public static function getEntityType($type_name = 'user') {
  23. $api = static::$api;
  24. $result = $api('entityType', array('type_name' => $type_name));
  25. if ($result['stat'] == 'ok') {
  26. $name = $result['schema']['name'];
  27. $rows = array();
  28. foreach ($result['schema']['attr_defs'] as $typeInfo) {
  29. $row = array();
  30. $row['name'] = $typeInfo['name'];
  31. $row['type'] = $typeInfo['type'];
  32. $row['description'] = isset($typeInfo['description']) ? $typeInfo['description'] : NULL;
  33. unset($typeInfo['name'], $typeInfo['type'], $typeInfo['description']);
  34. $items = array();
  35. foreach ($typeInfo as $k => $v) {
  36. $items[] = t('@k: @v', array('@k' => $k, '@v' => print_r($v, TRUE)));
  37. }
  38. $row['other'] = theme('item_list', array('items' => $items));
  39. $rows[] = $row;
  40. }
  41. $header = array(
  42. t('Name'),
  43. t('Type'),
  44. t('Description'),
  45. t('Other'),
  46. );
  47. $ret = array(
  48. '#theme' => 'table',
  49. '#header' => $header,
  50. '#rows' => $rows,
  51. );
  52. }
  53. else {
  54. $ret = t('Operation did not succeed.');
  55. }
  56. return $ret;
  57. }
  58. public static function getAccessSchema($type_name = 'user', $client_id = NULL) {
  59. $api = static::$api;
  60. if (empty($client_id)) {
  61. $client_id = $api->clientId;
  62. }
  63. $read = $api('entityType.getAccessSchema', array(
  64. 'type_name' => $type_name,
  65. 'for_client_id' => $client_id,
  66. 'access_type' => 'read',
  67. ));
  68. dsm($read);
  69. $write = $api('entityType.getAccessSchema', array(
  70. 'type_name' => $type_name,
  71. 'for_client_id' => $client_id,
  72. 'access_type' => 'read',
  73. ));
  74. dsm($write);
  75. }
  76. }