Documentation is available at classes_slideshow.php
- <?php
- class slideshow extends b_object {
- //base resource definition
- var $id;
- var $name;
- var $description;
- var $imageArray;
- function slideshow( $constructID = NULL ) {
- parent::b_object( $constructID, 'slideshows' );
- //convert the image array to object references
- if( $ids = unserialize( $this->imageArray ) ) {
- unset( $this->imageArray );
- foreach( $ids as $id ) {
- $this->imageArray[] =& get_object( $id, 'images' );
- }
- } else {
- $this->imageArray = array();
- }
- }
- function get_index() {
- if( $this->name ) {
- return $this->name;
- } else {
- return 'new slideshow';
- }
- }
- function get_image_key( $id ) {
- foreach( $this->imageArray as $key => $image ) {
- if( $image->id == $id ) { return $key; }
- }
- }
- function verify_set( $post ) {
- foreach( $post as $key => $value ) {
- $id = substr( $key, ( strrpos( $key, '_' ) + 1 ) );
- if( strstr( $key, 'f_browser_' ) && $value ) {
- //add file or folder to slideshow
- $this->append_object( $id );
- unset( $post[$key] );
- }
- if( strstr( $key, 's_order_' ) && $value ) {
- //change image ordering
- $target = $value - 1;
- $current = $this->get_image_key( $id );
- if( $current != $target ) {
- //copy image in the target slot to a placeholder
- $existing = $this->imageArray[ $target ];
- //put the move the image from its current location to the target one
- $this->imageArray[$target] = $this->imageArray[ $current ];
- //and put the image from the target slot in the old image's slot
- $this->imageArray[ $current ] = $existing;
- }
- unset( $post[$key] );
- } else if( strstr( $key, 's_browser_' ) && $value ) {
- //remove file from slideshow
- $this->delete_image( $id );
- unset( $post[$key] );
- }
- }
- parent::verify_set($post);
- $this->set_image_array();
- }
- function append_object( $id ) {
- if( $object =& get_object( $id ) ) {
- if( $object->type->type_class_name == 'folder' ) {
- $this->append_folder( $object );
- } else {
- $this->append_image( $object->id );
- }
- }
- }
- function append_folder( &$folder ) {
- if( $folders = $folder->get_subfolders() ) {
- foreach( $folders as $folder ) {
- $this->append_folder( $folder );
- }
- }
- if( $files = $folder->get_files() ) {
- foreach( $files as $file ) {
- if( $file->type->get_attribute( 'type_class_name' ) == 'image' ) {
- $this->append_image( $file->id );
- }
- }
- }
- }
- function append_image( &$image ) {
- $this->imageArray[] =& get_object($image);
- $this->set_image_array();
- }
- function delete_image( $imageID ) {
- //delete the image from the image array
- foreach( $this->imageArray as $key => $image ) {
- if( $image->id == $imageID ) {
- unset( $this->imageArray[$key] );
- $this->set_image_array();
- break;
- }
- }
- }
- function set_image_array() {
- foreach( $this->imageArray as $image ) {
- $DBarray[] = $image->id;
- }
- parent::set_DB( array( 'imageArray' => serialize( $DBarray ) ) );
- }
- function get_object_table( $fieldArray = NULL ) {
- /*
- * this should consist of two panes, one on the left which browses all defined folders
- * and one on the right which displays the images in the slideshow. both folders and files
- * should be able to be dragged to the right pane, and once they've been placed they should
- * be draggable to control sequence. each image in the right pane should have an
- * edit link for changing the object's properties (although maybe these properties should
- * be able to be 'overloaded' by the slideshow).
- */
- if( $this->id != '*new*' ) {
- //start the return element
- $return = new HTMLElement( 'div' );
- $return->set_attribute( 'class', 'two_column_container' );
- //add a file browser
- $files =& $return->add_element( file_browser( false, true ) );
- $files->set_attributes(array( 'id'=>'file_browser', 'class'=>'left_pane' ));
- $instructions =& $files->add_element( new HTMLElement( 'p' ), 0 );
- $instructions->add_element( 'select a checkbox and press \'save changes\' to add the file or folder to the slideshow' );
- //add a slide browser
- $slides =& $return->add_element( $this->slide_browser( true ) );
- $slides->set_attributes(array( 'id'=>'slide_browser', 'class'=>'right_pane' ));
- $instructions =& $slides->add_element( new HTMLElement( 'p' ), 0 );
- $instructions->add_element( 'select a checkbox and press \'save changes\' to remove an image from the slideshow' );
- $instructions =& $slides->add_element( new HTMLElement( 'p' ), 1 );
- $instructions->add_element( 'to change the image sequence, enter the desired order and press \'save changes\'' );
- $returnString = $return->to_html();
- }
- $returnString .= parent::get_object_table( $fieldArray );
- return $returnString;
- }
- function slide_browser( $returnElement = false ) {
- $return = new HTMLElement( 'div' );
- if( count($this->imageArray) ) {
- foreach( $this->imageArray as $key => $image ) {
- $imageObj =& $return->add_element( new HTMLElement( 'div' ) );
- $imageObj->set_attribute( 'id', $image->id );
- $order =& $imageObj->add_element( new HTMLElement('input') );
- //NOTE!!!! this is incrementing the key value by one - IT MUST BE DECREMENTED TO WORK PROPERLY WHEN PROCESSED AS A POST VARIABLE
- $order->set_attributes( array('type'=>'input', 'name'=>'s_order_'.$image->id, 'value'=>$key+1, 'class'=>'form_state' ) );
- $checkbox =& $imageObj->add_element( new HTMLElement('input') );
- $checkbox->set_attributes( array('type'=>'checkbox', 'name'=>'s_browser_'.$image->id ) );
- $checkbox->add_element( $image->get_index() );
- }
- } else {
- $return->add_element( 'no images in slideshow' );
- }
- return $returnElement?$return:$return->to_html();
- }
- }
- function file_browser( $include_files = true, $returnElement = false, $root_IDs = NULL, $radio = false ) {
- //if no root folders are specified add them all
- if( !$root_IDs ) {
- //find root folders
- $folder_type = $GLOBALS['core']->get_object_type( 'folders' );
- $constraint_type = $GLOBALS['core']->get_object_type( 'constraints' );
- $is_subfolder =& reset($constraint_type->get_byValue( array( array( 'attribute'=>'name','operator'=>'=','value'=>'is subfolder' ) ) ) );
- if( $folders = $folder_type->retrieve_all() ) {
- foreach( $folders as $folder ) {
- if( !core_satisfied( $is_subfolder, $folder ) ) { $root_IDs[] = $folder->id; }
- }
- }
- }
- $return = new HTMLElement( 'div' );
- if( $root_IDs ) {
- $return->add_element( 'click folder to view contents' );
- foreach( $root_IDs as $folderID ) {
- $return->add_element( browser_folder( $folderID, $include_files, true, $radio ) );
- }
- } else {
- $return->add_element( 'no files defined' );
- }
- return $returnElement?$return:$return->to_html();
- }
- function browser_folder( $id, $include_files = true, $returnElement = false, $radio = false ) {
- if( $folder =& get_object( $id, "folders" ) ) {
- //start the folder's container
- $return =& new HTMLElement('div');
- //add the folder's link
- $input =& $return->add_element( new HTMLElement('input') );
- if( $radio ) { $input->set_attributes( array('type'=>'radio', 'name'=>'folder', 'value'=>$id ) ); }
- else { $input->set_attributes( array('type'=>'checkbox', 'name'=>'f_browser_'.$id ) ); }
- $folder_link =& $return->add_element( new HTMLElement('a') );
- $folder_link->set_attribute( 'href', '#' );
- //$folder_link->set_attribute( 'onClick', /*onclick expand or retract contents*/ );
- //$folder_link->set_attribute( 'onMouseOver', /*change color*/ );
- //$folder_link->set_attribute( 'onMouseOut', /*change color back*/ );
- $folder_link->add_element( $folder->get_index() );
- //add the folder's content div
- $content =& $return->add_element( new HTMLElement('div') );
- $content->set_attribute( 'id', 'f_browser_'.$folder->id );
- $content->set_attribute( 'class', 'indent' );
- //add to subfolders
- if( $subfolders = $folder->get_subfolders() ) {
- foreach( $subfolders as $subfolder ) {
- $folder_link =& $content->add_element( browser_folder( $subfolder->id, true ) );
- }
- }
- //add files
- if( $files = $folder->get_files() ) {
- foreach( $files as $file ) {
- if( $include_files ) {
- $checkbox =& $content->add_element( new HTMLElement('input') );
- $checkbox->set_attributes( array('type'=>'checkbox', 'name'=>'f_browser_'.$file->id ) );
- }
- $file_link =& $content->add_element( new HTMLElement( 'a' ) );
- $file_link->set_attribute( 'href', '#' );
- //$file_link->set_attribute( 'onMouseOver', /*dragging code*/ );
- $file_link->add_element( $file->get_index() );
- $file_link->add_element( new HTMLElement( 'br', NULL, true ) );
- }
- }
- return $returnElement?$return:$return->to_html();
- }
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:18 -0400 by phpDocumentor 1.3.0RC3