Source for file classes_slideshow.php

Documentation is available at classes_slideshow.php

  1. <?php
  2.  
  3. class slideshow extends b_object {
  4. //base resource definition
  5. var $id;
  6. var $name;
  7. var $description;
  8. var $imageArray;
  9. function slideshow( $constructID = NULL ) {
  10. parent::b_object( $constructID, 'slideshows' );
  11. //convert the image array to object references
  12. if( $ids = unserialize( $this->imageArray ) ) {
  13. unset( $this->imageArray );
  14. foreach( $ids as $id ) {
  15. $this->imageArray[] =& get_object( $id, 'images' );
  16. }
  17. } else {
  18. $this->imageArray = array();
  19. }
  20. }
  21. function get_index() {
  22. if( $this->name ) {
  23. return $this->name;
  24. } else {
  25. return 'new slideshow';
  26. }
  27. }
  28. function get_image_key( $id ) {
  29. foreach( $this->imageArray as $key => $image ) {
  30. if( $image->id == $id ) { return $key; }
  31. }
  32. }
  33. function verify_set( $post ) {
  34. foreach( $post as $key => $value ) {
  35. $id = substr( $key, ( strrpos( $key, '_' ) + 1 ) );
  36. if( strstr( $key, 'f_browser_' ) && $value ) {
  37. //add file or folder to slideshow
  38. $this->append_object( $id );
  39. unset( $post[$key] );
  40. }
  41. if( strstr( $key, 's_order_' ) && $value ) {
  42. //change image ordering
  43. $target = $value - 1;
  44. $current = $this->get_image_key( $id );
  45. if( $current != $target ) {
  46. //copy image in the target slot to a placeholder
  47. $existing = $this->imageArray[ $target ];
  48. //put the move the image from its current location to the target one
  49. $this->imageArray[$target] = $this->imageArray[ $current ];
  50. //and put the image from the target slot in the old image's slot
  51. $this->imageArray[ $current ] = $existing;
  52. }
  53. unset( $post[$key] );
  54. } else if( strstr( $key, 's_browser_' ) && $value ) {
  55. //remove file from slideshow
  56. $this->delete_image( $id );
  57. unset( $post[$key] );
  58. }
  59. }
  60. parent::verify_set($post);
  61. $this->set_image_array();
  62.  
  63. }
  64. function append_object( $id ) {
  65. if( $object =& get_object( $id ) ) {
  66. if( $object->type->type_class_name == 'folder' ) {
  67. $this->append_folder( $object );
  68. } else {
  69. $this->append_image( $object->id );
  70. }
  71. }
  72. }
  73. function append_folder( &$folder ) {
  74. if( $folders = $folder->get_subfolders() ) {
  75. foreach( $folders as $folder ) {
  76. $this->append_folder( $folder );
  77. }
  78. }
  79. if( $files = $folder->get_files() ) {
  80. foreach( $files as $file ) {
  81. if( $file->type->get_attribute( 'type_class_name' ) == 'image' ) {
  82. $this->append_image( $file->id );
  83. }
  84. }
  85. }
  86. }
  87. function append_image( &$image ) {
  88. $this->imageArray[] =& get_object($image);
  89. $this->set_image_array();
  90. }
  91. function delete_image( $imageID ) {
  92. //delete the image from the image array
  93. foreach( $this->imageArray as $key => $image ) {
  94. if( $image->id == $imageID ) {
  95. unset( $this->imageArray[$key] );
  96. $this->set_image_array();
  97. break;
  98. }
  99. }
  100. }
  101. function set_image_array() {
  102. foreach( $this->imageArray as $image ) {
  103. $DBarray[] = $image->id;
  104. }
  105. parent::set_DB( array( 'imageArray' => serialize( $DBarray ) ) );
  106. }
  107. function get_object_table( $fieldArray = NULL ) {
  108. /*
  109. * this should consist of two panes, one on the left which browses all defined folders
  110. * and one on the right which displays the images in the slideshow. both folders and files
  111. * should be able to be dragged to the right pane, and once they've been placed they should
  112. * be draggable to control sequence. each image in the right pane should have an
  113. * edit link for changing the object's properties (although maybe these properties should
  114. * be able to be 'overloaded' by the slideshow).
  115. */
  116. if( $this->id != '*new*' ) {
  117. //start the return element
  118. $return = new HTMLElement( 'div' );
  119. $return->set_attribute( 'class', 'two_column_container' );
  120. //add a file browser
  121. $files =& $return->add_element( file_browser( false, true ) );
  122. $files->set_attributes(array( 'id'=>'file_browser', 'class'=>'left_pane' ));
  123. $instructions =& $files->add_element( new HTMLElement( 'p' ), 0 );
  124. $instructions->add_element( 'select a checkbox and press \'save changes\' to add the file or folder to the slideshow' );
  125. //add a slide browser
  126. $slides =& $return->add_element( $this->slide_browser( true ) );
  127. $slides->set_attributes(array( 'id'=>'slide_browser', 'class'=>'right_pane' ));
  128. $instructions =& $slides->add_element( new HTMLElement( 'p' ), 0 );
  129. $instructions->add_element( 'select a checkbox and press \'save changes\' to remove an image from the slideshow' );
  130. $instructions =& $slides->add_element( new HTMLElement( 'p' ), 1 );
  131. $instructions->add_element( 'to change the image sequence, enter the desired order and press \'save changes\'' );
  132.  
  133. $returnString = $return->to_html();
  134. }
  135. $returnString .= parent::get_object_table( $fieldArray );
  136. return $returnString;
  137. }
  138. function slide_browser( $returnElement = false ) {
  139. $return = new HTMLElement( 'div' );
  140. if( count($this->imageArray) ) {
  141. foreach( $this->imageArray as $key => $image ) {
  142. $imageObj =& $return->add_element( new HTMLElement( 'div' ) );
  143. $imageObj->set_attribute( 'id', $image->id );
  144.  
  145. $order =& $imageObj->add_element( new HTMLElement('input') );
  146. //NOTE!!!! this is incrementing the key value by one - IT MUST BE DECREMENTED TO WORK PROPERLY WHEN PROCESSED AS A POST VARIABLE
  147. $order->set_attributes( array('type'=>'input', 'name'=>'s_order_'.$image->id, 'value'=>$key+1, 'class'=>'form_state' ) );
  148.  
  149. $checkbox =& $imageObj->add_element( new HTMLElement('input') );
  150. $checkbox->set_attributes( array('type'=>'checkbox', 'name'=>'s_browser_'.$image->id ) );
  151. $checkbox->add_element( $image->get_index() );
  152. }
  153. } else {
  154. $return->add_element( 'no images in slideshow' );
  155. }
  156. return $returnElement?$return:$return->to_html();
  157. }
  158. }
  159.  
  160. function file_browser( $include_files = true, $returnElement = false, $root_IDs = NULL, $radio = false ) {
  161. //if no root folders are specified add them all
  162. if( !$root_IDs ) {
  163. //find root folders
  164. $folder_type = $GLOBALS['core']->get_object_type( 'folders' );
  165. $constraint_type = $GLOBALS['core']->get_object_type( 'constraints' );
  166. $is_subfolder =& reset($constraint_type->get_byValue( array( array( 'attribute'=>'name','operator'=>'=','value'=>'is subfolder' ) ) ) );
  167. if( $folders = $folder_type->retrieve_all() ) {
  168. foreach( $folders as $folder ) {
  169. if( !core_satisfied( $is_subfolder, $folder ) ) { $root_IDs[] = $folder->id; }
  170. }
  171. }
  172. }
  173.  
  174. $return = new HTMLElement( 'div' );
  175. if( $root_IDs ) {
  176. $return->add_element( 'click folder to view contents' );
  177. foreach( $root_IDs as $folderID ) {
  178. $return->add_element( browser_folder( $folderID, $include_files, true, $radio ) );
  179. }
  180. } else {
  181. $return->add_element( 'no files defined' );
  182. }
  183. return $returnElement?$return:$return->to_html();
  184. }
  185.  
  186. function browser_folder( $id, $include_files = true, $returnElement = false, $radio = false ) {
  187. if( $folder =& get_object( $id, "folders" ) ) {
  188. //start the folder's container
  189. $return =& new HTMLElement('div');
  190. //add the folder's link
  191. $input =& $return->add_element( new HTMLElement('input') );
  192. if( $radio ) { $input->set_attributes( array('type'=>'radio', 'name'=>'folder', 'value'=>$id ) ); }
  193. else { $input->set_attributes( array('type'=>'checkbox', 'name'=>'f_browser_'.$id ) ); }
  194. $folder_link =& $return->add_element( new HTMLElement('a') );
  195. $folder_link->set_attribute( 'href', '#' );
  196. //$folder_link->set_attribute( 'onClick', /*onclick expand or retract contents*/ );
  197. //$folder_link->set_attribute( 'onMouseOver', /*change color*/ );
  198. //$folder_link->set_attribute( 'onMouseOut', /*change color back*/ );
  199. $folder_link->add_element( $folder->get_index() );
  200. //add the folder's content div
  201. $content =& $return->add_element( new HTMLElement('div') );
  202. $content->set_attribute( 'id', 'f_browser_'.$folder->id );
  203. $content->set_attribute( 'class', 'indent' );
  204. //add to subfolders
  205. if( $subfolders = $folder->get_subfolders() ) {
  206. foreach( $subfolders as $subfolder ) {
  207. $folder_link =& $content->add_element( browser_folder( $subfolder->id, true ) );
  208. }
  209. }
  210. //add files
  211. if( $files = $folder->get_files() ) {
  212. foreach( $files as $file ) {
  213. if( $include_files ) {
  214. $checkbox =& $content->add_element( new HTMLElement('input') );
  215. $checkbox->set_attributes( array('type'=>'checkbox', 'name'=>'f_browser_'.$file->id ) );
  216. }
  217.  
  218. $file_link =& $content->add_element( new HTMLElement( 'a' ) );
  219. $file_link->set_attribute( 'href', '#' );
  220. //$file_link->set_attribute( 'onMouseOver', /*dragging code*/ );
  221. $file_link->add_element( $file->get_index() );
  222. $file_link->add_element( new HTMLElement( 'br', NULL, true ) );
  223. }
  224. }
  225. return $returnElement?$return:$return->to_html();
  226. }
  227. }
  228.  
  229. ?>

Documentation generated on Tue, 24 May 2005 03:57:18 -0400 by phpDocumentor 1.3.0RC3