From d656ea72fc333bad0d4f90e373cd024db3fe1bb1 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 24 Jan 2018 14:57:58 -0500 Subject: [PATCH] Add video import file. Adding ability to import for the member videos. --- models/admin/import/index.php | 98 ++++++++++++++++++++++++++ views/admin/import/header.html | 3 + views/admin/import/videos.html | 45 ++++++++++++ views/admin/import/videosProcess.html | 24 +++++++ views/admin/import/videosValidate.html | 32 +++++++++ 5 files changed, 202 insertions(+) create mode 100644 views/admin/import/videos.html create mode 100644 views/admin/import/videosProcess.html create mode 100644 views/admin/import/videosValidate.html diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 2ac696c7..49a49fa0 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -173,6 +173,10 @@ class GlmMembersAdmin_import_index */ public $processingComplete = false; + public $totalVideos = 0; + + public $videosProcessed = 0; + /** * Constructor * @@ -507,6 +511,77 @@ class GlmMembersAdmin_import_index $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; $clearData = ( filter_var( $_REQUEST['clear_data'], FILTER_VALIDATE_BOOLEAN ) ); + break; + + case 'videosValidate': + if ( isset( $_FILES ) ) { + move_uploaded_file( $_FILES['files_file']['tmp_name'], $uploadPath . '/videosData.csv' ); + } + if ( is_file( $uploadPath . '/videosData.csv' ) ) { + $fileExists = true; + } + // validate the header line + $fData = $this->readCSVFileHeaders( $uploadPath . '/videosData.csv' ); + $validate = array( 'member_id', 'member_name', 'video_url' ); + $isValid = ( $fData == $validate ); + // If the file validates then we're ready to process + $readyToProcess = $isValid; + // Set the view file + $view = 'videosValidate.html'; + $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; + $clearData = ( filter_var( $_REQUEST['clear_data'], FILTER_VALIDATE_BOOLEAN ) ); + break; + + case 'videosProcess': + $view = 'videosProcess.html'; + // 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 . '/videosData.csv' ) ) { + $videoData = $this->readCSVFile( $uploadPath . '/videosData.csv' ); + $this->totalVideos = count( $videoData ); + + foreach ( $videoData as $video ) { + // Get the member id for this video + $memberId = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE old_member_id = %s", + $video['member_id'] + ) + ); + if ( !$memberId ) { + var_dump( 'no member id' ); + continue; + } + // Now that we have the member id we need to get the + // id for the active member info record + $memberInfoId = $memberInfoObj->getActiveInfoIdForMember( $memberId ); + // echo '
$memberInfoId: ' . print_r( $memberInfoId, true ) . '
'; + if ( !$memberInfoId ) { + var_dump( 'no member info id' ); + continue; + } + + // check the video url to make sure it is valid + if ( $video_url = filter_var( $video['video_url'], FILTER_VALIDATE_URL ) ) { + $this->videosProcessed++; + $this->wpdb->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info', + array( 'video_url' => $video_url ), + array( 'id' => $memberInfoId ), + array( '%s' ), + array( '%d' ) + ); + // echo '
' . $video['member_name'] . ': ' . htmlspecialchars( $video['video_url'] ) .'
'; + } + } + + } + + break; case 'photosProcess': @@ -729,6 +804,27 @@ class GlmMembersAdmin_import_index } break; + case 'videos': + // Set the view file + $view = 'videos.html'; + unset( $fileData ); + if ( is_file( $uploadPath . '/videosData.csv' ) ) { + $fileExists = true; + $fileData['Videos'] = array( + 'field' => 'videos_file', + 'name' => 'videosData.csv', + 'exists' => true, + 'mtime' => filemtime( $uploadPath . '/videosData.csv' ), + ); + } else { + $fileData['Videos'] = array( + 'field' => 'videos_file', + 'name' => 'videosData.csv', + 'exists' => false, + ); + } + break; + case 'default': default: // Set the view file @@ -757,6 +853,8 @@ class GlmMembersAdmin_import_index 'totalFiles' => $this->totalFiles, 'photosProcessed' => $this->photosProcessed, 'filesProcessed' => $this->filesProcessed, + 'totalVideos' => $this->totalVideos, + 'videosProcessed' => $this->videosProcessed, 'completed' => $this->processingComplete, 'data' => false, 'fileData' => $fileData, diff --git a/views/admin/import/header.html b/views/admin/import/header.html index 0de87f73..621570d3 100644 --- a/views/admin/import/header.html +++ b/views/admin/import/header.html @@ -12,6 +12,9 @@ Import Files + Import Videos {/if} {foreach $addOnTabs as $a} diff --git a/views/admin/import/videos.html b/views/admin/import/videos.html new file mode 100644 index 00000000..e65dbc73 --- /dev/null +++ b/views/admin/import/videos.html @@ -0,0 +1,45 @@ +{include file='admin/import/header.html'} + +

Data Import: Videos

+
+ + + + + + + + + + + + {foreach $fileData as $fileHeader => $file} + + + + + + + {/foreach} + + +
File TypeNew FileSample FileCurrent FileUpdated
+ {$fileHeader} + + + + Sample {$fileHeader} File + + {if $file.exists} + {$fileHeader} File + {/if} + + {if $file.exists} + {$file.mtime|date_format:"%D %I:%M %p"} + {/if} +
+ + +
+ +{include file='admin/footer.html'} diff --git a/views/admin/import/videosProcess.html b/views/admin/import/videosProcess.html new file mode 100644 index 00000000..69e2cbd5 --- /dev/null +++ b/views/admin/import/videosProcess.html @@ -0,0 +1,24 @@ +{include file='admin/import/header.html'} + +

Data Import Step 3: Process Videos File

+ + + + + + + + + + + + + {if $errors} + {foreach $errors as $error} + {$error} + {/foreach} + {/if} + +
Total Videos{$totalVideos}
Processed Videos{$videosProcessed}
+ +{include file='admin/footer.html'} diff --git a/views/admin/import/videosValidate.html b/views/admin/import/videosValidate.html new file mode 100644 index 00000000..e9c0b096 --- /dev/null +++ b/views/admin/import/videosValidate.html @@ -0,0 +1,32 @@ +{include file='admin/import/header.html'} + +

Data Import: Videos Validation

+ + + + + + + + + {if $readyToProcess} + + + + {/if} + +
+ {if $fileExists} + videosData.csv + {/if} + + {if $isValid} + Is Valid + {else} + Not Valid + {/if} +
+ Process Files +
+ +{include file='admin/footer.html'} -- 2.17.1