From 7960ca30cd968e6ace7282e0db6fb5e2be692771 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 4 Apr 2017 15:00:33 -0400 Subject: [PATCH] Work on categories Setup category import sql --- .../management/import/brewbakersImport.php | 70 ++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/models/admin/management/import/brewbakersImport.php b/models/admin/management/import/brewbakersImport.php index 0f6b6eb7..55e7d164 100644 --- a/models/admin/management/import/brewbakersImport.php +++ b/models/admin/management/import/brewbakersImport.php @@ -3,12 +3,14 @@ echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; // Setup the database connection to postgres -$dbServer = 'ds4'; -$dbName = 'brewbakers'; -$dbUser = 'postgres'; -$resetdb = false; -$rvs = array(); -$homes = array(); +$dbServer = 'ds4'; +$dbName = 'brewbakers'; +$dbUser = 'postgres'; +$resetdb = false; +$rvs = array(); +$homes = array(); +$amenities = array(); +$amenityData = array(); // Create connection $connString = "host=$dbServer dbname=$dbName user=$dbUser"; @@ -102,7 +104,7 @@ if ( !$failure ) { } $failure = true; } - echo '
$amenities: ' . print_r( $amenities, true ) . '
'; + //echo '
$amenities: ' . print_r( $amenities, true ) . '
'; } } // 4. Get amenity member relation data @@ -127,9 +129,61 @@ if ( !$failure ) { } $failure = true; } - echo '
$amenityData: ' . print_r( $amenityData, true ) . '
'; + //echo '
$amenityData: ' . print_r( $amenityData, true ) . '
'; } } // 5. Get categories +// Setup three main level categories +// Brands, Manufactures, and Classes +function addNewCategory( $wpdb, $name, $parent ) +{ + // check to see if the category already exists + $catId = $wpdb->get_var( + $wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories + WHERE name = %s + AND parent = %d", + $name, + $parent + ) + ); + if ( $catId ) { + return $catId; + } else { + // Add the category + $wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'categories', + array( + 'name' => $name, + 'descr' => '', + 'short_descr' => '', + 'parent' => $parent + ), + array( + '%s', + '%s', + '%s', + '%d', + ) + ); + return $wpdb->insert_id; + } +} +if ( !$failure ) { + // Add new main level for Brands + $brandId = addNewCategory( $this->wpdb, 'Brands', 0 ); + echo '
$brandId: ' . print_r( $brandId, true ) . '
'; + // Get all Brands and add them as sub categories + $sql = " + SELECT id,name + FROM brands + ORDER BY id"; + $res = pg_query( $db, $sql ); + $rows = pg_num_rows( $res ); + if ( $rows == 0 ) { + + } +} // 6. Get category member relation data -- 2.17.1