PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/package/app/app/alpha/lib/model/entry.php

https://bitbucket.org/pandaos/kaltura
PHP | 2584 lines | 1855 code | 412 blank | 317 comment | 353 complexity | ae7c4ee32669c4d8ae9f60b4d74a3fa6 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. /**
  3. * Subclass for representing a row from the 'entry' table.
  4. *
  5. *
  6. *
  7. * @package Core
  8. * @subpackage model
  9. */
  10. class entry extends Baseentry implements ISyncableFile, IIndexable
  11. {
  12. private $previous_status ;
  13. protected $old_categories;
  14. protected $is_categories_modified = false;
  15. const MINIMUM_ID_TO_DISPLAY = 8999;
  16. const ROOTS_FIELD_PREFIX = 'K_Pref';
  17. const ROOTS_FIELD_ENTRY_PREFIX = 'KP_Entry';
  18. const ROOTS_FIELD_BULK_UPLOAD_PREFIX = 'KP_Bulk';
  19. // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
  20. // different sort orders for browsing entries
  21. const ENTRY_SORT_MOST_VIEWED = 0;
  22. const ENTRY_SORT_MOST_RECENT = 1;
  23. const ENTRY_SORT_MOST_COMMENTS = 2;
  24. const ENTRY_SORT_MOST_FAVORITES = 3;
  25. const ENTRY_SORT_RANK = 4;
  26. const ENTRY_SORT_MEDIA_TYPE = 5;
  27. const ENTRY_SORT_NAME = 6;
  28. const ENTRY_SORT_KUSER_SCREEN_NAME = 7;
  29. // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
  30. const ENTRY_MEDIA_TYPE_AUTOMATIC = -1;
  31. const ENTRY_MEDIA_TYPE_ANY = 0;
  32. const ENTRY_MEDIA_TYPE_VIDEO = 1;
  33. const ENTRY_MEDIA_TYPE_IMAGE = 2;
  34. const ENTRY_MEDIA_TYPE_TEXT = 3;
  35. const ENTRY_MEDIA_TYPE_HTML = 4;
  36. const ENTRY_MEDIA_TYPE_AUDIO = 5;
  37. const ENTRY_MEDIA_TYPE_SHOW = 6;
  38. const ENTRY_MEDIA_TYPE_SHOW_XML = 7; // for the kplayer: the data contains the xml itself and not a url
  39. const ENTRY_MEDIA_TYPE_BUBBLES = 9;
  40. const ENTRY_MEDIA_TYPE_XML = 10;
  41. const ENTRY_MEDIA_TYPE_DOCUMENT = 11;
  42. const ENTRY_MEDIA_TYPE_SWF = 12;
  43. const ENTRY_MEDIA_TYPE_PDF = 13;
  44. const ENTRY_MEDIA_TYPE_GENERIC_1= 101; // these types can be used for derived classes - assume this is some kind of TXT file
  45. const ENTRY_MEDIA_TYPE_GENERIC_2= 102; // these types can be used for derived classes
  46. const ENTRY_MEDIA_TYPE_GENERIC_3= 103; // these types can be used for derived classes
  47. const ENTRY_MEDIA_TYPE_GENERIC_4= 104; // these types can be used for derived classes
  48. const ENTRY_MEDIA_TYPE_LIVE_STREAM_FLASH = 201;
  49. const ENTRY_MEDIA_TYPE_LIVE_STREAM_WINDOWS_MEDIA = 202;
  50. const ENTRY_MEDIA_TYPE_LIVE_STREAM_REAL_MEDIA = 203;
  51. const ENTRY_MEDIA_TYPE_LIVE_STREAM_QUICKTIME = 204;
  52. // NOTE - CHANGES MUST BE MADE TO LAYOUT.PHP JS PART AS WELL
  53. const ENTRY_MEDIA_SOURCE_FILE = 1;
  54. const ENTRY_MEDIA_SOURCE_WEBCAM = 2;
  55. const ENTRY_MEDIA_SOURCE_FLICKR = 3;
  56. const ENTRY_MEDIA_SOURCE_YOUTUBE = 4;
  57. const ENTRY_MEDIA_SOURCE_URL = 5;
  58. const ENTRY_MEDIA_SOURCE_TEXT = 6;
  59. const ENTRY_MEDIA_SOURCE_MYSPACE = 7;
  60. const ENTRY_MEDIA_SOURCE_PHOTOBUCKET = 8;
  61. const ENTRY_MEDIA_SOURCE_JAMENDO = 9;
  62. const ENTRY_MEDIA_SOURCE_CCMIXTER = 10;
  63. const ENTRY_MEDIA_SOURCE_NYPL = 11;
  64. const ENTRY_MEDIA_SOURCE_CURRENT = 12;
  65. const ENTRY_MEDIA_SOURCE_MEDIA_COMMONS = 13;
  66. const ENTRY_MEDIA_SOURCE_KALTURA = 20;
  67. const ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS = 21;
  68. const ENTRY_MEDIA_SOURCE_ARCHIVE_ORG = 22;
  69. const ENTRY_MEDIA_SOURCE_KALTURA_PARTNER = 23;
  70. const ENTRY_MEDIA_SOURCE_METACAFE = 24;
  71. const ENTRY_MEDIA_SOURCE_KALTURA_QA = 25;
  72. const ENTRY_MEDIA_SOURCE_KALTURA_KSHOW = 26;
  73. const ENTRY_MEDIA_SOURCE_KALTURA_PARTNER_KSHOW = 27;
  74. const ENTRY_MEDIA_SOURCE_SEARCH_PROXY = 28;
  75. const ENTRY_MEDIA_SOURCE_AKAMAI_LIVE = 29;
  76. const ENTRY_MEDIA_SOURCE_PARTNER_SPECIFIC = 100;
  77. const ENTRY_MODERATION_STATUS_PENDING_MODERATION = 1;
  78. const ENTRY_MODERATION_STATUS_APPROVED = 2;
  79. const ENTRY_MODERATION_STATUS_REJECTED = 3;
  80. const ENTRY_MODERATION_STATUS_FLAGGED_FOR_REVIEW = 5;
  81. const ENTRY_MODERATION_STATUS_AUTO_APPROVED = 6;
  82. const MAX_NORMALIZED_RANK = 5;
  83. const MAX_CATEGORIES_PER_ENTRY = 32;
  84. const FILE_SYNC_ENTRY_SUB_TYPE_DATA = 1;
  85. const FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT = 2;
  86. const FILE_SYNC_ENTRY_SUB_TYPE_THUMB = 3;
  87. const FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE = 4;
  88. const FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD = 5;
  89. const FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB = 6;
  90. const FILE_SYNC_ENTRY_SUB_TYPE_ISM = 7;
  91. const FILE_SYNC_ENTRY_SUB_TYPE_ISMC = 8;
  92. const FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG = 9;
  93. const MIX_EDITOR_TYPE_SIMPLE = 1;
  94. const MIX_EDITOR_TYPE_ADVANCED = 2;
  95. const ENTRY_DURATION_TYPE_NOTAVAILABLE = "notavailable";
  96. const ENTRY_DURATION_TYPE_SHORT = "short";
  97. const ENTRY_DURATION_TYPE_MEDIUM = "medium";
  98. const ENTRY_DURATION_TYPE_LONG = "long";
  99. const ENTRY_CATEGORY_ESCAPE = "_";
  100. const ENTRY_CATEGORY_SEPARATOR = ",";
  101. private $appears_in = null;
  102. private $m_added_moderation = false;
  103. private $should_call_set_data_content = false;
  104. private $data_content = null;
  105. private $desired_version = null;
  106. private $archive_extension = null;
  107. private static $mediaTypeNames = array(
  108. self::ENTRY_MEDIA_TYPE_AUTOMATIC => 'AUTOMATIC',
  109. self::ENTRY_MEDIA_TYPE_ANY => 'ANY',
  110. self::ENTRY_MEDIA_TYPE_VIDEO => 'VIDEO',
  111. self::ENTRY_MEDIA_TYPE_IMAGE => 'IMAGE',
  112. self::ENTRY_MEDIA_TYPE_TEXT => 'TEXT',
  113. self::ENTRY_MEDIA_TYPE_HTML => 'HTML',
  114. self::ENTRY_MEDIA_TYPE_AUDIO => 'AUDIO',
  115. self::ENTRY_MEDIA_TYPE_SHOW => 'SHOW',
  116. self::ENTRY_MEDIA_TYPE_SHOW_XML => 'SHOW_XML',
  117. self::ENTRY_MEDIA_TYPE_BUBBLES => 'BUBBLES',
  118. self::ENTRY_MEDIA_TYPE_XML => 'XML',
  119. self::ENTRY_MEDIA_TYPE_DOCUMENT => 'DOCUMENT',
  120. self::ENTRY_MEDIA_TYPE_SWF => 'SWF',
  121. self::ENTRY_MEDIA_TYPE_PDF => 'PDF',
  122. self::ENTRY_MEDIA_TYPE_GENERIC_1 => 'GENERIC_1',
  123. self::ENTRY_MEDIA_TYPE_GENERIC_2 => 'GENERIC_2',
  124. self::ENTRY_MEDIA_TYPE_GENERIC_3 => 'GENERIC_3',
  125. self::ENTRY_MEDIA_TYPE_GENERIC_4 => 'GENERIC_4',
  126. self::ENTRY_MEDIA_TYPE_LIVE_STREAM_FLASH => 'LIVE_STREAM_FLASH',
  127. self::ENTRY_MEDIA_TYPE_LIVE_STREAM_WINDOWS_MEDIA => 'LIVE_STREAM_WINDOWS_MEDIA',
  128. self::ENTRY_MEDIA_TYPE_LIVE_STREAM_REAL_MEDIA => 'LIVE_STREAM_REAL_MEDIA',
  129. self::ENTRY_MEDIA_TYPE_LIVE_STREAM_QUICKTIME => 'LIVE_STREAM_QUICKTIME',
  130. );
  131. /**
  132. * Applies default values to this object.
  133. * This method should be called from the object's constructor (or
  134. * equivalent initialization method).
  135. * @see __construct()
  136. */
  137. public function applyDefaultValues()
  138. {
  139. parent::applyDefaultValues();
  140. $this->setStatus(entryStatus::PENDING);
  141. $this->setModerationStatus(self::ENTRY_MODERATION_STATUS_AUTO_APPROVED);
  142. }
  143. // the columns names is a list of all fields that will participate in the search_text
  144. // TODO - add the admin_tags to the column names
  145. public static function getColumnNames() { return array ( "name" , "tags" ,"description" , "admin_tags" ); }
  146. public static function getSearchableColumnName () { return "search_text" ; }
  147. // don't stop until a unique hash is created for this object
  148. private static function calculateId ( )
  149. {
  150. $dc = kDataCenterMgr::getCurrentDc();
  151. for ( $i = 0 ; $i < 10 ; ++$i)
  152. {
  153. $id = $dc["id"].'_'.kString::generateStringId();
  154. $existing_object = entryPeer::retrieveByPk( $id );
  155. if ( ! $existing_object ) return $id;
  156. }
  157. die();
  158. }
  159. public function justSave($con = null)
  160. {
  161. return parent::save( $con );
  162. }
  163. public function save(PropelPDO $con = null)
  164. {
  165. $is_new = false;
  166. if ( $this->isNew() )
  167. {
  168. $this->setId(self::calculateId());
  169. // start by setting the modified_at to the current time
  170. $this->setModifiedAt( time() ) ;
  171. $this->setModerationCount(0);
  172. if (is_null($this->getAccessControlId()))
  173. {
  174. $partner = $this->getPartner();
  175. if($partner)
  176. $this->setAccessControlId($partner->getDefaultAccessControlId());
  177. }
  178. // only media clips should increments - not roughcuts or backgrounds
  179. if ( $this->type == entryType::MEDIA_CLIP )
  180. myStatisticsMgr::addEntry( $this );
  181. $is_new = true;
  182. }
  183. if ( $this->isColumnModified ( entryPeer::STATUS ) && ( $this->previous_status != $this->getStatus() ) )
  184. {
  185. // add a track for when the status changed
  186. $track_entry = new TrackEntry();
  187. $track_entry->setEntryId( $this->getId() );
  188. $track_entry->setTrackEventTypeId( TrackEntry::TRACK_ENTRY_EVENT_TYPE_UPDATE_ENTRY );
  189. $track_entry->setChangedProperties( "status [{$this->previous_status}]->[{$this->getStatus()}]" );
  190. if ( $this->previous_status != entryStatus::DELETED &&
  191. $this->getStatus() == entryStatus::DELETED )
  192. {
  193. myStatisticsMgr::deleteEntry( $this );
  194. $track_entry->setTrackEventTypeId( TrackEntry::TRACK_ENTRY_EVENT_TYPE_DELETED_ENTRY );
  195. }
  196. TrackEntry::addTrackEntry( $track_entry );
  197. }
  198. if ( $this->type == entryType::MIX )
  199. {
  200. // some of the properties should be copied to the kshow
  201. $kshow = $this->getkshow();
  202. if ( $kshow )
  203. {
  204. $modified = false;
  205. if ( $kshow->getRank() != $this->getRank() )
  206. {
  207. $kshow->setRank( $this->getRank() );
  208. $modified = true;
  209. }
  210. if ( $kshow->getLengthInMsecs() != $this->getLengthInMsecs() )
  211. {
  212. $kshow->setLengthInMsecs ( $this->getLengthInMsecs() );
  213. $modified = true;
  214. }
  215. if ( $modified ) $kshow->save();
  216. }
  217. else
  218. {
  219. $this->log( "entry [" . $this->getId() . "] does not have a real kshow with id [" . $this->getKshowId() . "]", Propel::LOG_WARNING );
  220. }
  221. }
  222. myPartnerUtils::setPartnerIdForObj( $this );
  223. if ( $this->getType() != entryType::PLAYLIST )
  224. mySearchUtils::setDisplayInSearch( $this );
  225. mySearchUtils::setSearchTextDiscreteForEntry($this);
  226. // update the admin_tags per partner
  227. ktagword::updateAdminTags( $this );
  228. // same for puserId ...
  229. $this->getPuserId( true );
  230. // make sure this entry is saved before calling updateAllMetadataVersionsRelevantForEntry, since fixMetadata retrieves the entry from the DB
  231. // and checks its data path which was modified above.
  232. $res = parent::save( $con );
  233. if ($is_new)
  234. {
  235. // when retrieving the entry - ignore thr filter - when in partner has moderate_content =1 - the entry will have status=3 and will fail the retrieveByPk
  236. entryPeer::setUseCriteriaFilter(false);
  237. $obj = entryPeer::retrieveByPk($this->getId());
  238. $this->setIntId($obj->getIntId());
  239. entryPeer::setUseCriteriaFilter(true);
  240. }
  241. if ( $this->should_call_set_data_content )
  242. {
  243. // calling the funciton with null will cause it to use the $this->data_content
  244. $this->setDataContent( null );
  245. $res = parent::save( $con );
  246. }
  247. // the fix should be done whether the status is READY or ERROR_CONVERTING
  248. if ( $this->getStatus() == entryStatus::READY || $this->getStatus() == entryStatus::ERROR_CONVERTING )
  249. {
  250. // fire some stuff due to the new status
  251. $version_to_update = $this->getUpdateWhenReady();
  252. if ( $version_to_update )
  253. {
  254. try{
  255. myMetadataUtils::updateAllMetadataVersionsRelevantForEntry ( $this);
  256. $this->resetUpdateWhenReady();
  257. $res = parent::save( $con );
  258. }
  259. catch(Exception $e)
  260. {
  261. KalturaLog::err($e->getMessage());
  262. }
  263. }
  264. }
  265. $this->syncCategories();
  266. return $res;
  267. }
  268. // TODO - PERFORMANCE DB - move to use cache !!
  269. // will increment the views by 1
  270. public function incViews ( $should_save = true )
  271. {
  272. myStatisticsMgr::incEntryViews( $this );
  273. }
  274. private function statusChangedTo ( $new_status )
  275. {
  276. return ( $this->previous_status != $new_status &&
  277. $this->getStatus() == $new_status );
  278. }
  279. public function setStatus ( $v)
  280. {
  281. // if we haven't yet set the previous status - remember it now
  282. if ( is_null ( $this->previous_status ) )
  283. $this->previous_status = $this->getStatus();
  284. parent::setStatus( $v );
  285. }
  286. /**
  287. * will handle the flow in case of need to moderate.
  288. */
  289. public function setStatusReady ( $force = false )
  290. {
  291. $this->setStatus( entryStatus::READY );
  292. $this->setDefaultModerationStatus();
  293. return $this->getStatus();
  294. }
  295. public function setDefaultModerationStatus()
  296. {
  297. $should_moderate = false;
  298. // in this case no configuration really matters
  299. if ( $this->getModerate() )
  300. {
  301. $should_moderate = true;
  302. }
  303. else
  304. {
  305. $should_moderate = myPartnerUtils::shouldModerate( $this->getPartnerId(), $this);
  306. }
  307. if( $should_moderate )
  308. {
  309. if ( ! $this->getId() )
  310. $this->save(); // save to DB so we'll have the id for the moderation list
  311. $this->setModerationStatus( self::ENTRY_MODERATION_STATUS_PENDING_MODERATION );
  312. if ( !$this->m_added_moderation )
  313. {
  314. myModerationMgr::addToModerationList( $this );
  315. $this->m_added_moderation = true;
  316. }
  317. }
  318. else
  319. {
  320. $this->setModerationStatus( self::ENTRY_MODERATION_STATUS_AUTO_APPROVED );
  321. }
  322. }
  323. public function isReady()
  324. {
  325. return ( $this->getStatus() == entryStatus::READY ) ;
  326. }
  327. public function getNormalizedRank ()
  328. {
  329. $res = round($this->rank / 1000);
  330. if ( $res > self::MAX_NORMALIZED_RANK ) return self::MAX_NORMALIZED_RANK;
  331. return $res;
  332. }
  333. /*
  334. * return an array of tuples of the file's version: [name, size, time, version]
  335. */
  336. public function getAllVersions ()
  337. {
  338. $current_version = $this->getData();
  339. $c = strstr($current_version, '^') ? '^' : '&';
  340. $parts = explode($c, $current_version);
  341. if (count($parts) == 2 && strlen($parts[1]))
  342. {
  343. return null;
  344. }
  345. // create an array to hold versions list
  346. $results = array();
  347. for ($version = 100000; $version <= $current_version; $version++ )
  348. {
  349. $version_sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version);
  350. $local_file_sync = kFileSyncUtils::getLocalFileSyncForKey($version_sync_key, false);
  351. if ($local_file_sync)
  352. {
  353. $result = array();
  354. // first - file name (with the full path)
  355. $result[] = $local_file_sync->getFilePath();
  356. // second - size
  357. $result[] = $local_file_sync->getFileSize();
  358. // third - time
  359. $result[] = filemtime ( $local_file_sync->getFullPath());
  360. // forth - version
  361. $result[] = substr( kFile::getFileNameNoExtension ( $local_file_sync->getFilePath() ) , strlen ($this->getId().'_') );
  362. $results[] = $result;
  363. }
  364. }
  365. return $results;
  366. }
  367. public function getAllVersionsFormatted()
  368. {
  369. $res = $this->getAllVersions();
  370. $formatted = array ();
  371. if ( ! is_array ( $res ) ) return null;
  372. foreach ( $res as $version_info )
  373. {
  374. $formatted []= array (
  375. "version" => $version_info[3] ,
  376. "rawData" => $version_info[2] ,
  377. "date" => strftime( "%d/%m/%y %H:%M:%S" , $version_info[2] ) );
  378. }
  379. return $formatted;
  380. }
  381. public function getLastVersion()
  382. {
  383. $version = kFile::getFileNameNoExtension ( $this->getData() );
  384. return $version;
  385. }
  386. public function getFormattedLengthInMsecs ()
  387. {
  388. return dateUtils::formatDuration ( $this->getLengthInMsecs() );
  389. }
  390. /**
  391. * (non-PHPdoc)
  392. * @see lib/model/ISyncableFile#getSyncKey()
  393. */
  394. public function getSyncKey ( $sub_type , $version = null )
  395. {
  396. self::validateFileSyncSubType ( $sub_type );
  397. $key = new FileSyncKey();
  398. $key->object_type = FileSyncObjectType::ENTRY;
  399. // // remarked by Tan-Tan 13/01/2010
  400. // if($sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB && $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE)
  401. // {
  402. // $key->object_sub_type = self::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
  403. // }
  404. // else
  405. // {
  406. $key->object_sub_type = $sub_type;
  407. // }
  408. $key->object_id = $this->getId();
  409. $key->version = $this->getVersionForSubType ( $sub_type, $version );
  410. $key->partner_id = $this->getPartnerId();
  411. return $key;
  412. }
  413. /**
  414. * @return string
  415. */
  416. public function generateBaseFileName( $sub_type, $version = null)
  417. {
  418. if(is_null($version))
  419. $version = $this->getVersion();
  420. // TODO - remove after Akamai bug fixed and create the file names with sub type
  421. if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM)
  422. return "_{$version}";
  423. if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC)
  424. return "_{$version}";
  425. // remove till here
  426. return "{$sub_type}_{$version}";
  427. }
  428. /* (non-PHPdoc)
  429. * @see lib/model/ISyncableFile#generateFileName()
  430. */
  431. public function generateFileName( $sub_type, $version = null)
  432. {
  433. if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM)
  434. return $this->getId() . '_' . $this->generateBaseFileName(0, $version) . '.ism';
  435. if($sub_type == entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC)
  436. return $this->getId() . '_' . $this->generateBaseFileName(0, $version) . '.ismc';
  437. return $this->getId() . '_' . $this->generateBaseFileName($sub_type, $version);
  438. }
  439. /**
  440. * (non-PHPdoc)
  441. * @see lib/model/ISyncableFile#generateFilePathArr()
  442. */
  443. public function generateFilePathArr( $sub_type, $version = null)
  444. {
  445. self::validateFileSyncSubType ( $sub_type );
  446. if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA )
  447. {
  448. $data = $this->getData();
  449. if($this->getType() == entryType::MIX && (!$this->getData() || !strpos($this->getData(), 'xml')))
  450. {
  451. $data .= ".xml";
  452. }
  453. $res = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $data, $version);
  454. // $res = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version);
  455. }
  456. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT )
  457. {
  458. $res = myContentStorage::getFileNameEdit( myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version) );
  459. }
  460. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB )
  461. {
  462. $res = myContentStorage::getGeneralEntityPath("entry/bigthumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version);
  463. }
  464. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE )
  465. {
  466. $res = null;
  467. $data_path = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData(), $version);
  468. // assume the suffix is not the same as the one on the data
  469. $archive_path = dirname ( str_replace ( "content/entry/" , "archive/" , $data_path ) ) . "/" . $this->getId();
  470. if ($this->getArchiveExtension())
  471. {
  472. $res = $archive_path . "." . $this->getArchiveExtension();
  473. }
  474. else
  475. {
  476. $archive_pattern = $archive_path . ".*" ;
  477. $arc_files = glob ( myContentStorage::getFSContentRootPath( ) . $archive_pattern );
  478. foreach ( $arc_files as $full_path_name )
  479. {
  480. // return the first file found
  481. $res = $full_path_name;
  482. break;
  483. }
  484. if ( ! $res )
  485. $res = $archive_pattern;
  486. }
  487. }
  488. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
  489. {
  490. // in this case the $version is used as the format
  491. $basename = kFile::getFileNameNoExtension ( $this->getData() );
  492. $path = myContentStorage::getGeneralEntityPath("entry/download", $this->getIntId(), $this->getId(), $basename);
  493. $download_path = $path.".$version";
  494. $res = $download_path;
  495. }
  496. else
  497. {
  498. $path = "entry/data";
  499. switch($sub_type)
  500. {
  501. case self::FILE_SYNC_ENTRY_SUB_TYPE_ISM:
  502. $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
  503. $basename .= '.ism';
  504. break;
  505. case self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC:
  506. $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
  507. $basename .= '.ismc';
  508. break;
  509. case self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG:
  510. $basename = $this->generateBaseFileName(0, $this->getIsmVersion());
  511. $basename .= '.log';
  512. break;
  513. }
  514. $res = myContentStorage::getGeneralEntityPath($path, $this->getIntId(), $this->getId(), $basename);
  515. }
  516. return array ( myContentStorage::getFSContentRootPath( ) , $res );
  517. }
  518. private function getVersionForSubType ( $sub_type, $version = null )
  519. {
  520. if (
  521. $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ISM
  522. ||
  523. $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC
  524. ||
  525. $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG
  526. )
  527. {
  528. if(!is_null($version))
  529. return $version;
  530. return $this->getIsmVersion();
  531. }
  532. $new_version = "";
  533. if ( $version )
  534. {
  535. if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
  536. {
  537. // MUST have A VERSION !
  538. $new_version = $this->getVersion() . "." . $version;
  539. }
  540. else
  541. {
  542. $new_version = $version;
  543. }
  544. }
  545. else
  546. {
  547. if ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA || $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT )
  548. $new_version = $this->getVersion();
  549. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB )
  550. $new_version = $this->getThumbnailVersion();
  551. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE )
  552. $new_version = "";
  553. elseif ( $sub_type == self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD )
  554. {
  555. // MUST have A VERSION !
  556. $new_version = $this->getVersion();
  557. }
  558. }
  559. return $new_version;
  560. }
  561. /**
  562. * Enter description here...
  563. *
  564. * @var FileSync
  565. */
  566. private $m_file_sync;
  567. /**
  568. * @return FileSync
  569. */
  570. public function getFileSync ( )
  571. {
  572. return $this->m_file_sync;
  573. }
  574. public function setFileSync ( FileSync $file_sync )
  575. {
  576. $this->m_file_sync = $file_sync;
  577. }
  578. private static function validateFileSyncSubType ( $sub_type )
  579. {
  580. if ( $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DATA &&
  581. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT &&
  582. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB &&
  583. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE &&
  584. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD &&
  585. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ISM &&
  586. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC &&
  587. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG &&
  588. $sub_type != self::FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB
  589. )
  590. throw new FileSyncException ( FileSyncObjectType::ENTRY ,
  591. $sub_type , array (
  592. self::FILE_SYNC_ENTRY_SUB_TYPE_DATA ,
  593. self::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT,
  594. self::FILE_SYNC_ENTRY_SUB_TYPE_THUMB ,
  595. self::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE ,
  596. self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD ,
  597. self::FILE_SYNC_ENTRY_SUB_TYPE_ISM ,
  598. self::FILE_SYNC_ENTRY_SUB_TYPE_ISMC ,
  599. self::FILE_SYNC_ENTRY_SUB_TYPE_CONVERSION_LOG ,
  600. self::FILE_SYNC_ENTRY_SUB_TYPE_OFFLINE_THUMB ,
  601. ) );
  602. }
  603. // return the full path on the disk
  604. public function getFullDataPath( $version = NULL )
  605. {
  606. $path = myContentStorage::getFSContentRootPath() . $this->getDataPath();
  607. if ( file_exists( $path )) return $path;
  608. return $path;
  609. }
  610. /**
  611. * This function returns the file system path for a requested content entity.
  612. * @return string the content path
  613. */
  614. public function getDataPath( $version = NULL )
  615. {
  616. if ( $version == NULL || $version == -1 )
  617. {
  618. return myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $this->getData());
  619. }
  620. else
  621. {
  622. $ext = pathinfo ($this->getData(), PATHINFO_EXTENSION);
  623. $file_version = myContentStorage::getGeneralEntityPath("entry/data", $this->getIntId(), $this->getId(), $version);
  624. return $file_version . "." . $ext;
  625. }
  626. }
  627. public function getDataUrl( $version = NULL )
  628. {
  629. if( $this->getType() == entryType::PLAYLIST )
  630. {
  631. return myPlaylistUtils::getExecutionUrl( $this );
  632. }
  633. //$path = $this->getThumbnailPath ( $version );
  634. $path = myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/flvclipper/entry_id/" . $this->getId() ;
  635. $current_version = $this->getVersion();
  636. if ( $version )
  637. $path .= "/version/$version";
  638. else
  639. $path .= "/version/$current_version";
  640. $url = myPartnerUtils::getCdnHost($this->getPartnerId()) . $path ;
  641. return $url;
  642. }
  643. /**
  644. * This function sets and returns a new path for a requested content entity.
  645. * @param string $filename = the original fileName from which the extension is cut.
  646. * @return string the content file name
  647. */
  648. public function setData($filename , $force = false )
  649. {
  650. if ( $force )
  651. $data = $filename;
  652. else
  653. $data = myContentStorage::generateRandomFileName($filename, $this->getData());
  654. Baseentry::setData( $data );
  655. return $this->getData();
  656. }
  657. /**
  658. *
  659. * @param $version
  660. * @param $format
  661. * @return FileSync
  662. */
  663. public function getDownloadFileSyncAndLocal ( $version = NULL , $format = null , $sub_type = null )
  664. {
  665. $sync_key = null;
  666. if ( $this->getType() == entryType::MEDIA_CLIP)
  667. {
  668. if ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_VIDEO || $this->getMediaType() == self::ENTRY_MEDIA_TYPE_AUDIO)
  669. {
  670. $flavor_assets = assetPeer::retrieveBestPlayByEntryId($this->getId()); // uset the format as the extension
  671. if($flavor_assets)
  672. $sync_key = $flavor_assets->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
  673. }
  674. elseif ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE )
  675. {
  676. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
  677. }
  678. }
  679. elseif ( $this->getType() == entryType::MIX )
  680. {
  681. // if roughcut - the version should be used
  682. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD , $version );
  683. }
  684. else
  685. {
  686. // if not roughcut - the format should be used
  687. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD , $format );
  688. }
  689. if(!$sync_key)
  690. return null;
  691. return kFileSyncUtils::getReadyFileSyncForKey ( $sync_key , true , false );
  692. }
  693. // return the file
  694. public function getDownloadPath( $version = NULL , $format = null , $sub_type = null )
  695. {
  696. // fetch the path (from remote if no local)
  697. list ( $file_sync , $local ) = $this->getDownloadFileSyncAndLocal( $version , $format , $sub_type );
  698. if ( ! $file_sync )
  699. return null;
  700. return $file_sync->getFullPath();
  701. }
  702. public function getDownloadSize( $version = NULL )
  703. {
  704. // fetch the path (from remote if no local)
  705. list ( $file_sync , $local ) = $this->getDownloadFileSyncAndLocal( $version , null );
  706. if ( ! $file_sync )
  707. return 0;
  708. return $file_sync->getFileSize();
  709. }
  710. public function getDownloadUrl( $version = NULL )
  711. {
  712. // always return the URL for the download - there is enough logic there to fix problems return the correct version/flavor
  713. return myPartnerUtils::getCdnHost($this->getPartnerId()). myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/raw/entry_id/" . $this->getId() . "/version/" . $this->getVersion();
  714. }
  715. public function getDownloadPathForFormat ( $version = NULL , $format )
  716. {
  717. // used by ppt-convert flow (downloadPath in addDownload response)
  718. // and perhaps by other clients as name
  719. $download_path = $this->getDownloadPath( $version , $format , self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD );
  720. if($download_path)
  721. return $download_path;
  722. // if did not return anything, probably due to missing fileSync
  723. // missing fileSync - if conversion was not done yet
  724. $key = $this->getSyncKey(self::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $format);
  725. return kFileSyncUtils::getLocalFilePathForKey($key);
  726. }
  727. /*
  728. * deprecated - was called from myBatchDownloadVideoServer which is no longer used
  729. // given the path of the converted file (not an FLV file) - create its URL
  730. public function getConvertedDownoadUrl ( $file_real_path )
  731. {
  732. $path = str_replace ( myContentStorage::getFSContentRootPath() , "" , $file_real_path );
  733. $path = str_replace ( "\\" , "" , $path );
  734. return myPartnerUtils::getCdnHost($this->getPartnerId()). myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . $path;
  735. }
  736. */
  737. public function setDesiredVersion ( $v )
  738. {
  739. $this->desired_version = $v;
  740. }
  741. public function getDesiredVersion ( )
  742. {
  743. return $this->desired_version ;
  744. }
  745. public function setArchiveExtension($v)
  746. {
  747. $this->archive_extension = $v;
  748. }
  749. public function getArchiveExtension()
  750. {
  751. return $this->archive_extension;
  752. }
  753. // will work only for types that the data can be served as an a response to the service
  754. public function getDataContent ( $from_cache = false )
  755. {
  756. if ( $this->getType() == entryType::MIX ||
  757. $this->getType() == entryType::DATA ||
  758. $this->getType() == entryType::PLAYLIST ||
  759. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML ||
  760. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
  761. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
  762. {
  763. if ( $from_cache ) return $this->data_content;
  764. $content_path = myContentStorage::getFSContentRootPath();
  765. $version = $this->desired_version;
  766. if ( ! $version || $version == -1 ) $version = null;
  767. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
  768. $content = kFileSyncUtils::file_get_contents( $sync_key , true , false ); // don't be strict when fetching this content
  769. if ( $content )
  770. {
  771. // patch for fixing old AE roughcuts without cross="0"
  772. if ($this->getType() == entryType::MIX)
  773. {
  774. $data2 = str_replace('<EndTransition type', '<EndTransition cross="0" type', $content);
  775. return $data2;
  776. }
  777. return $content;
  778. }
  779. }
  780. return null;
  781. }
  782. // will work only for types that the data can be served as an a response to the service
  783. public function setDataContent ( $v , $increment_version = true , $allow_type_roughcut = false )
  784. {
  785. // if ( $v === null ) return ;
  786. // DON'T do this for ENTRY_TYPE_SHOW unless $allow_type_roughcut is true
  787. // - the metadata is handling is complex and is done in other places in the code
  788. if ( ($allow_type_roughcut && $this->getType() == entryType::MIX) ||
  789. $this->getType() == entryType::DATA ||
  790. $this->getType() == entryType::PLAYLIST ||
  791. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML ||
  792. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_SHOW ||
  793. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
  794. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
  795. {
  796. if ( $this->getId() == null )
  797. {
  798. // come back when there is an ID
  799. $this->data_content = $v;
  800. $this->should_call_set_data_content = true;
  801. return ;
  802. }
  803. // if increment_version is false - don't be strict
  804. $strict = false;
  805. if ( ! $increment_version || $v == $this->data_content )
  806. {
  807. // attempting to update the same value
  808. $strict = false ;
  809. }
  810. if ( $v == null ) $v = $this->data_content;
  811. else $this->data_content = $v; // store it so it can be used with getDataContent(true) is called
  812. if ( $v !== null )
  813. {
  814. // increment the version
  815. if ( $increment_version ) $this->setData ( parent::getData() . $this->getFileSuffix() ) ;
  816. $this->should_call_set_data_content = false;
  817. $this->save();
  818. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA );
  819. kFileSyncUtils::file_put_contents( $sync_key , $v , $strict );
  820. }
  821. }
  822. }
  823. // return the default file suffix according to the entry type
  824. private function getFileSuffix ( )
  825. {
  826. if ( $this->getType() == entryType::MIX ||
  827. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_SHOW ||
  828. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_XML )
  829. {
  830. return ".xml";
  831. }
  832. elseif ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_TEXT ||
  833. $this->getMediaType() == self::ENTRY_MEDIA_TYPE_GENERIC_1 )
  834. {
  835. return ".txt";
  836. }
  837. return "";
  838. }
  839. public function getThumbnail()
  840. {
  841. $thumbnail = parent::getThumbnail();
  842. if (!$thumbnail && $this->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)
  843. $thumbnail = "&audio_thumb.jpg";
  844. return $thumbnail;
  845. }
  846. /**
  847. * This function returns the file system path for a requested content entity.
  848. * @return string the content path
  849. */
  850. public function getThumbnailPath( $version = NULL )
  851. {
  852. return myContentStorage::getGeneralEntityPath("entry/thumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version );
  853. }
  854. public function getThumbnailUrl( $version = NULL )
  855. {
  856. if(PermissionPeer::isValidForPartner(PermissionName::FEATURE_DISABLE_KMC_DRILL_DOWN_THUMB_RESIZE, $this->getPartnerId()))
  857. {
  858. $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
  859. if($this->getType() == entryType::MEDIA_CLIP && $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE)
  860. $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB;
  861. $syncKey = $this->getSyncKey($subType);
  862. $fileSync = null;
  863. $serveRemote = false;
  864. $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
  865. switch($partner->getStorageServePriority())
  866. {
  867. case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY:
  868. $serveRemote = true;
  869. $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
  870. if(!$fileSync)
  871. return null;
  872. break;
  873. case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_FIRST:
  874. $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
  875. if($fileSync)
  876. $serveRemote = true;
  877. break;
  878. case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST:
  879. $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
  880. if($fileSync)
  881. break;
  882. $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
  883. if(!$fileSync)
  884. return null;
  885. $serveRemote = true;
  886. break;
  887. case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY:
  888. $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
  889. if(!$fileSync)
  890. return null;
  891. break;
  892. }
  893. if($serveRemote && $fileSync)
  894. return $fileSync->getExternalUrl();
  895. }
  896. //$path = $this->getThumbnailPath ( $version );
  897. $path = myPartnerUtils::getUrlForPartner( $this->getPartnerId() , $this->getSubpId() ) . "/thumbnail/entry_id/" . $this->getId() ;
  898. $current_version = $this->getThumbnailVersion();
  899. if ( $version )
  900. $path .= "/version/$version";
  901. else
  902. $path .= "/version/$current_version";
  903. $url = myPartnerUtils::getCdnHost($this->getPartnerId()) . $path ;
  904. return $url;
  905. }
  906. public function getBigThumbnailPath($revertToSmall = false , $version = NULL )
  907. {
  908. if ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE )
  909. {
  910. // we dont need to make a copy for the big thumbnail - we can use the image itself
  911. return $this->getDataPath();
  912. }
  913. $path = myContentStorage::getGeneralEntityPath("entry/bigthumbnail", $this->getIntId(), $this->getId(), $this->getThumbnail() , $version );
  914. if ($revertToSmall && !file_exists(myContentStorage::getFSContentRootPath().$path))
  915. $path = $this->getThumbnailPath();
  916. return $path;
  917. }
  918. public function getBigThumbnailUrl( $version = NULL )
  919. {
  920. $path = $this->getBigThumbnailPath ( $version );
  921. $url = requestUtils::getRequestHost() . $path ;
  922. return $url;
  923. }
  924. /**
  925. * This function sets and returns a new path for a requested content entity.
  926. * @param string $filename = the original fileName from which the extension is cut.
  927. * @return string the content file name
  928. */
  929. public function setThumbnail($filename , $force = false )
  930. {
  931. if ( $force )
  932. $data = $filename;
  933. else
  934. $data = myContentStorage::generateRandomFileName($filename, $this->getThumbnail());
  935. parent::setThumbnail($data);
  936. return $this->getThumbnail();
  937. }
  938. public function setTags($tags , $update_db = true )
  939. {
  940. if ($this->tags !== $tags) {
  941. $tags = ktagword::updateTags($this->tags, $tags , $update_db );
  942. parent::setTags( trim($tags));
  943. }
  944. }
  945. public function setAdminTags($tags)
  946. {
  947. if ( $tags === null ) return ;
  948. if ( $tags == "" || $this->getAdminTags() !== $tags ) {
  949. parent::setAdminTags(trim(ktagword::fixAdminTags( $tags)));
  950. }
  951. }
  952. /**
  953. * Set the categories (use only the most child categories)
  954. *
  955. * @param string $categories
  956. */
  957. public function setCategories($newCats)
  958. {
  959. $newCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $newCats);
  960. $this->trimCategories($newCats);
  961. if (count($newCats) > self::MAX_CATEGORIES_PER_ENTRY)
  962. throw new kCoreException("Max number of allowed entries per category was reached", kCoreException::MAX_CATEGORIES_PER_ENTRY);
  963. // remove duplicates
  964. $newCats = array_unique($newCats);
  965. // leave only the most child categories
  966. $mostChildCats = array();
  967. foreach($newCats as $currentCat)
  968. {
  969. $unsetI = false;
  970. $add = true;
  971. foreach($mostChildCats as $i => $mostChild)
  972. {
  973. if (strpos($currentCat, $mostChild.categoryPeer::CATEGORY_SEPARATOR) === 0)
  974. {
  975. $unsetI = $i;
  976. break;
  977. }
  978. if (strpos($mostChild, $currentCat.categoryPeer::CATEGORY_SEPARATOR) === 0)
  979. {
  980. $add = false;
  981. }
  982. }
  983. if ($unsetI !== false)
  984. unset($mostChildCats[$unsetI]);
  985. if ($add)
  986. $mostChildCats[] = $currentCat;
  987. }
  988. $this->old_categories = $this->categories;
  989. parent::setCategories(implode(",", $mostChildCats));
  990. $this->is_categories_modified = true;
  991. }
  992. public function renameCategory($oldFullName, $newFullName)
  993. {
  994. $categories = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
  995. foreach($categories as &$category)
  996. {
  997. $category = preg_replace("/^".$oldFullName."/", $newFullName, $category);
  998. }
  999. $this->categories = implode(self::ENTRY_CATEGORY_SEPARATOR, $categories);
  1000. $this->old_categories = $this->categories; // so the sync won't increment the count on categories
  1001. $this->modifiedColumns[] = entryPeer::CATEGORIES;
  1002. $this->is_categories_modified = true;
  1003. }
  1004. public function removeCategory($fullName)
  1005. {
  1006. $this->old_categories = $this->categories;
  1007. $categories = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
  1008. $newCategories = array();
  1009. foreach($categories as $category)
  1010. {
  1011. if (!preg_match("/^".$fullName."/", $category))
  1012. $newCategories[] = $category;
  1013. }
  1014. $this->categories = implode(self::ENTRY_CATEGORY_SEPARATOR, $newCategories);
  1015. $this->modifiedColumns[] = entryPeer::CATEGORIES;
  1016. $this->is_categories_modified = true;
  1017. }
  1018. private function trimCategories(&$categories)
  1019. {
  1020. $trimedCategories = array();
  1021. foreach($categories as &$cat)
  1022. {
  1023. $cat = trim($cat);
  1024. $catExploded = explode(categoryPeer::CATEGORY_SEPARATOR, $cat);
  1025. $fixedCat = array();
  1026. foreach($catExploded as $subCat)
  1027. {
  1028. if (strlen($subCat) > 0)
  1029. {
  1030. $fixedCat[] = $subCat;
  1031. }
  1032. }
  1033. $cat = implode($fixedCat, categoryPeer::CATEGORY_SEPARATOR);
  1034. if (strlen($cat) > 0)
  1035. $trimedCategories[] = $cat;
  1036. }
  1037. $categories = $trimedCategories;
  1038. }
  1039. public function getCreatedAtAsInt ()
  1040. {
  1041. return $this->getCreatedAt( null );
  1042. }
  1043. public function getUpdateAtAsInt ()
  1044. {
  1045. return $this->getUpdatedAt( null );
  1046. }
  1047. public function getFormattedCreatedAt( $format = dateUtils::KALTURA_FORMAT )
  1048. {
  1049. return dateUtils::formatKalturaDate( $this , 'getCreatedAt' , $format );
  1050. }
  1051. public function getFormattedUpdatedAt( $format = dateUtils::KALTURA_FORMAT )
  1052. {
  1053. return dateUtils::formatKalturaDate( $this , 'getUpdatedAt' , $format );
  1054. }
  1055. public function getAppearsIn ( )
  1056. {
  1057. if ( $this->appears_in == NULL )
  1058. {
  1059. if ( $this->getkshow() )
  1060. {
  1061. $this->setAppearsIn ( $this->getkshow()->getName() );
  1062. }
  1063. else
  1064. {
  1065. return ""; // strange - no kshow ! must be a dangling entry
  1066. }
  1067. }
  1068. return $this->appears_in;
  1069. }
  1070. public function setAppearsIn ( $name )
  1071. {
  1072. $this->appears_in = $name;
  1073. }
  1074. public function getWidgetImagePath()
  1075. {
  1076. return myContentStorage::getGeneralEntityPath("entry/widget", $this->getIntId(), $this->getId(), ".gif" );
  1077. }
  1078. // when calling duration - use seconds rather than msecs
  1079. public function getDuration ()
  1080. {
  1081. $t = $this->getLengthInMsecs();
  1082. if ( $t == null ) return 0;
  1083. return ( $t / 1000 );
  1084. }
  1085. /**
  1086. * returns the duration as int
  1087. * @return int
  1088. */
  1089. public function getDurationInt()
  1090. {
  1091. return (int)round($this->getDuration());
  1092. }
  1093. /**
  1094. * @return string
  1095. */
  1096. public function getDurationType()
  1097. {
  1098. return entryPeer::getDurationType($this->getDurationInt());
  1099. }
  1100. public function getMetadata( $version = null)
  1101. {
  1102. if ( $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW )
  1103. {
  1104. return null;
  1105. }
  1106. if ( $version <= 0 ) $version=null;
  1107. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
  1108. $content = kFileSyncUtils::file_get_contents( $sync_key , true , false ); // don't be strict when fetching metadata
  1109. if ( $content )
  1110. return $content;
  1111. else
  1112. return "<xml></xml>";
  1113. }
  1114. // will place the metadata in the entry (as long as it's of type show)
  1115. // TODO - maybe change this because entries can change their types - intro of type video can become a show !!
  1116. // by default will override the existing file - this will be starnge because there is not supposed to be a file with that name yet -
  1117. // all the indexes up to this point where smaller then this futurae one.
  1118. /**
  1119. Writes the content of the metadata to a new file.
  1120. Returns the number of bytes written to disk
  1121. */
  1122. // TODO - is this really what should be returned ??
  1123. public function setMetadata ( $kshow , $content , $override_existing=true , $total_duration = null , $specific_version = null )
  1124. {
  1125. if ( $this->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW )
  1126. {
  1127. return null;
  1128. }
  1129. // TODO - better to call this with slight modifications
  1130. //myMetadataUtils::setMetadata ($content, $kshow, $this , $override_existing );
  1131. if ( $specific_version == null )
  1132. {
  1133. // increment the counter of the file
  1134. $this->setData ( parent::getData() );
  1135. }
  1136. // check that the file of the desired version really exists
  1137. // $content_dir = myContentStorage::getFSContentRootPath();
  1138. // $file_name = $content_dir . $this->getDataPath( $specific_version ); // replaced__getDataPath
  1139. $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $specific_version );
  1140. if ( $override_existing || ! kFileSyncUtils::file_exists( $sync_key ,false ) )
  1141. {
  1142. $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration ( $content );
  1143. $this->setLengthInMsecs ( $duration * 1000 );
  1144. $total_duration = null;
  1145. $editor_type = null;
  1146. $version = myContentStorage::getVersion( kFileSyncUtils::getReadyLocalFilePathForKey ( $sync_key ) );
  1147. $fixed_content = myFlvStreamer::fixMetadata( $content , $version, $total_duration , $editor_type);
  1148. $this->setModifiedAt(time()); // update the modified_at date
  1149. $this->save();
  1150. $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
  1151. // TODO: here we assume we are UPDATING an exising version of the file - make sure all the following functions are tolerant.
  1152. kFileSyncUtils::file_put_contents( $sync_key , $fixed_content , false ); // replaced__setFileContent
  1153. // update the roughcut_entry table
  1154. if ( $kshow != null ) $kshow_id = $kshow->getId();
  1155. else $kshow_id = $this->getKshowId();
  1156. $all_entries_for_roughcut = myMetadataUtils::getAllEntries ( $fixed_content );
  1157. roughcutEntry::updateRoughcut( $this->getId() , $version , $kshow_id , $all_entries_for_roughcut );
  1158. return ;
  1159. }
  1160. else
  1161. {
  1162. // no need to save changes - why increment the count if failed ??
  1163. return -1;
  1164. }
  1165. }
  1166. public function fixMetadata ( $increment_version = true , $content = null , $total_duration = null , $specific_version = null )
  1167. {
  1168. // check that the file of the desired version really exists
  1169. $content_dir = myContentStorage::getFSContentRootPath();
  1170. if ( !$content ) $content = $this->getMetadata( $specific_version );
  1171. if ( $increment_version )
  1172. {
  1173. // increment the counter of the file
  1174. $this->setData ( parent::getData() );
  1175. }
  1176. $file_name = kFileSyncUtils::getLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $specific_version)); // replaced__getDataPath
  1177. $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration ( $content );
  1178. $this->setLengthInMsecs ( $duration * 1000 );
  1179. $total_duration = null;
  1180. $editor_type = null;
  1181. $version = myContentStorage::getVersion($file_name);
  1182. $fixed_content = myFlvStreamer::fixMetadata( $content , $version, $total_duration , $editor_type);
  1183. $this->save();
  1184. $sync_key = $this->getSyncKey ( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $version );
  1185. kFileSyncUtils::file_put_contents( $sync_key , $fixed_content , false ); // replaced__setFileContent
  1186. return $fixed_content;
  1187. }
  1188. public function getVersion()
  1189. {
  1190. $version = parent::getData();
  1191. if ($version)
  1192. {
  1193. $c = strstr($version, '^') ? '^' : '&';
  1194. $parts = explode( $c, $version);
  1195. }
  1196. else
  1197. $parts = array('');
  1198. if (strlen($parts[0]))
  1199. $current_version = pathinfo($parts[0], PATHINFO_FILENAME) ;
  1200. else
  1201. $current_version = 0;
  1202. return $current_version;
  1203. }
  1204. public function getThumbnailVersion()
  1205. {
  1206. // For image entry, the data file sync sub type is used as thumbnail
  1207. if($this->getType() == entryType::MEDIA_CLIP && $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE)
  1208. return $this->getVersion();
  1209. $version = parent::getThumbnail();
  1210. if ($version)
  1211. {
  1212. $c = strstr($version, '^') ? '^' : '&';
  1213. $parts = explode( $c, $version);
  1214. }
  1215. else
  1216. $parts = array('');
  1217. if (strlen($parts[0]))
  1218. $current_version = pathinfo($parts[0], PATHINFO_FILENAME) ;
  1219. else
  1220. $current_version = 0;
  1221. return $current_version;
  1222. }
  1223. // makes a copy of the desired version from the past as the next coming version of the entry
  1224. // $desired_version = 100003, current_version = 100006 -> will conpy the content of <id>_100003.xxx -> <id>_1000007.xxx and will increment the version
  1225. // so current_version = 100007.xxx now
  1226. public function rollbackVersion( $desired_version )
  1227. {
  1228. // don't duplicate if staying in hte same version
  1229. $current_version = $this->getVersion();
  1230. if ( $desired_version == $current_version)
  1231. return $current_version;
  1232. $source_syc_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA , $desired_version );
  1233. /*
  1234. // check that the file of the desired version really exists
  1235. $content = myContentStorage::getFSContentRootPath();
  1236. $path = $content . $this->getDataPath( $desired_version ); // replaced__getDataPath
  1237. if ( ! file_exists( $path ))
  1238. {
  1239. return null;
  1240. }
  1241. */
  1242. // increment the counter of the file
  1243. $this->setData ( parent::getData() );
  1244. $target_syc_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA );
  1245. /*
  1246. $new_path = $content . $this->getDataPath( ); //replaced__getDataPath
  1247. // make a copy
  1248. kFile::moveFile( $path , $new_path , true , true );
  1249. */
  1250. kFileSyncUtils::copy( $source_syc_key , $target_syc_key );
  1251. $this->save();
  1252. // return the new version
  1253. return $this->getVersion();
  1254. }
  1255. // if has status self::ENTRY_S
  1256. public function getImportInfo ()
  1257. {
  1258. if ( $this->getStatus() == entryStatus::IMPORT )
  1259. {
  1260. $c = new Criteria();
  1261. $c->add ( BatchJobPeer::ENTRY_ID , $this->getId() );
  1262. $c->addDescendingOrderByColumn( BatchJobPeer::ID );
  1263. $import = BatchJobPeer::doSelectOne ( $c );
  1264. return $import;
  1265. }
  1266. return null;
  1267. }
  1268. public function getDisplayCredit ( )
  1269. {
  1270. if ($this->getCredit())
  1271. return $this->getCredit();
  1272. else if ( $this->getScreenName() )
  1273. {
  1274. return $this->getScreenName();
  1275. }
  1276. else
  1277. {
  1278. $kuser = $this->getkuser();
  1279. return ( $kuser ? $kuser->getScreenName() : "" );
  1280. }
  1281. }
  1282. public function moderate ($new_moderation_status , $fix_moderation_objects = false )
  1283. {
  1284. $error_msg = "Moderation status [$new_moderation_status] not supported by entry";
  1285. switch($new_moderation_status)
  1286. {
  1287. case moderation::MODERATION_STATUS_APPROVED:
  1288. // a new notification that is sent when an entry was founc to be ok after moderation
  1289. myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE , $this );
  1290. break;
  1291. case moderation::MODERATION_STATUS_BLOCK:
  1292. myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_BLOCK , $this->getid());
  1293. break;
  1294. case moderation::MODERATION_STATUS_DELETE:
  1295. // physical disk deletion
  1296. myEntryUtils::deleteEntry($this);
  1297. myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_BLOCK , $this->getid());
  1298. break;
  1299. case moderation::MODERATION_STATUS_PENDING:
  1300. // $this->setStatus(entryStatus::MODERATE);
  1301. // throw new Exception($error_msg);
  1302. break;
  1303. case moderation::MODERATION_STATUS_REVIEW:
  1304. // in this case the status of the entry should not change
  1305. // throw new Exception($error_msg);
  1306. break;
  1307. default:
  1308. throw new Exception($error_msg);
  1309. break;
  1310. }
  1311. $this->setModerationStatus( $new_moderation_status );
  1312. // TODO - fix loop of updating from entry ot moderation back to entry ...
  1313. if ( $fix_moderation_objects )
  1314. {
  1315. myModerationMgr::updateModerationsForObject ( $this , $new_moderation_status );
  1316. }
  1317. $this->save();
  1318. }
  1319. public function setEditorType ( $editor_type ) { $this->putInCustomData ( "editor_type" , $editor_type ); }
  1320. public function getEditorType ( )
  1321. {
  1322. if ( $this->getType() != entryType::MIX ) return null;
  1323. $res = $this->getFromCustomData( "editor_type" );
  1324. if ( $res == null ) return "Keditor"; // no value means Keditor == advanced
  1325. return $res;
  1326. }
  1327. public function setConversionProfileId($conversion_quality)
  1328. {
  1329. $this->setConversionQuality($conversion_quality);
  1330. }
  1331. public function setConversionQuality($conversion_quality)
  1332. {
  1333. parent::setConversionProfileId($conversion_quality);
  1334. $this->putInCustomData("conversion_quality", $conversion_quality);
  1335. }
  1336. public function getConversionQuality ( ){return $this->getFromCustomData( "conversion_quality" );}
  1337. public function setBulkUploadId ( $bulkUploadId ) { $this->putInCustomData ( "bulk_upload_id" , $bulkUploadId ); }
  1338. public function getBulkUploadId ( ) { return $this->getFromCustomData( "bulk_upload_id" ); }
  1339. public function setModerate ( $should_moderate ) { $this->putInCustomData ( "moderate" , $should_moderate ); }
  1340. public function getModerate ( ) { return $this->getFromCustomData( "moderate" ); }
  1341. public function resetUpdateWhenReady ( ) { $this->putInCustomData ( "current_kshow_version" , null ); }
  1342. public function setUpdateWhenReady ( $current_kshow_version ) { $this->putInCustomData ( "current_kshow_version" , $current_kshow_version ); }
  1343. public function getUpdateWhenReady ( ) { return $this->getFromCustomData( "current_kshow_version" ); }
  1344. // will be set if the entry has a real download path (
  1345. public function setHasDownload ( $v ) { $this->putInCustomData ( "hasDownload" , $v); }
  1346. public function getHasDownload ( ) { return $this->getFromCustomData( "hasDownload" ); }
  1347. public function setCount ( $v ) { $this->putInCustomData ( "count" , $v ); }
  1348. public function getCount ( ) { return $this->getFromCustomData( "count" ); }
  1349. public function setCountDate ( $v ) { $this->putInCustomData ( "count_date" , $v ); }
  1350. public function getCountDate ( ) { return $this->getFromCustomData( "count_date" ); }
  1351. public function setEncodingIP1 ( $v ) { $this->putInCustomData ( "encodingIP1" , $v ); }
  1352. public function getEncodingIP1 ( ) { return $this->getFromCustomData( "encodingIP1" ); }
  1353. public function setEncodingIP2 ( $v ) { $this->putInCustomData ( "encodingIP2" , $v ); }
  1354. public function getEncodingIP2 ( ) { return $this->getFromCustomData( "encodingIP2" ); }
  1355. public function setStreamUsername ( $v ) { $this->putInCustomData ( "streamUsername" , $v ); }
  1356. public function getStreamUsername ( ) { return $this->getFromCustomData( "streamUsername" ); }
  1357. public function setStreamPassword ( $v ) { $this->putInCustomData ( "streamPassword" , $v ); }
  1358. public function getStreamPassword ( ) { return $this->getFromCustomData( "streamPassword" ); }
  1359. public function setOfflineMessage ( $v ) { $this->putInCustomData ( "offlineMessage" , $v ); }
  1360. public function getOfflineMessage ( ) { return $this->getFromCustomData( "offlineMessage" ); }
  1361. public function setStreamRemoteId ( $v ) { $this->putInCustomData ( "streamRemoteId" , $v ); }
  1362. public function getStreamRemoteId ( ) { return $this->getFromCustomData( "streamRemoteId" ); }
  1363. public function setStreamRemoteBackupId ( $v ) { $this->putInCustomData ( "streamRemoteBackupId" , $v ); }
  1364. public function getStreamRemoteBackupId ( ) { return $this->getFromCustomData( "streamRemoteBackupId" ); }
  1365. public function setStreamUrl ( $v ) { $this->putInCustomData ( "streamUrl" , $v ); }
  1366. public function getStreamUrl ( ) { return $this->getFromCustomData( "streamUrl" ); }
  1367. public function setPrimaryBroadcastingUrl ( $v ) { $this->putInCustomData ( "primaryBroadcastingUrl" , $v ); }
  1368. public function getPrimaryBroadcastingUrl ( ) { return $this->getFromCustomData( "primaryBroadcastingUrl" ); }
  1369. public function setSecondaryBroadcastingUrl ( $v ) { $this->putInCustomData ( "secondaryBroadcastingUrl" , $v ); }
  1370. public function getSecondaryBroadcastingUrl ( ) { return $this->getFromCustomData( "secondaryBroadcastingUrl" ); }
  1371. public function setStreamName ( $v ) { $this->putInCustomData ( "streamName" , $v ); }
  1372. public function getStreamName ( ) { return $this->getFromCustomData( "streamName" ); }
  1373. public function setStreamBitrates (array $v ) { $this->putInCustomData ( "streamBitrates" , $v ); }
  1374. public function getStreamBitrates ( ) { return $this->getFromCustomData( "streamBitrates" ); }
  1375. public function setIsmVersion ( $v ) { $this->putInCustomData ( "ismVersion" , $v ); }
  1376. public function getIsmVersion ( ) { return (int) $this->getFromCustomData( "ismVersion" ); }
  1377. public function setReferenceID ( $v ) { $this->putInCustomData ( "referenceID" , $v ); }
  1378. public function getReferenceID ( ) { return $this->getFromCustomData( "referenceID" ); }
  1379. public function setPartnerSortValue ( $v ) { $this->putInCustomData ( "partnerSortValue" , $v ); }
  1380. public function getPartnerSortValue ( ) { return (int) $this->getFromCustomData( "partnerSortValue" ); }
  1381. public function setReplacementStatus ( $v ) { $this->putInCustomData ( "replacementStatus" , $v ); }
  1382. public function getReplacementStatus ( ) { return (int) $this->getFromCustomData( "replacementStatus" ); }
  1383. public function setReplacingEntryId ( $v ) { $this->putInCustomData ( "replacingEntryId" , $v ); }
  1384. public function getReplacingEntryId ( ) { return $this->getFromCustomData( "replacingEntryId" ); }
  1385. public function setReplacedEntryId ( $v ) { $this->putInCustomData ( "replacedEntryId" , $v ); }
  1386. public function getReplacedEntryId ( ) { return $this->getFromCustomData( "replacedEntryId" ); }
  1387. public function setCreateThumb ( $v ) { $this->putInCustomData ( "createThumb" , (bool) $v ); }
  1388. public function getCreateThumb ( ) { return (bool) $this->getFromCustomData( "createThumb" ,null, true ); }
  1389. public function setThumbBitrate ( $v ) { $this->putInCustomData ( "thumbBitrate" , $v ); }
  1390. public function getThumbBitrate ( ) { return $this->getFromCustomData( "thumbBitrate", null, 0 ); }
  1391. public function setThumbHeight ( $v ) { $this->putInCustomData ( "thumbHeight" , $v ); }
  1392. public function getThumbHeight ( ) { return $this->getFromCustomData( "thumbHeight", null, 0 ); }
  1393. public function setRootEntryId($v)
  1394. {
  1395. $this->putInCustomData("rootEntryId", $v);
  1396. }
  1397. public function getRoots()
  1398. {
  1399. // the prefix required becaue combined sphinx match is rrequired,
  1400. // only negative expression won't work such as '@roots -entry',
  1401. // the prefix will enable '@roots prefix -entry'
  1402. $ret = array(entry::ROOTS_FIELD_PREFIX);
  1403. if($this->getBulkUploadId())
  1404. $ret[] = entry::ROOTS_FIELD_BULK_UPLOAD_PREFIX . ' ' . $this->getBulkUploadId();
  1405. if($this->getRootEntryId() != $this->getId())
  1406. $ret[] = entry::ROOTS_FIELD_ENTRY_PREFIX . ' ' . $this->getRootEntryId();
  1407. return implode(',', $ret);
  1408. }
  1409. public function getRootEntryId($deep = false)
  1410. {
  1411. $rootEntryId = $this->getFromCustomData("rootEntryId", null, null);
  1412. if(is_null($rootEntryId))
  1413. return $this->getId();
  1414. if(!$deep)
  1415. return $rootEntryId;
  1416. $rootEntry = entryPeer::retrieveByPKNoFilter($rootEntryId);
  1417. if($rootEntry)
  1418. $rootEntryId = $rootEntry->getRootEntryId($deep);
  1419. return $rootEntryId;
  1420. }
  1421. public function setDynamicFlavorAttributes(array $v)
  1422. {
  1423. $this->putInCustomData("dynamicFlavorAttributes", serialize($v));
  1424. }
  1425. public function setOperationAttributes(array $operationAttributes)
  1426. {
  1427. $this->putInCustomData("operationAttributes", $operationAttributes);
  1428. }
  1429. public function getOperationAttributes()
  1430. {
  1431. return $this->getFromCustomData("operationAttributes", null, array());
  1432. }
  1433. public function getDynamicFlavorAttributes()
  1434. {
  1435. $value = $this->getFromCustomData("dynamicFlavorAttributes");
  1436. if(!$value)
  1437. return array();
  1438. try
  1439. {
  1440. $arr = unserialize($value);
  1441. if(!is_array($arr))
  1442. return array();
  1443. return $arr;
  1444. }
  1445. catch(Exception $e)
  1446. {
  1447. return array();
  1448. }
  1449. }
  1450. // privacySettyings is an alias for permissions
  1451. public function getPrivacySettings () { return $this->getPermissions(); }
  1452. public function setPrivacySettings ( $v ) { return $this->setPermissions( $v ); }
  1453. public function incrementIsmVersion ( )
  1454. {
  1455. $version = $this->getIsmVersion() + 1;
  1456. $this->setIsmVersion($version);
  1457. return $version;
  1458. }
  1459. public function getHeight()
  1460. {
  1461. // return null if media_type is NOT image OR video
  1462. if ( $this->getMediaType() != self::ENTRY_MEDIA_TYPE_IMAGE && $this->getMediaType() != self::ENTRY_MEDIA_TYPE_VIDEO ) return null;
  1463. return $this->getFromCustomData( "height" );
  1464. }
  1465. public function getWidth()
  1466. {
  1467. // return null if media_type is NOT image OR video
  1468. if ( $this->getMediaType() != self::ENTRY_MEDIA_TYPE_IMAGE && $this->getMediaType() != self::ENTRY_MEDIA_TYPE_VIDEO ) return null;
  1469. return $this->getFromCustomData( "width" );
  1470. }
  1471. public function getMediaTypeName()
  1472. {
  1473. $type = $this->getMediaType();
  1474. if(isset(self::$mediaTypeNames[$type]))
  1475. return self::$mediaTypeNames[$type];
  1476. return null;
  1477. }
  1478. public function setDimensions ( $width , $height )
  1479. {
  1480. $this->putInCustomData( "height" , $height );
  1481. $this->putInCustomData( "width" , $width );
  1482. }
  1483. public function updateDimensions ( )
  1484. {
  1485. if ( $this->getMediaType() == self::ENTRY_MEDIA_TYPE_IMAGE)
  1486. $this->updateImageDimensions();
  1487. else if ($this->getMediaType() == self::ENTRY_MEDIA_TYPE_VIDEO )
  1488. $this->updateVideoDimensions();
  1489. }
  1490. public function updateImageDimensions ( )
  1491. {
  1492. $dataPath = kFileSyncUtils::getReadyLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA));
  1493. list ( $width , $height ) = $arr = myFileConverter::getImageDimensions( $dataPath );
  1494. if ( $width )
  1495. {
  1496. $this->putInCustomData( "height" , $height );
  1497. $this->putInCustomData( "width" , $width );
  1498. }
  1499. return $arr;
  1500. }
  1501. public function updateVideoDimensions ( )
  1502. {
  1503. $syncKey = $this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
  1504. $dataPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
  1505. list ( $width , $height ) = $arr = myFileConverter::getVideoDimensions( $dataPath );
  1506. if ( $width )
  1507. {
  1508. $this->putInCustomData( "height" , $height );
  1509. $this->putInCustomData( "width" , $width );
  1510. }
  1511. return $arr;
  1512. }
  1513. public function getDisplayScope()
  1514. {
  1515. if( $this->getDisplayInSearch() == 0 ) return "";
  1516. if( $this->getDisplayInSearch() == 1 ) return "_PRIVATE_";
  1517. if( $this->getDisplayInSearch() >= 2 ) return "_KN_";
  1518. }
  1519. public function incModerationCount() { $this->setModerationCount( $this->getModerationCount() + 1 ); }
  1520. /**
  1521. * @return partner
  1522. */
  1523. public function getPartner() { return PartnerPeer::retrieveByPK( $this->getPartnerId() ); }
  1524. public function getSubpId()
  1525. {
  1526. return ($this->subp_id != null ? $this->subp_id : 0);
  1527. }
  1528. public function getPartnerLandingPage ()
  1529. {
  1530. if ( ! $this->getPartner() ) return null;
  1531. $url = $this->getPartner()->getLandingPage();
  1532. if ( $url )
  1533. {
  1534. if ( strpos ( $url , '{id}' ) > 0 )
  1535. {
  1536. return str_replace( '{id}' , $this->getId() , $url );
  1537. }
  1538. else
  1539. return $url . $this->getId();
  1540. // return objectWrapperBase::parseString ( $url , $this );//
  1541. }
  1542. else
  1543. {
  1544. return null;
  1545. }
  1546. }
  1547. public function getUserLandingPage ()
  1548. {
  1549. if ( ! $this->getPartner() ) return null;
  1550. $url = $this->getPartner()->getUserLandingPage();
  1551. if ( $url )
  1552. {
  1553. if ( strpos ( $url , '{uid}' ) > 0 )
  1554. {
  1555. return str_replace( '{uid}' , $this->getPuserId( true ) , $url );
  1556. }
  1557. else
  1558. return $url . $this->getPuserId( true );
  1559. // return objectWrapperBase::parseString ( $url , $this );//
  1560. }
  1561. else
  1562. {
  1563. return null;
  1564. }
  1565. }
  1566. public function getConversionProfile()
  1567. {
  1568. $conversion_profile = $this->getConversionQuality();
  1569. if ( $conversion_profile )
  1570. {
  1571. return ConversionProfilePeer::retrieveByPK( $conversion_profile );
  1572. }
  1573. return null;
  1574. }
  1575. public function getRankAsFloat()
  1576. {
  1577. return (float)($this->getRank() / 1000);
  1578. }
  1579. public function setSecurityPolicy ( $security_policy ) { $this->putInCustomData ( "security_policy" , $security_policy ); }
  1580. public function getSecurityPolicy ( ) { return $this->getFromCustomData( "security_policy" ); }
  1581. public function setStorageSize ( $storage_size ) { $this->putInCustomData ( "storage_size" , $storage_size ); }
  1582. public function getStorageSize ( ) { return $this->getFromCustomData( "storage_size" ); }
  1583. public function setExtStorageUrl( $v ) { $this->putInCustomData("ext_storage_url", $v); }
  1584. public function getExtStorageUrl() { return $this->getFromCustomData("ext_storage_url"); }
  1585. private $m_puser_id = null;
  1586. public function tempSetPuserId ( $puser_id )
  1587. {
  1588. $this->m_puser_id = $puser_id;
  1589. }
  1590. public function getPuserId( $real_puser_id = false )
  1591. {
  1592. if (defined("KALTURA_API_V3"))
  1593. return parent::getPuserId();
  1594. // HACK for FootBo
  1595. if ( !$real_puser_id && $this->getPartnerId() == 8304 )
  1596. {
  1597. return $this->getContributorScreenName();
  1598. }
  1599. $puser_id = $this->getFromCustomData( "puserId" );
  1600. if ( $this->m_puser_id ) // ! $puser_id )
  1601. {
  1602. return $this->m_puser_id;
  1603. }
  1604. else
  1605. {
  1606. if ( $this->getKuserId() )
  1607. {
  1608. $puser_id = PuserKuserPeer::getPuserIdFromKuserId ( $this->getPartnerId(), $this->getKuserId() );
  1609. $this->putInCustomData( "puserId" , $puser_id );
  1610. $this->m_puser_id = $puser_id;
  1611. }
  1612. }
  1613. return $puser_id;
  1614. }
  1615. public function getContributorScreenName()
  1616. {
  1617. // HACK fro FootBo
  1618. if ($this->getPartnerId() != 8304 && $this->getCredit())
  1619. return $this->getCredit();
  1620. else
  1621. {
  1622. return $this->getUserScreenName();
  1623. }
  1624. }
  1625. // will return the user's screen name - not the credit even if exists
  1626. public function getUserScreenName()
  1627. {
  1628. $kuser = $this->getkuser();
  1629. return ( $kuser ? $kuser->getScreenName() : "" );
  1630. }
  1631. // this will make sure that the extra data set in the search_text won't leak out
  1632. public function getSearchText() { return mySearchUtils::removePartner( parent::getSearchText() ); }
  1633. public function getSearchTextRaw() { return parent::getSearchText(); }
  1634. /*
  1635. public function dumpContent()
  1636. {
  1637. // $dataPath = myContentStorage::getFSContentRootPath() . $this->getDataPath(); // replaced__getDataPath
  1638. // kFile::dumpFile($dataPath);
  1639. $sync_key = $this->getSyncKey( self::FILE_SYNC_ENTRY_SUB_TYPE_DATA );
  1640. }
  1641. */
  1642. public function getTypeAsString()
  1643. {
  1644. $t = $this->getMediaType();
  1645. if ( $t == self::ENTRY_MEDIA_TYPE_AUDIO ) return "audio";
  1646. if ( $t == self::ENTRY_MEDIA_TYPE_VIDEO ) return "video";
  1647. if ( $t == self::ENTRY_MEDIA_TYPE_IMAGE ) return "image";
  1648. if ( $t == self::ENTRY_MEDIA_TYPE_SHOW ) return "roughcut";
  1649. return "";
  1650. }
  1651. public function getFileSize()
  1652. {
  1653. return 0; // temp fix
  1654. $dataFileKey = $this->getSyncKey(self::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
  1655. $fileSync = kFileSyncUtils::getLocalFileSyncForKey($dataFileKey);
  1656. if($fileSync && $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_READY) return $fileSync->getFileSize();
  1657. return "";
  1658. }
  1659. // -- retrieveDataContentByGet --
  1660. // disable/enable sending data content for data entries in API v3 (for binary-data-entry use-case)
  1661. public function setRetrieveDataContentByGet( $v ) { $this->putInCustomData("retrieveDataContentByGet", $v); }
  1662. public function getRetrieveDataContentByGet() { return $this->getFromCustomData("retrieveDataContentByGet", "", 1); }
  1663. // ------------------------------------------------------------
  1664. // setters & gettes for entry when callnig addentry
  1665. private $m_url;
  1666. public function getUrl() { return $this->m_url; }
  1667. public function setUrl ( $v ) { $this->m_url = $v ;}
  1668. private $m_thumb_url;
  1669. public function getThumbUrl() { return $this->m_thumb_url; }
  1670. public function setThumbUrl ( $v ) { $this->m_thumb_url = $v ;}
  1671. private $m_filename;
  1672. public function getFilename() { return $this->m_filename; }
  1673. public function setFilename ( $v ) { $this->m_filename= $v ;}
  1674. private $m_realFilename;
  1675. public function getRealFilename() { return $this->m_realFilename; }
  1676. public function setRealFilename ( $v ) { $this->m_realFilename= $v ;}
  1677. private $m_mediaId;
  1678. public function getMediaId() { return $this->m_mediaId; }
  1679. public function setMediaId ( $v ) { $this->m_mediaId= $v ;}
  1680. // ------------------------------------------------------------
  1681. private $m_thumbOffset;
  1682. public function getThumbOffset($default_offset = 3)
  1683. {
  1684. $offset = $this->getFromCustomData ( "thumb_offset" );
  1685. if(is_null($offset))
  1686. {
  1687. // get from partner if null on entry:
  1688. $partner = $this->getPartner();
  1689. $offset = $partner ? $partner->getDefThumbOffset() : $default_offset;
  1690. if(is_null($offset) || $offset === false)
  1691. return $default_offset;
  1692. }
  1693. return $offset;
  1694. }
  1695. public function setThumbOffset ( $v ) { $this->putInCustomData ( "thumb_offset" , $v ); }
  1696. public function getBestThumbOffset( $default_offset = 3 )
  1697. {
  1698. if ($default_offset === null)
  1699. $default_offset = 3;
  1700. $offset = $this->getThumbOffset();
  1701. $duration = $this->getLengthInMsecs();
  1702. if(!$offset || $offset < 0)
  1703. $offset = $default_offset;
  1704. return max(0 ,min($offset, $duration));
  1705. }
  1706. public function getHasRealThumb()
  1707. {
  1708. $thumb = $this->getThumbnail();
  1709. return myContentStorage::isTemplate( $thumb );
  1710. }
  1711. public function setKuserId($v)
  1712. {
  1713. // if we set the kuserId when not needed - this causes the kuser object to be reset (even if the joinKuser was done properly)
  1714. if ( self::getKuserId() == $v ) // same value - don't set for nothing
  1715. return;
  1716. parent::setKuserId($v);
  1717. $kuser = $this->getKuser();
  1718. if ($kuser)
  1719. $this->setPuserId($kuser->getPuserId());
  1720. }
  1721. public function syncCategories()
  1722. {
  1723. if (!$this->is_categories_modified)
  1724. return;
  1725. if ($this->categories != null && $this->categories !== "")
  1726. $newCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
  1727. else
  1728. $newCats = array();
  1729. if ($this->old_categories !== null && $this->old_categories !== "")
  1730. $oldCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->old_categories);
  1731. else
  1732. $oldCats = array();
  1733. $allIds = array();
  1734. $allIdsWithParents = array ();
  1735. $addedCats = array();
  1736. $removedCats = array();
  1737. $remainingCats = array();
  1738. foreach ( $oldCats as $cat )
  1739. {
  1740. if (array_search ( $cat, $newCats ) === false)
  1741. $removedCats [] = $cat;
  1742. }
  1743. foreach ( $newCats as $cat )
  1744. {
  1745. if (array_search ( $cat, $oldCats ) === false)
  1746. $addedCats [] = $cat;
  1747. else
  1748. $remainingCats [] = $cat;
  1749. }
  1750. foreach ( $remainingCats as $cat )
  1751. {
  1752. $category = categoryPeer::getByFullNameExactMatch ( $cat );
  1753. if ($category)
  1754. {
  1755. $allIds [] = $category->getId ();
  1756. $allIdsWithParents [] = $category->getId ();
  1757. $allIdsWithParents = array_merge ( $allIdsWithParents, $category->getAllParentsIds () );
  1758. }
  1759. }
  1760. $alreadyAddedCatIds = $allIdsWithParents;
  1761. foreach ( $addedCats as $cat )
  1762. {
  1763. $category = categoryPeer::getByFullNameExactMatch ( $cat );
  1764. if (! $category)
  1765. $category = category::createByPartnerAndFullName ( $this->getPartnerId (), $cat );
  1766. $category->incrementEntriesCount ( 1, $alreadyAddedCatIds );
  1767. $allIds [] = $category->getId ();
  1768. $alreadyAddedCatIds [] = $category->getId ();
  1769. $alreadyAddedCatIds = array_merge ( $alreadyAddedCatIds, $category->getAllParentsIds () );
  1770. }
  1771. $alreadyRemovedCatIds = $allIdsWithParents;
  1772. foreach ( $removedCats as $cat ) {
  1773. $category = categoryPeer::getByFullNameExactMatch ( $cat );
  1774. if ($category){
  1775. $category->decrementEntriesCount ( 1, $alreadyRemovedCatIds );
  1776. $alreadyRemovedCatIds [] = $category->getId ();
  1777. $alreadyRemovedCatIds = array_merge ( $alreadyRemovedCatIds, $category->getAllParentsIds () );
  1778. }
  1779. }
  1780. $this->setCategoriesIds ( implode ( ",", $allIds ) );
  1781. mySearchUtils::setSearchTextDiscreteForEntry ( $this );
  1782. parent::save ();
  1783. $this->is_categories_modified = false;
  1784. }
  1785. public function isScheduledNow()
  1786. {
  1787. $startDateCheck = (!$this->getStartDate() || $this->getStartDate(null) <= time());
  1788. $endDateCheck = (!$this->getEndDate() || $this->getEndDate(null) >= time());
  1789. return $startDateCheck && $endDateCheck;
  1790. }
  1791. /**
  1792. * Force modifiedColumns to be affected even if the value not changed
  1793. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  1794. * be treated as NULL for temporal objects.
  1795. * @return entry The current object (for fluent API support)
  1796. * @see Baseentry::setUpdatedAt()
  1797. */
  1798. public function setUpdatedAt($v)
  1799. {
  1800. parent::setUpdatedAt($v);
  1801. if(!in_array(entryPeer::UPDATED_AT, $this->modifiedColumns, false))
  1802. $this->modifiedColumns[] = entryPeer::UPDATED_AT;
  1803. return $this;
  1804. }
  1805. /* (non-PHPdoc)
  1806. * @see Baseentry::setAccessControlId()
  1807. */
  1808. public function setAccessControlId($v)
  1809. {
  1810. if ($v === 0 || $v === -1) // handle 0 and -1 as null
  1811. $v = null;
  1812. parent::setAccessControlId($v);
  1813. }
  1814. public function addFlavorParamsId($v)
  1815. {
  1816. $flavorParamIds = $this->getFlavorParamsIds();
  1817. if (strlen($flavorParamIds) > 0)
  1818. $flavorParamIdsArray = explode(",", $flavorParamIds);
  1819. else
  1820. $flavorParamIdsArray = array();
  1821. $flavorParamIdsArray = array_unique($flavorParamIdsArray);
  1822. $flavorParamIdsArray[] = $v;
  1823. $flavorParamIds = implode(",", $flavorParamIdsArray);
  1824. $this->setFlavorParamsIds($flavorParamIds);
  1825. }
  1826. public function removeFlavorParamsId($v)
  1827. {
  1828. // get the ids
  1829. $flavorParamIds = $this->getFlavorParamsIds();
  1830. // if empty, no need to remove
  1831. if(!strlen($flavorParamIds))
  1832. return;
  1833. // build array with the ids as keys
  1834. $arrFlavorParamIds = array_flip(explode(',', $flavorParamIds));
  1835. // if not in array, no need to remove
  1836. if(!isset($arrFlavorParamIds[$v]))
  1837. return;
  1838. // remove from array
  1839. unset($arrFlavorParamIds[$v]);
  1840. // save imploded string of the array keys (ids)
  1841. $this->setFlavorParamsIds(implode(',', array_keys($arrFlavorParamIds)));
  1842. }
  1843. public function getRawDownloadUrl()
  1844. {
  1845. $finalPath = "/downloadUrl?url=".
  1846. myPartnerUtils::getUrlForPartner($this->getPartnerId(), $this->getSubpId()).
  1847. "/raw/entry_id/".
  1848. $this->getId();
  1849. $downloadUrl = myPartnerUtils::getCdnHost($this->getPartnerId()).$finalPath;
  1850. return $downloadUrl;
  1851. }
  1852. public function setEndDate($date)
  1853. {
  1854. if (!is_null($date) && $date > 0)
  1855. {
  1856. parent::setEndDate($date);
  1857. }
  1858. else
  1859. {
  1860. parent::setEndDate(null);
  1861. }
  1862. }
  1863. public function setStartDate($date)
  1864. {
  1865. if (!is_null($date) && $date > 0)
  1866. {
  1867. parent::setStartDate($date);
  1868. parent::setAvailableFrom($date);
  1869. }
  1870. else // restore availableFrom from the createdAt
  1871. {
  1872. parent::setStartDate(null);
  1873. parent::setAvailableFrom(parent::getCreatedAt());
  1874. }
  1875. }
  1876. public function setCreatedAt($date)
  1877. {
  1878. parent::setCreatedAt($date);
  1879. if (is_null($this->getAvailableFrom())) // only if the availableFrom was not set yet
  1880. parent::setAvailableFrom($date);
  1881. }
  1882. // ----------- Extra object connections ----------------
  1883. public function getNotifications()
  1884. {
  1885. return notificationPeer::retrieveByEntryId( $this->getId() );
  1886. }
  1887. public function getBatchJobs()
  1888. {
  1889. return BatchJobPeer::retrieveByEntryId( $this->getId() );
  1890. }
  1891. public function getRoughcutId()
  1892. {
  1893. $kshow = $this->getKshow();
  1894. return $kshow ? $kshow->getShowEntryId() : null;
  1895. }
  1896. // get all related roughcuts where this entry appears
  1897. public function getRoughcuts()
  1898. {
  1899. return roughcutEntry::getAllRoughcuts( $this->getId() );
  1900. }
  1901. // ----------- Extra object connections ----------------
  1902. /* (non-PHPdoc)
  1903. * @see lib/model/om/Baseentry#postUpdate()
  1904. */
  1905. public function postUpdate(PropelPDO $con = null)
  1906. {
  1907. if ($this->alreadyInSave)
  1908. return parent::postUpdate($con);
  1909. $objectUpdated = $this->isModified();
  1910. $objectDeleted = false;
  1911. if($this->isColumnModified(entryPeer::STATUS) && $this->getStatus() == entryStatus::DELETED)
  1912. $objectDeleted = true;
  1913. $ret = parent::postUpdate($con);
  1914. if($objectDeleted)
  1915. kEventsManager::raiseEvent(new kObjectDeletedEvent($this));
  1916. if($objectUpdated)
  1917. kEventsManager::raiseEvent(new kObjectUpdatedEvent($this));
  1918. return $ret;
  1919. }
  1920. /* (non-PHPdoc)
  1921. * @see lib/model/om/Baseentry#postInsert()
  1922. */
  1923. public function postInsert(PropelPDO $con = null)
  1924. {
  1925. parent::postInsert($con);
  1926. if (!$this->alreadyInSave)
  1927. kEventsManager::raiseEvent(new kObjectAddedEvent($this));
  1928. }
  1929. /*************** Bulk download functions - start ******************/
  1930. /**
  1931. * Check if the returned asset (flavor asset or entry file sync could be downloaded)
  1932. *
  1933. * @param int $flavorParamsId
  1934. * @return bool
  1935. */
  1936. public function hasDownloadAsset($flavorParamsId)
  1937. {
  1938. if($this->getType() == entryType::MIX)
  1939. return false; // always create new flattening job
  1940. $flavorAsset = assetPeer::retrieveByEntryIdAndParams($this->getId(), $flavorParamsId);
  1941. if ($flavorAsset && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY)
  1942. return true;
  1943. if(assetPeer::retrieveOriginalByEntryId($this->getId()))
  1944. return false; // flavor asset should be created
  1945. // entry file sync should be used (data or download)
  1946. return true;
  1947. }
  1948. /**
  1949. * @param BatchJob $parentJob
  1950. * @param int $flavorParamsId
  1951. * @param string $puserId
  1952. * @return int job id
  1953. */
  1954. public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null)
  1955. {
  1956. $job = null;
  1957. if ($this->getType() == entryType::MIX)
  1958. {
  1959. // if flavor params == SOURCE, or no format defined for flavor params, default to 'flv'
  1960. $flattenFormat = null;
  1961. if($flavorParamsId != 0)
  1962. $flattenFormat = assetParamsPeer::retrieveByPK($flavorParamsId)->getFormat();
  1963. if(!$flattenFormat)
  1964. $flattenFormat = 'flv';
  1965. $job = myBatchFlattenClient::addJob($puserId, $this, $this->getVersion(), $flattenFormat);
  1966. }
  1967. else
  1968. {
  1969. $err = '';
  1970. $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err);
  1971. }
  1972. if($job)
  1973. return $job->getId();
  1974. return null;
  1975. }
  1976. /**
  1977. * @param int $flavorParamsId
  1978. * @return string
  1979. */
  1980. public function getDownloadAssetUrl($flavorParamsId)
  1981. {
  1982. $flavorAsset = assetPeer::retrieveByEntryIdAndParams($this->getId(), $flavorParamsId);
  1983. if ($flavorAsset && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY)
  1984. return $flavorAsset->getDownloadUrl();
  1985. if(assetPeer::retrieveOriginalByEntryId($this->getId()))
  1986. return null; // flavor asset should be created
  1987. // entry file sync should be used (data or download)
  1988. return $this->getRawDownloadUrl();
  1989. }
  1990. /*************** Bulk download functions - end ******************/
  1991. /**
  1992. * @return int sorting value
  1993. */
  1994. public function getSortName()
  1995. {
  1996. return kUTF8::str2int64($this->getName());
  1997. }
  1998. /**
  1999. * @return int
  2000. */
  2001. public function getIndexedId()
  2002. {
  2003. return crc32($this->getId());
  2004. }
  2005. /* (non-PHPdoc)
  2006. * @see IIndexable::getEntryId()
  2007. */
  2008. public function getEntryId()
  2009. {
  2010. return $this->getId();
  2011. }
  2012. /* (non-PHPdoc)
  2013. * @see IIndexable::getObjectIndexName()
  2014. */
  2015. public function getObjectIndexName()
  2016. {
  2017. $partner = $this->getPartner();
  2018. $partnerSearchIndex = $partner->getSearchIndex(entryPeer::TABLE_NAME);
  2019. return $partnerSearchIndex;
  2020. }
  2021. /* (non-PHPdoc)
  2022. * @see IIndexable::getIndexFieldsMap()
  2023. */
  2024. public function getIndexFieldsMap()
  2025. {
  2026. return array(
  2027. 'entry_id' => 'id',
  2028. 'str_entry_id' => 'id',
  2029. 'int_entry_id' => 'indexedId',
  2030. 'name' => 'name',
  2031. 'sort_name' => 'sortName',
  2032. 'tags' => 'tags',
  2033. 'categories' => 'categoriesIds',
  2034. 'flavor_params' => 'flavorParamsIds',
  2035. 'source_link' => 'sourceLink',
  2036. 'kshow_id' => 'kshowId',
  2037. 'group_id' => 'groupId',
  2038. 'description' => 'description',
  2039. 'admin_tags' => 'adminTags',
  2040. 'duration_type' => 'durationType',
  2041. 'reference_id' => 'referenceId',
  2042. 'replacing_entry_id' => 'replacingEntryId',
  2043. 'replaced_entry_id' => 'replacedEntryId',
  2044. 'roots' => 'roots',
  2045. 'kuser_id' => 'kuserId',
  2046. 'entry_status' => 'status',
  2047. 'type' => 'type',
  2048. 'media_type' => 'mediaType',
  2049. 'views' => 'views',
  2050. 'partner_id' => 'partnerId',
  2051. 'moderation_status' => 'moderationStatus',
  2052. 'display_in_search' => 'displayInSearch',
  2053. 'duration' => 'durationInt',
  2054. 'access_control_id' => 'accessControlId',
  2055. 'moderation_count' => 'moderationCount',
  2056. 'rank' => 'rank',
  2057. 'plays' => 'plays',
  2058. 'partner_sort_value' => 'partnerSortValue',
  2059. 'replacement_status' => 'replacementStatus',
  2060. 'created_at' => 'createdAt',
  2061. 'updated_at' => 'updatedAt',
  2062. 'modified_at' => 'modifiedAt',
  2063. 'media_date' => 'mediaDate',
  2064. 'start_date' => 'startDate',
  2065. 'end_date' => 'endDate',
  2066. 'available_from' => 'availableFrom',
  2067. );
  2068. }
  2069. private static $indexFieldTypes = array(
  2070. 'entry_id' => IIndexable::FIELD_TYPE_STRING,
  2071. 'str_entry_id' => IIndexable::FIELD_TYPE_STRING,
  2072. 'name' => IIndexable::FIELD_TYPE_STRING,
  2073. 'tags' => IIndexable::FIELD_TYPE_STRING,
  2074. 'categories' => IIndexable::FIELD_TYPE_STRING,
  2075. 'flavor_params' => IIndexable::FIELD_TYPE_STRING,
  2076. 'source_link' => IIndexable::FIELD_TYPE_STRING,
  2077. 'kshow_id' => IIndexable::FIELD_TYPE_STRING,
  2078. 'group_id' => IIndexable::FIELD_TYPE_STRING,
  2079. 'description' => IIndexable::FIELD_TYPE_STRING,
  2080. 'admin_tags' => IIndexable::FIELD_TYPE_STRING,
  2081. 'duration_type' => IIndexable::FIELD_TYPE_STRING,
  2082. 'reference_id' => IIndexable::FIELD_TYPE_STRING,
  2083. 'replacing_entry_id' => IIndexable::FIELD_TYPE_STRING,
  2084. 'replaced_entry_id' => IIndexable::FIELD_TYPE_STRING,
  2085. 'roots' => IIndexable::FIELD_TYPE_STRING,
  2086. 'sort_name' => IIndexable::FIELD_TYPE_INTEGER,
  2087. 'int_entry_id' => IIndexable::FIELD_TYPE_INTEGER,
  2088. 'kuser_id' => IIndexable::FIELD_TYPE_INTEGER,
  2089. 'entry_status' => IIndexable::FIELD_TYPE_INTEGER,
  2090. 'type' => IIndexable::FIELD_TYPE_INTEGER,
  2091. 'media_type' => IIndexable::FIELD_TYPE_INTEGER,
  2092. 'views' => IIndexable::FIELD_TYPE_INTEGER,
  2093. 'partner_id' => IIndexable::FIELD_TYPE_INTEGER,
  2094. 'moderation_status' => IIndexable::FIELD_TYPE_INTEGER,
  2095. 'display_in_search' => IIndexable::FIELD_TYPE_INTEGER,
  2096. 'duration' => IIndexable::FIELD_TYPE_INTEGER,
  2097. 'access_control_id' => IIndexable::FIELD_TYPE_INTEGER,
  2098. 'moderation_count' => IIndexable::FIELD_TYPE_INTEGER,
  2099. 'rank' => IIndexable::FIELD_TYPE_INTEGER,
  2100. 'plays' => IIndexable::FIELD_TYPE_INTEGER,
  2101. 'partner_sort_value' => IIndexable::FIELD_TYPE_INTEGER,
  2102. 'replacement_status' => IIndexable::FIELD_TYPE_INTEGER,
  2103. 'created_at' => IIndexable::FIELD_TYPE_DATETIME,
  2104. 'updated_at' => IIndexable::FIELD_TYPE_DATETIME,
  2105. 'modified_at' => IIndexable::FIELD_TYPE_DATETIME,
  2106. 'media_date' => IIndexable::FIELD_TYPE_DATETIME,
  2107. 'start_date' => IIndexable::FIELD_TYPE_DATETIME,
  2108. 'end_date' => IIndexable::FIELD_TYPE_DATETIME,
  2109. 'available_from' => IIndexable::FIELD_TYPE_DATETIME,
  2110. );
  2111. /**
  2112. * @return string field type, string, int or timestamp
  2113. */
  2114. public function getIndexFieldType($field)
  2115. {
  2116. if(isset(self::$indexFieldTypes[$field]))
  2117. return self::$indexFieldTypes[$field];
  2118. return null;
  2119. }
  2120. public function getCacheInvalidationKeys()
  2121. {
  2122. return array("entry:id=".$this->getId());
  2123. }
  2124. /**
  2125. * @return entry
  2126. */
  2127. public function copyTemplate($coptPartnerId = false)
  2128. {
  2129. // we use get_class(), because this might be a subclass
  2130. $clazz = get_class($this);
  2131. $copyObj = new $clazz();
  2132. /* @var $copyObj entry */
  2133. $copyObj->setKuserId($this->kuser_id);
  2134. $copyObj->setName($this->name);
  2135. $copyObj->setType($this->type);
  2136. $copyObj->setMediaType($this->media_type);
  2137. $copyObj->setTags($this->tags);
  2138. $copyObj->setAnonymous($this->anonymous);
  2139. $copyObj->setSource($this->source);
  2140. $copyObj->setSourceId($this->source_id);
  2141. $copyObj->setSourceLink($this->source_link);
  2142. $copyObj->setLicenseType($this->license_type);
  2143. $copyObj->setCredit($this->credit);
  2144. $copyObj->setDisplayInSearch($this->display_in_search);
  2145. $copyObj->setScreenName($this->screen_name);
  2146. $copyObj->setSiteUrl($this->site_url);
  2147. $copyObj->setPermissions($this->permissions);
  2148. $copyObj->setGroupId($this->group_id);
  2149. $copyObj->setPartnerData($this->partner_data);
  2150. $copyObj->setIndexedCustomData1($this->indexed_custom_data_1);
  2151. $copyObj->setDescription($this->description);
  2152. $copyObj->setAdminTags($this->admin_tags);
  2153. $copyObj->setPuserId($this->puser_id);
  2154. $copyObj->setAccessControlId($this->access_control_id);
  2155. $copyObj->setConversionProfileId($this->conversion_profile_id);
  2156. $copyObj->setCategories($this->categories);
  2157. $copyObj->setCategoriesIds($this->categories_ids);
  2158. // $copyObj->setStartDate($this->start_date);
  2159. // $copyObj->setEndDate($this->end_date);
  2160. if($coptPartnerId)
  2161. $copyObj->setPartnerId($this->getPartnerId());
  2162. $copyObj->setNew(true);
  2163. $copyObj->setCopiedFrom($this);
  2164. return $copyObj;
  2165. }
  2166. }