Work on categories
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 4 Apr 2017 19:00:33 +0000 (15:00 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 4 Apr 2017 19:00:33 +0000 (15:00 -0400)
Setup category import sql

models/admin/management/import/brewbakersImport.php

index 0f6b6eb..55e7d16 100644 (file)
@@ -3,12 +3,14 @@
 echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
 
 // 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 '<pre>$amenities: ' . print_r( $amenities, true ) . '</pre>';
+        //echo '<pre>$amenities: ' . print_r( $amenities, true ) . '</pre>';
     }
 }
 // 4. Get amenity member relation data
@@ -127,9 +129,61 @@ if ( !$failure ) {
             }
             $failure = true;
         }
-        echo '<pre>$amenityData: ' . print_r( $amenityData, true ) . '</pre>';
+        //echo '<pre>$amenityData: ' . print_r( $amenityData, true ) . '</pre>';
     }
 }
 // 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 '<pre>$brandId: ' . print_r( $brandId, true ) . '</pre>';
+    // 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