/secure/models/Content_Library_Video.php

https://github.com/gogbuehi/BMCD.com · PHP · 152 lines · 134 code · 10 blank · 8 comment · 18 complexity · e657d99da6da93587034934bc2603e89 MD5 · raw file

  1. <?php
  2. require_once 'models/database_object.php';
  3. require_once 'models/Content_Library_Thumbnail.php';
  4. require_once 'includes/amfphp/services/vo/Video.php';
  5. /**
  6. * Description of Content_Library_Video
  7. *
  8. * @author Goodwin
  9. */
  10. class Content_Library_Video extends DBObject {
  11. public $d_location;
  12. public $d_o_content_library_thumbnail;
  13. public $d_width;
  14. public $d_height;
  15. public $d_title; //A.K.A. "title"
  16. public $d_alternate; //A.K.A. "alternate"
  17. public $d_description;
  18. public $d_scale;
  19. public $d_rotation;
  20. public $d_offset_x;
  21. public $d_offset_y;
  22. public $d_offset_seconds;
  23. public $d_blnvalid;
  24. public $d_domain;
  25. function __construct($value=null,$field='id') {
  26. if ($value instanceof Video) {
  27. parent::__construct(false);
  28. $this->loadDataFromAmfPhp($value);
  29. }
  30. else {
  31. parent::__construct($value, $field);
  32. }
  33. if ($value !== FALSE) {
  34. $this->save();
  35. }
  36. }
  37. function setDefaultValues($value,$field) {
  38. $this->tLog->debug('Setting '.$this->getTable().' default values...');
  39. parent::setDefaultValues($value,$field);
  40. $this->d_location = '';
  41. $this->d_title = '';
  42. $this->d_alternate = '';
  43. $this->d_description = '';
  44. $this->d_width = 0;
  45. $this->d_height = 0;
  46. $this->d_rotation = 0;
  47. $this->d_scale = 1;
  48. $this->d_offset_x = 0;
  49. $this->d_offset_y = 0;
  50. $this->d_blnvalid = true;
  51. $this->d_domain = $_SERVER['SERVER_NAME'];
  52. }
  53. function validateValue($key,$value) {
  54. switch($key) {
  55. case 'dt':
  56. if ($value == '') {
  57. return parent::validateValue($key,$_SERVER['REQUEST_TIME']);
  58. }
  59. else {
  60. return parent::validateValue($key, $value);
  61. }
  62. break;
  63. default:
  64. return parent::validateValue($key, $value);
  65. }
  66. }
  67. function revertValue($key,$value) {
  68. switch($key) {
  69. case 'id':
  70. if ($value === -1 || $value === 0) {
  71. return self::NULL;
  72. }
  73. else {
  74. return parent::revertValue($key, $value);
  75. }
  76. break;
  77. case 'dt':
  78. if ($value == '') {
  79. return $_SERVER['REQUEST_TIME'];
  80. }
  81. else {
  82. return parent::revertValue($key, $value);
  83. }
  84. break;
  85. case 'thumbnail_location':
  86. if (!self::isNull($value)) {
  87. return new Content_Library_Thumbnail($value,'location');
  88. }
  89. break;
  90. case 'content_library_thumbnail':
  91. //Only valid for "id"s
  92. if (!self::isNull($value)) {
  93. return new Content_Library_Thumbnail($value);
  94. }
  95. break;
  96. default:
  97. return parent::revertValue($key, $value);
  98. }
  99. return self::NULL;
  100. }
  101. function revertKey($key) {
  102. switch($key) {
  103. case 'thumbnail_location':
  104. return 'content_library_thumbnail';
  105. break;
  106. default:
  107. return parent::revertKey($key);
  108. }
  109. }
  110. function loadDataFromAmfPhp(Video $video) {
  111. $transientData = $video->getFields();
  112. $transientData = self::cleanupTransientData($transientData);
  113. $transientId = $transientData['id'];
  114. if (!self::isNull($this->revertValue('id',$transientId))) {
  115. //This object has an ID; Go ahead an load it
  116. $this->loadObjectByField($this->getTable(), 'id', $transientId, $this);
  117. if (!$this->isPersistent){
  118. $msg = 'AMFPHP is trying to save data for an object that is not in the database:'.$this->__toString();
  119. $this->tLog->error($msg);
  120. throw new Exception($msg);
  121. }
  122. }
  123. $this->loadData($transientData);
  124. //Figure out what thumbnail location is being used
  125. $thumbnailLocation = $transientData['thumbnail_location'];
  126. if ($this->d_o_content_library_thumbnail instanceof Content_Library_Thumbnail) {
  127. $this->d_o_content_library_thumbnail->setLocation($thumbnailLocation);
  128. }
  129. else {
  130. $this->d_o_content_library_thumbnail = new Content_Library_Thumbnail($thumbnailLocation,'location');
  131. }
  132. $this->d_domain = $_SERVER['SERVER_NAME'];
  133. }
  134. function getAmfPhpInstance() {
  135. $data = $this->getFields();
  136. $video = new Video();
  137. $video->loadData($data);
  138. $video->thumbnailLocation = $this->d_o_content_library_thumbnail->d_location;
  139. return $video;
  140. }
  141. }
  142. ?>