wip
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Jun 2017 20:07:04 +0000 (16:07 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Jun 2017 20:29:49 +0000 (16:29 -0400)
models/admin/import/index.php
views/admin/import/filesValidate.html

index 8fac51d..443560d 100644 (file)
@@ -126,6 +126,14 @@ class GlmMembersAdmin_import_index
      */
     public $totalPhotos = 0;
 
+    /**
+     * totalFiles
+     *
+     * @var float
+     * @access public
+     */
+    public $totalFiles = 0;
+
     /**
      * photosProcessed
      *
@@ -525,6 +533,72 @@ class GlmMembersAdmin_import_index
             }
             break;
 
+        case 'filesProcess':
+            // Setup the file processing
+            require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/fileUpload.php';
+            $FileUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+            // Setup the member_info class
+            require_once GLM_MEMBERS_PLUGIN_PATH .  '/classes/data/dataMemberInfo.php';
+            $memberInfoObj = new GlmDataMemberInfo( $this->wpdb, $this->config );
+
+            if ( is_file( $uploadPath . '/filesData.csv' ) ) {
+                // Get the entire files file data
+                $filesData = $this->readCSVFile( $uploadPath . '/filesData.csv' );
+                //echo '<pre>$filesData: ' . print_r( $filesData, true ) . '</pre>';
+                $this->totalFiles     = count( $filesData );
+                $this->filesProcessed = count( $filesData );
+
+                $refType = $this->config['ref_type_numb']['MemberInfo'];
+                $refTable = $this->config['ref_type_table'][$refType];
+
+                // Loop through the filesData array
+                foreach ( $filesData as $file ) {
+                    echo '<pre>$file: ' . print_r( $file, true ) . '</pre>';
+                    // If there's no url or the url is not valid then skip it.
+                    if ( $fileUrl = filter_var( $file['image'], FILTER_VALIDATE_URL ) ) {
+                        echo '<pre>$fileUrl: ' . print_r( $fileUrl, true ) . '</pre>';
+                        // Need to first get the member id from the database
+                        // It will match from the old_member_id field
+                        $memberId = $this->wpdb->get_var(
+                            $this->wpdb->prepare(
+                                "SELECT id
+                                   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                                  WHERE old_member_id = %d",
+                                $file['member_id']
+                            )
+                        );
+                        if ( !$memberId ) {
+                            continue;
+                        }
+                        echo '<pre>$memberId: ' . print_r( $memberId, true ) . '</pre>';
+                        // Now that we have the member id we need to get the
+                        // id for the active member info record
+                        $memberInfoId = $memberInfoObj->getActiveInfoIdForMember( $memberId );
+                        if ( !$memberInfoId ) {
+                            continue;
+                        }
+                        echo '<pre>$memberInfoId: ' . print_r( $memberInfoId, true ) . '</pre>';
+                        $res = $FileUpload->storeFile(
+                            $fileUrl,
+                            $refType,
+                            $refTable,
+                            $memberInfoId,
+                            $file['caption']
+                        );
+                    }
+
+                }
+
+                // Set the view file
+                $view= 'filesProcess.html';
+            } else {
+                // Set the view file
+                $view= 'filesValidate.html';
+            }
+            $view= 'filesValidate.html';
+            break;
+
         case 'photos':
             // Set the view file
             $view= 'photos.html';
@@ -591,6 +665,7 @@ class GlmMembersAdmin_import_index
             'numberProcessed' => $this->numberProcessed,
             'totalMembers'    => $this->totalMembers,
             'totalPhotos'     => $this->totalPhotos,
+            'totalFiles'      => $this->totalFiles,
             'photosProcessed' => $this->photosProcessed,
             'completed'       => $this->processingComplete,
             'data'            => false,
index 6a8acaa..1e2f502 100644 (file)
@@ -21,7 +21,7 @@
         {if $readyToProcess}
         <tr>
             <td colspan="2">
-                <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=photosFiles" class="button">Process Files</a>
+                <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=filesProcess" class="button">Process Files</a>
             </td>
         </tr>
         {/if}