diff options
| -rw-r--r-- | Pigeonholes.php | 102 | ||||
| -rw-r--r-- | admin/schema_inc.php | 15 | ||||
| -rw-r--r-- | admin/upgrade_inc.php | 46 | ||||
| -rw-r--r-- | edit_pigeonholes.php | 6 | ||||
| -rw-r--r-- | servicefunctions_inc.php | 10 | ||||
| -rw-r--r-- | templates/edit_pigeonholes.tpl | 2 |
6 files changed, 60 insertions, 121 deletions
diff --git a/Pigeonholes.php b/Pigeonholes.php index 978625d..31eb0a2 100644 --- a/Pigeonholes.php +++ b/Pigeonholes.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_pigeonholes/Pigeonholes.php,v 1.30 2006/01/26 10:12:45 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_pigeonholes/Pigeonholes.php,v 1.31 2006/01/30 16:41:46 squareing Exp $ * * +----------------------------------------------------------------------+ * | Copyright ( c ) 2004, bitweaver.org @@ -17,7 +17,7 @@ * Pigeonholes class * * @author xing <xing@synapse.plus.com> - * @version $Revision: 1.30 $ + * @version $Revision: 1.31 $ * @package pigeonholes */ @@ -461,12 +461,10 @@ class Pigeonholes extends LibertyAttachable { $result = $this->mDb->associateInsert( $table, $pParamHash['pigeonhole_store'] ); } - // store pigeonhole settings + // store individual pigeonhole preferences if( !empty( $pParamHash['pigeonhole_settings_store'] ) ) { - // remove previous settings first - $this->expungePigeonholeSettings( $this->mContentId ); - if( !$this->insertPigeonholeSettings( $pParamHash['pigeonhole_settings_store'] ) ) { - $this->mErrors['store'] = 'The individual pigeonhole settings could not be stored.'; + foreach( $pParamHash['pigeonhole_settings_store'] as $name => $value ) { + $this->storePreference( $name, $value ); } } @@ -567,80 +565,6 @@ class Pigeonholes extends LibertyAttachable { } /** - * get all content inserted in a given pigeonhole. if no id is given, it gets all content for all pigeonholes - * @param $pContentId content id of the pigeonhole - * @return array of pigeonhole members with according title and content type guid - * @access public - **/ - function getPigeonholeSettings( $pContentId=NULL, $pMemberId=NULL ) { - global $gBitUser, $gLibertySystem, $gBitSystem; - if( @BitBase::verifyId( $this->mContentId ) || @BitBase::verifyId( $pContentId ) || @BitBase::verifyId( $pMemberId ) ) { - if( @BitBase::verifyId( $pMemberId ) ) { - $where = "WHERE bpm.`content_id`=?"; - $bindVars[] = $pMemberId; - } else { - $where = "WHERE bps.`content_id`=?"; - $bindVars[] = @BitBase::verifyId( $pContentId ) ? $pContentId : $this->mContentId; - } - $query = "SELECT bps.`name`, bps.`value` - FROM `".BIT_DB_PREFIX."bit_pigeonhole_settings` bps - INNER JOIN `".BIT_DB_PREFIX."bit_pigeonhole_members` bpm ON ( bps.`content_id` = bpm.`parent_id` ) - $where"; - - $ret = $this->mDb->getAssoc( $query, $bindVars ); - } else { - $this->mErrors['get_members'] = tra( 'No valid content / member id was given.' ); - } - return( !empty( $ret ) ? $ret : NULL ); - } - - /** - * Store pigeonhole settings - * @param $pParamHash an array of content to be stored. - * @param $pParamHash[parent_id] id of pigeonhole it belongs to, default is $this->mContentId - * @param $pParamHash[content_id] content_id of the item to be stored - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public - **/ - function insertPigeonholeSettings( &$pParamHash, $pContentId=NULL ) { - if( $this->verifyPigeonholeSettings( $pParamHash ) ) { - foreach( $pParamHash['settings_store'] as $setting ) { - $setting['content_id'] = @BitBase::verifyId( $pContentId ) ? $pContentId : $this->mContentId; - $result = $this->mDb->associateInsert( BIT_DB_PREFIX."bit_pigeonhole_settings", $setting ); - } - } else { - vd( $this->mErrors ); - } - return( count( $this->mErrors ) == 0 ); - } - - /** - * verify, clean up and prepare data to be stored - * @param $pParamHash all information that is being stored. will update $pParamHash by reference with fixed array of itmes - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access private - **/ - function verifyPigeonholeSettings( &$pParamHash ) { - if( !empty( $pParamHash ) ) { - $availableSettings = array( 'style' ); - $i = 0; - foreach( $pParamHash as $name => $value ) { - if( in_array( $name, $availableSettings ) ) { - $pParamHash['settings_store'][$i]['name'] = $name; - $pParamHash['settings_store'][$i]['value'] = !empty( $value ) ? $value : NULL; - $i++; - } - } - } - - if( empty( $pParamHash['settings_store'] ) ) { - $pParamHash['settings_store'] = array(); - } - - return( count( $this->mErrors ) == 0 ); - } - - /** * Store pigeonhole member * @param $pParamHash an array of content to be stored. * @param $pParamHash[parent_id] id of pigeonhole it belongs to, default is $this->mContentId @@ -690,21 +614,6 @@ class Pigeonholes extends LibertyAttachable { } /** - * Expunge pigeonhole settings - * @param $pContentId content id for which all settings are to be removed - * @access public - **/ - function expungePigeonholeSettings( $pContentId=NULL ) { - if( @BitBase::verifyId( $pContentId ) ) { - $query = "DELETE FROM `".BIT_DB_PREFIX."bit_pigeonhole_settings` WHERE `content_id` = ?"; - $result = $this->mDb->query( $query, array( $pContentId ) ); - } else { - $this->mErrors['settings_expunge'] = 'The settings could not be removed.'; - } - return( count( $this->mErrors ) == 0 ); - } - - /** * Expunge pigeonhole member * @param $pParamHash['parent_id'] parent_id of content to be deleted * @param $pParamHash['member_id'] content_id of content to be deleted @@ -785,7 +694,6 @@ class Pigeonholes extends LibertyAttachable { $result = $this->mDb->query( $query, array( $id['content_id'] ) ); $query = "DELETE FROM `".BIT_DB_PREFIX."bit_pigeonhole_members` WHERE `parent_id` = ?"; $result = $this->mDb->query( $query, array( $id['content_id'] ) ); - $this->expungePigeonholeSettings( $id['content_id'] ); // remove all entries from content tables $this->mContentId = $id['content_id']; diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 66de512..7888888 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -1,18 +1,19 @@ <?php $tables = array( - 'bit_pigeonholes' => " + 'pigeonholes' => " content_id I4 NOTNULL PRIMARY, structure_id I4 NOTNULL PRIMARY + CONSTRAINTS ', + CONSTRAINT `bit_pigeonholes_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` ), + CONSTRAINT `bit_pigeonholes_ref` FOREIGN KEY (`structure_id`) REFERENCES `".BIT_DB_PREFIX."tiki_structures`( `structure_id` )' ", - 'bit_pigeonhole_settings' => " - content_id I4 NOTNULL PRIMARY, - name C(40) NOTNULL, - value C(40) NULL - ", - 'bit_pigeonhole_members' => " + 'pigeonhole_members' => " parent_id I4 NOTNULL PRIMARY, content_id I4 NOTNULL PRIMARY + CONSTRAINTS ', + CONSTRAINT `bit_pigeonhole_members_ref` FOREIGN KEY (`parent_id`) REFERENCES `".BIT_DB_PREFIX."bit_pigeonholes`( `content_id` ), + CONSTRAINT `bit_pigeonhole_members_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )' " ); diff --git a/admin/upgrade_inc.php b/admin/upgrade_inc.php index 337803f..ec2c36d 100644 --- a/admin/upgrade_inc.php +++ b/admin/upgrade_inc.php @@ -5,12 +5,45 @@ global $gBitSystem, $gUpgradeFrom, $gUpgradeTo; $upgrades = array( 'BWR1' => array( 'BWR2' => array( - // STEP 1 - array( 'DATADICT' => array( - array( 'DROPCOLUMN' => array( - 'bit_pigeonhole_members' => array( '`pos`' ), - )), - )), + +// transfer all the settings into liberty_content_prefs +array( 'PHP' => ' + global $gBitSystem; + $pigeonhole_settings = $gBitSystem->mDb->getAssoc( "SELECT `content_id`, `name`, `value` FROM `".BIT_DB_PREFIX."bit_pigeonhole_settings` ); + if( !empty( $pigeonhole_settings ) ) { + foreach( $pigeonhole_settings as $store ) { + $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_content_prefs` (`content_id`,`name`,`value`) VALUES(?, ?, ?)"; + $result = $this->mDb->query( $query, $store ); + } + } +'), + +// add constraints for pgsql +array( 'QUERY' => + array( 'PGSQL' => array( + "ALTER TABLE `".BIT_DB_PREFIX."bit_pigeonholes` ADD CONSTRAINT `bit_pigeonholes_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )", + "ALTER TABLE `".BIT_DB_PREFIX."bit_pigeonholes` ADD CONSTRAINT `bit_pigeonholes_ref` FOREIGN KEY (`structure_id`) REFERENCES `".BIT_DB_PREFIX."tiki_structures`( `structure_id` )", + "ALTER TABLE `".BIT_DB_PREFIX."bit_pigeonhole_members` ADD CONSTRAINT `bit_pigeonhole_members_ref` FOREIGN KEY (`parent_id`) REFERENCES `".BIT_DB_PREFIX."bit_pigeonholes`( `content_id` )", + "ALTER TABLE `".BIT_DB_PREFIX."bit_pigeonhole_members` ADD CONSTRAINT `bit_pigeonhole_members_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )", + )), +), + +// drop unused columns and tables +array( 'DATADICT' => array( + // positional data for categories is just odd + array( 'DROPCOLUMN' => array( + 'bit_pigeonhole_members' => array( '`pos`' ), + )), + // bw now has liberty_content_prefs for this + array( 'DROPTABLE' => array( + 'bit_pigeonhole_settings', + )), +// // remove bit_ prefix +// array( 'RENAMETABLE' => array( +// 'bit_pigeonholes' => 'pigeonholes', +// 'bit_pigeonhole_members' => 'pigeonhole_members', +// )), +)), ) ) ); @@ -19,5 +52,4 @@ if( isset( $upgrades[$gUpgradeFrom][$gUpgradeTo] ) ) { $gBitSystem->registerUpgrade( PIGEONHOLES_PKG_NAME, $upgrades[$gUpgradeFrom][$gUpgradeTo] ); } - ?> diff --git a/edit_pigeonholes.php b/edit_pigeonholes.php index 683b8b2..b8fc653 100644 --- a/edit_pigeonholes.php +++ b/edit_pigeonholes.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_pigeonholes/edit_pigeonholes.php,v 1.10 2006/01/24 22:41:47 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_pigeonholes/edit_pigeonholes.php,v 1.11 2006/01/30 16:41:46 squareing Exp $ * * Copyright ( c ) 2004 bitweaver.org * Copyright ( c ) 2003 tikwiki.org @@ -8,7 +8,7 @@ * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: edit_pigeonholes.php,v 1.10 2006/01/24 22:41:47 squareing Exp $ + * $Id: edit_pigeonholes.php,v 1.11 2006/01/30 16:41:46 squareing Exp $ * @package pigeonholes * @subpackage functions */ @@ -73,7 +73,7 @@ if( !empty( $_REQUEST['search_objects'] ) ) { // if we need to edit, show the information if( $_REQUEST['action'] == 'edit' ) { $pigeonInfo = $gContent->mInfo; - $pigeonInfo['settings'] = $gContent->getPigeonholeSettings( $gContent->mContentId ); + $gContent->loadPreferences(); // create usable array for selected items in content listing if( !empty( $pigeonInfo['members'] ) ) { diff --git a/servicefunctions_inc.php b/servicefunctions_inc.php index 8cda864..ebb0b4b 100644 --- a/servicefunctions_inc.php +++ b/servicefunctions_inc.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_pigeonholes/Attic/servicefunctions_inc.php,v 1.7 2006/01/24 22:41:47 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_pigeonholes/Attic/servicefunctions_inc.php,v 1.8 2006/01/30 16:41:46 squareing Exp $ * * Copyright ( c ) 2004 bitweaver.org * All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -19,17 +19,15 @@ function display_pigeonholes( &$pObject ) { require_once( PIGEONHOLES_PKG_PATH.'Pigeonholes.php' ); $pigeonholes = new Pigeonholes(); - $settings = $pigeonholes->getPigeonholeSettings( NULL, $pObject->mContentId ); - if( !empty( $settings['style'] ) ) { - $gPreviewStyle = $settings["style"]; - } - if( $gBitUser->hasPermission( 'bit_p_view_pigeonholes' ) ) { if( $pigeons = $pigeonholes->getPigeonholesFromContentId( $pObject->mContentId ) ) { foreach( $pigeons as $pigeon ) { $pigeonholes->mContentId = $pigeon['content_id']; $pigeonholes->load( TRUE ); $pigeonData[] = $pigeonholes->mInfo; + // set the theme chosen for this page - virtually random if page is part of multiple themes + $pigeonholes->loadPreferences(); + $gPreviewStyle = $pigeonholes->getPreference( 'style' ); } $gBitSmarty->assign( 'pigeonData', !empty( $pigeonData ) ? $pigeonData : FALSE ); } diff --git a/templates/edit_pigeonholes.tpl b/templates/edit_pigeonholes.tpl index 4eb6fa2..833358a 100644 --- a/templates/edit_pigeonholes.tpl +++ b/templates/edit_pigeonholes.tpl @@ -45,7 +45,7 @@ <div class="row"> {formlabel label="Theme" for="pigeonhole-style"} {forminput} - {html_options id="pigeonhole-style" name="pigeonhole[settings][style]" output=$styles values=$styles selected=$pigeonInfo.settings.style} + {html_options id="pigeonhole-style" name="pigeonhole[settings][style]" output=$styles values=$styles selected=$gContent->mPrefs.style} {formhelp note="This theme will be applied when viewing any page belonging to this category."} {/forminput} </div> |
