PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_data/class.gallery_mapper.php

https://github.com/Fishgate/privatecollectionswp
PHP | 130 lines | 85 code | 19 blank | 26 comment | 11 complexity | 6aacb74f4411730f06cbd355afa39121 MD5 | raw file
  1. <?php
  2. /**
  3. * Provides a datamapper for galleries
  4. */
  5. class C_Gallery_Mapper extends C_CustomTable_DataMapper_Driver
  6. {
  7. public static $_instances = array();
  8. /**
  9. * Define the object
  10. * @param string $context
  11. */
  12. function define($context=FALSE, $not_used=FALSE)
  13. {
  14. // Add 'gallery' context
  15. if (!is_array($context)) $context = array($context);
  16. array_push($context, 'gallery');
  17. $this->_primary_key_column = 'gid';
  18. // Continue defining the object
  19. parent::define('ngg_gallery', $context);
  20. $this->set_model_factory_method('gallery');
  21. $this->add_mixin('Mixin_NextGen_Table_Extras');
  22. $this->add_mixin('Mixin_Gallery_Mapper');
  23. $this->implement('I_Gallery_Mapper');
  24. // Define the columns
  25. $this->define_column('gid', 'BIGINT', 0);
  26. $this->define_column('name', 'VARCHAR(255)');
  27. $this->define_column('slug', 'VARCHAR(255');
  28. $this->define_column('path', 'TEXT');
  29. $this->define_column('title', 'TEXT');
  30. $this->define_column('pageid', 'INT', 0);
  31. $this->define_column('previewpic', 'INT', 0);
  32. $this->define_column('author', 'INT', 0);
  33. $this->define_column('extras_post_id', 'BIGINT', 0);
  34. }
  35. function initialize($object_name=FALSE)
  36. {
  37. parent::initialize('ngg_gallery');
  38. }
  39. /**
  40. * Returns a singleton of the gallery mapper
  41. * @param string $context
  42. * @return C_Gallery_Mapper
  43. */
  44. public static function get_instance($context = False)
  45. {
  46. if (!isset(self::$_instances[$context]))
  47. {
  48. self::$_instances[$context] = new C_Gallery_Mapper($context);
  49. }
  50. return self::$_instances[$context];
  51. }
  52. }
  53. class Mixin_Gallery_Mapper extends Mixin
  54. {
  55. /**
  56. * Uses the title property as the post title when the Custom Post driver
  57. * is used
  58. */
  59. function get_post_title($entity)
  60. {
  61. return $entity->title;
  62. }
  63. function _save_entity($entity)
  64. {
  65. $retval = $this->call_parent('_save_entity', $entity);
  66. if ($retval) {
  67. do_action('ngg_created_new_gallery', $entity->{$entity->id_field});
  68. C_Photocrati_Cache::flush('displayed_gallery_rendering');
  69. }
  70. return $retval;
  71. }
  72. function destroy($image)
  73. {
  74. $retval = $this->call_parent('destroy',$image);
  75. C_Photocrati_Cache::flush('displayed_gallery_rendering');
  76. return $retval;
  77. }
  78. function set_preview_image($gallery, $image, $only_if_empty=FALSE)
  79. {
  80. $retval = FALSE;
  81. // We need the gallery object
  82. if (is_numeric($gallery)) {
  83. $gallery = $this->object->find($gallery);
  84. }
  85. // We need the image id
  86. if (!is_numeric($image)) {
  87. if (method_exists($image, 'id')) {
  88. $image = $image->id();
  89. }
  90. else {
  91. $image = $image->{$image->id_field};
  92. }
  93. }
  94. if ($gallery && $image) {
  95. if (($only_if_empty && !$gallery->previewpic) OR !$only_if_empty) {
  96. $gallery->previewpic = $image;
  97. $retval = $this->object->save($gallery);
  98. }
  99. }
  100. return $retval;
  101. }
  102. /**
  103. * Sets default values for the gallery
  104. */
  105. function set_defaults($entity)
  106. {
  107. // If author is missing, then set to the current user id
  108. // TODO: Using wordpress function. Should use abstraction
  109. $this->object->_set_default_value($entity, 'author', get_current_user_id());
  110. }
  111. }