/package/app/app/plugins/content_distribution/lib/api/KalturaGenericDistributionProfile.php

https://github.com/richhl/kalturaCE · PHP · 173 lines · 112 code · 29 blank · 32 comment · 19 complexity · da87fc479c8b3523d71eb367dec08c79 MD5 · raw file

  1. <?php
  2. /**
  3. * @package plugins.contentDistribution
  4. * @subpackage api.objects
  5. */
  6. class KalturaGenericDistributionProfile extends KalturaDistributionProfile
  7. {
  8. /**
  9. * @insertonly
  10. * @var int
  11. */
  12. public $genericProviderId;
  13. /**
  14. * @var KalturaGenericDistributionProfileAction
  15. */
  16. public $submitAction;
  17. /**
  18. * @var KalturaGenericDistributionProfileAction
  19. */
  20. public $updateAction;
  21. /**
  22. * @var KalturaGenericDistributionProfileAction
  23. */
  24. public $deleteAction;
  25. /**
  26. * @var KalturaGenericDistributionProfileAction
  27. */
  28. public $fetchReportAction;
  29. /**
  30. * @var string
  31. */
  32. public $updateRequiredEntryFields;
  33. /**
  34. * @var string
  35. */
  36. public $updateRequiredMetadataXPaths;
  37. /*
  38. * mapping between the field on this object (on the left) and the setter/getter on the object (on the right)
  39. */
  40. private static $map_between_objects = array
  41. (
  42. 'genericProviderId',
  43. );
  44. public function getMapBetweenObjects()
  45. {
  46. return array_merge(parent::getMapBetweenObjects(), self::$map_between_objects);
  47. }
  48. private static $actions = array
  49. (
  50. 'submit',
  51. 'update',
  52. 'delete',
  53. 'fetchReport',
  54. );
  55. public function toObject($object = null, $skip = array())
  56. {
  57. if(is_null($object))
  58. $object = new GenericDistributionProfile();
  59. $object = parent::toObject($object, $skip);
  60. foreach(self::$actions as $action)
  61. {
  62. $actionAttribute = "{$action}Action";
  63. if(!$this->$actionAttribute)
  64. continue;
  65. $typeReflector = KalturaTypeReflectorCacher::get(get_class($this->$actionAttribute));
  66. foreach ( $this->$actionAttribute->getMapBetweenObjects() as $this_prop => $object_prop )
  67. {
  68. if ( is_numeric( $this_prop) ) $this_prop = $object_prop;
  69. if (in_array($this_prop, $skip)) continue;
  70. $value = $this->$actionAttribute->$this_prop;
  71. if ($value !== null)
  72. {
  73. $propertyInfo = $typeReflector->getProperty($this_prop);
  74. if (!$propertyInfo)
  75. {
  76. KalturaLog::alert("property [$this_prop] was not found on object class [" . get_class($object) . "]");
  77. }
  78. else if ($propertyInfo->isDynamicEnum())
  79. {
  80. $propertyType = $propertyInfo->getType();
  81. $enumType = call_user_func(array($propertyType, 'getEnumClass'));
  82. $value = kPluginableEnumsManager::apiToCore($enumType, $value);
  83. }
  84. if ($value !== null)
  85. {
  86. $setter_callback = array($object, "set{$object_prop}");
  87. if (is_callable($setter_callback))
  88. call_user_func_array($setter_callback, array($value, $action));
  89. else
  90. KalturaLog::alert("setter for property [$object_prop] was not found on object class [" . get_class($object) . "]");
  91. }
  92. }
  93. }
  94. }
  95. $object->setUpdateRequiredEntryFields(explode(',', $this->updateRequiredEntryFields));
  96. $object->setUpdateRequiredMetadataXpaths(explode(',', $this->updateRequiredMetadataXPaths));
  97. return $object;
  98. }
  99. public function fromObject($object)
  100. {
  101. parent::fromObject($object);
  102. foreach(self::$actions as $action)
  103. {
  104. $actionAttribute = "{$action}Action";
  105. if(!$this->$actionAttribute)
  106. $this->$actionAttribute = new KalturaGenericDistributionProfileAction();
  107. $reflector = KalturaTypeReflectorCacher::get(get_class($this->$actionAttribute));
  108. $properties = $reflector->getProperties();
  109. foreach ( $this->$actionAttribute->getMapBetweenObjects() as $this_prop => $object_prop )
  110. {
  111. if ( is_numeric( $this_prop) )
  112. $this_prop = $object_prop;
  113. if(!isset($properties[$this_prop]) || $properties[$this_prop]->isWriteOnly())
  114. continue;
  115. $getter_callback = array ( $object ,"get{$object_prop}" );
  116. if (is_callable($getter_callback))
  117. {
  118. $value = call_user_func($getter_callback, $action);
  119. if($properties[$this_prop]->isDynamicEnum())
  120. {
  121. $propertyType = $properties[$this_prop]->getType();
  122. $enumType = call_user_func(array($propertyType, 'getEnumClass'));
  123. $value = kPluginableEnumsManager::coreToApi($enumType, $value);
  124. }
  125. $this->$actionAttribute->$this_prop = $value;
  126. }
  127. else
  128. {
  129. KalturaLog::alert("getter for property [$object_prop] was not found on object class [" . get_class($object) . "]");
  130. }
  131. }
  132. }
  133. $this->updateRequiredEntryFields = implode(',', $object->getUpdateRequiredEntryFields());
  134. $this->updateRequiredMetadataXPaths = implode(',', $object->getUpdateRequiredMetadataXPaths());
  135. }
  136. /* (non-PHPdoc)
  137. * @see KalturaObject::validateForInsert()
  138. */
  139. public function validateForInsert()
  140. {
  141. parent::validateForInsert();
  142. $this->validatePropertyNumeric('genericProviderId');
  143. }
  144. }