*/
public $totalMembers = 0;
+ /**
+ * totalPhotos
+ *
+ * @var float
+ * @access public
+ */
+ public $totalPhotos = 0;
+
+ /**
+ * photosProcessed
+ *
+ * @var float
+ * @access public
+ */
+ public $photosProcessed = 0;
+
/**
* processingComplete
*
$option = 'default';
$clearData = false;
$haveMembers = false;
+ $fileExists = false;
// Check to see if they have members
$haveMembers = $this->wpdb->get_var(
"SELECT count(id)
if ( isset( $_FILES ) ) {
move_uploaded_file( $_FILES['photos_file']['tmp_name'], $uploadPath . '/photoData.csv' );
}
+ if ( is_file( $uploadPath . '/photoData.csv' ) ) {
+ $fileExists = true;
+ }
// validate the header line
- $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' );
- $isValid = ( $fData == array( 'member_id', 'image', 'caption' ) );
+ $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' );
+ $validate = array( 'member_id', 'image', 'caption' );
+ $isValid = ( $fData == $validate );
// If the file validates then we're ready to process
$readyToProcess = $isValid;
- $view= 'photos.html';
+ $view= 'photosValidate.html';
$fileData = '<pre>$_FILES: ' . print_r( $_FILES, true ) . '</pre>';
break;
+ case 'photosProcess':
+ // Setup the image processing
+ require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/imageUpload.php';
+ $ImageUpload = 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 . '/photoData.csv' ) ) {
+ // Get the entire photo file data
+ $photoData = $this->readCSVFile( $uploadPath . '/photoData.csv' );
+ //echo '<pre>$photoData: ' . print_r( $photoData, true ) . '</pre>';
+ $this->totalPhotos = count( $photoData );
+ $this->photosProcessed = count( $photoData );
+
+ $refType = $this->config['ref_type_numb']['MemberInfo'];
+ $refTable = $this->config['ref_type_table'][$refType];
+
+ // Loop through the photoData array
+ foreach ( $photoData as $photo ) {
+ echo '<pre>$photo: ' . print_r( $photo, true ) . '</pre>';
+ // If there's no url or the url is not valid then skip it.
+ if ( $photoUrl = filter_var( $photo['image'], FILTER_VALIDATE_URL ) ) {
+ echo '<pre>$photoUrl: ' . print_r( $photoUrl, 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",
+ $photo['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 = $ImageUpload->storeImage(
+ $photoUrl,
+ $refType,
+ $refTable,
+ $memberInfoId,
+ $photo['caption']
+ );
+ }
+
+ }
+
+ $view= 'photosProcess.html';
+ } else {
+ $view= 'photosValidate.html';
+ }
+ break;
+
case 'photos':
$view= 'photos.html';
break;
// Setup the template data array
$templateData = array(
+ 'fileExists' => $fileExists,
'option' => $option,
'errors' => $this->errors,
'numberProcessed' => $this->numberProcessed,
'totalMembers' => $this->totalMembers,
+ 'totalPhotos' => $this->totalPhotos,
+ 'photosProcessed' => $this->photosProcessed,
'completed' => $this->processingComplete,
'data' => false,
'fileData' => $fileData,
'csvData' => '<pre>$fileData: ' . print_r( $fileData, true ) . '</pre>',
'readyToProcess' => $readyToProcess,
'haveMembers' => $haveMembers,
+ 'isValid' => $isValid,
);
// Return status, suggested view, and data to controller
return array(