/** * This function will be the hook that is called after a student public form * entry is made. This is to get all information from the student form and * make updates in the teacher master and the student master form. * * This can be used as such: * add_action( * 'gform_after_submission_x', 'aria_after_student_submission', 10, 2); * * @param $form GF Forms Object The form this function is attached to. * @param $entry GF Entry Object The entry that is returned after form submission. * * @since 1.0.0 * @author KREW */ public static function aria_after_student_submission($entry, $form) { if (!array_key_exists('isStudentPublicForm', $form) || !$form['isStudentPublicForm']) { return; } // Find common title and get the forms that are related to this form $prepended_comp_title = ARIA_API::aria_parse_form_name_for_title($form["title"]); $related_forms = $form['aria_relations']; // Find out the information associated with the $entry variable $student_fields = ARIA_Create_Competition::aria_student_field_id_array(); $teacher_master_fields = ARIA_Create_Master_Forms::aria_master_teacher_field_id_array(); $student_master_fields = ARIA_Create_Master_Forms::aria_master_student_field_id_array(); // Hash for teacher (just has the teacher name) $teacher_name = $entry[(string) $student_fields["teacher_name"]]; $teacher_hash = hash("md5", $teacher_name); // Hash for student (student name and entry date) $student_name_and_entry = $entry[(string) $student_fields["student_first_name"]]; $student_name_and_entry .= $entry[(string) $student_fields["student_last_name"]]; $student_name_and_entry .= $entry["date_created"]; $student_hash = hash("md5", $student_name_and_entry); // // Search through the teacher form to see if the teacher has an entry made // $teacher_entry = ARIA_Registration_Handler::aria_find_teacher_entry($form["title"], $teacher_hash); // $teacher_master_fields = ARIA_Create_Master_Forms::aria_master_teacher_field_id_array(); // // If the teacher exists, add the student hash to the students array // if ($teacher_entry !== false) { // $teacher_entry[(string) $teacher_master_fields["students"]][] = $student_hash; // } // // // If not make a new entry in the form // if (!$teacher_exists) { // $new_teacher_entry = array(); // $new_teacher_entry[] = array ( // (string) $teacher_master_fields["name"] => $entry[(string) $student_fields["not_listed_teacher_name"]], // (string) $teacher_master_fields["email"] => null, // (string) $teacher_master_fields["phone"] => null, // (string) $teacher_master_fields["volunteer_preference"] => null, // (string) $teacher_master_fields["volunteer_time"] => null, // (string) $teacher_master_fields["students"] => array($student_hash), // (string) $teacher_master_fields["is_judging"] => null, // (string) $teacher_master_fields["hash"] => null // ); // $teacher_result = GFAPI::add_entries($new_teacher_entry, $related_forms[ARIA_Registration_Handler::$TEACHER_FORM]); // if (is_wp_error($teacher_result)) { // wp_die($teacher_result->get_error_message()); // } // } // Make a new student master entry with the student hash $new_student_master_entry = array(array((string) $student_master_fields["parent_email"] => $entry[(string) $student_fields["parent_email"]], (string) $student_master_fields["student_birthday"] => $entry[(string) $student_fields["student_birthday"]], (string) $student_master_fields["teacher_name"] => $entry[(string) $student_fields["teacher_name"]], (string) $student_master_fields["not_listed_teacher_name"] => $entry[(string) $student_fields["not_listed_teacher_name"]], (string) $student_master_fields["available_festival_days"] => $entry[(string) $student_fields["available_festival_days"]], (string) $student_master_fields["preferred_command_performance"] => $entry[(string) $student_fields["preferred_command_performance"]], (string) $student_master_fields["song_1_period"] => $entry[(string) $student_fields["song_1_period"]], (string) $student_master_fields["song_1_composer"] => $entry[(string) $student_fields["song_1_composer"]], (string) $student_master_fields["song_1_selection"] => $entry[(string) $student_fields["song_1_selection"]], (string) $student_master_fields["song_2_period"] => $entry[(string) $student_fields["song_2_period"]], (string) $student_master_fields["song_2_composer"] => $entry[(string) $student_fields["song_2_composer"]], (string) $student_master_fields["song_2_selection"] => $entry[(string) $student_fields["song_2_selection"]], (string) $student_master_fields["theory_score"] => $entry[(string) $student_fields["theory_score"]], (string) $student_master_fields["alternate_theory"] => $entry[(string) $student_fields["alternate_theory"]], (string) $student_master_fields["competition_format"] => $entry[(string) $student_fields["competition_format"]], (string) $student_master_fields["timing_of_pieces"] => $entry[(string) $student_fields["timing_of_pieces"]], (string) $student_master_fields["hash"] => $student_hash)); $student_result = GFAPI::add_entries($new_student_master_entry, $related_forms['student_master_form_id']); if (is_wp_error($student_result)) { wp_die($student_result->get_error_message()); } }
/** * This function will create new registration forms for students and parents. * * This function is responsible for creating new registration forms for both * students and parents. This function will only create new registration forms * for students and parents if it is used ONLY in conjunction with the form * used to create new music competitions. * * @param Entry Object $entry The entry that was just submitted * @param Form Object $form The form used to submit entries * * @since 1.0.0 * @author KREW */ public static function aria_create_teacher_and_student_forms($confirmation, $form, $entry, $ajax) { // make sure the create competition form is calling this function $competition_creation_form_id = ARIA_API::aria_get_create_competition_form_id(); if ($form['id'] === $competition_creation_form_id) { /* Calls wp_die and returns a value of 86? self::aria_update_page_ids(); */ $field_mapping = self::aria_get_competition_entry_meta(); $competition_name = $entry[$field_mapping['Name of Competition']]; // create the student and teacher forms $student_form_id = self::aria_create_student_form($entry); $teacher_form_id = self::aria_create_teacher_form($entry, unserialize($entry[(string) $field_mapping['Volunteer Times']])); $student_form_url = self::aria_publish_form("{$competition_name} Student Registration", $student_form_id); $teacher_form_url = self::aria_publish_form("{$competition_name} Teacher Registration", $teacher_form_id); // create the sutdent and teacher (master) forms $student_master_form_id = ARIA_Create_Master_Forms::aria_create_student_master_form($competition_name); $teacher_master_form_id = ARIA_Create_Master_Forms::aria_create_teacher_master_form($competition_name); $related_forms = array('student_public_form_id' => $student_form_id, 'teacher_public_form_id' => $teacher_form_id, 'student_master_form_id' => $student_master_form_id, 'teacher_master_form_id' => $teacher_master_form_id, 'student_public_form_url' => $student_form_url, 'teacher_public_form_url' => $teacher_form_url); $student_public_form = GFAPI::get_form($student_form_id); $teacher_public_form = GFAPI::get_form($teacher_form_id); $student_master_form = GFAPI::get_form($student_master_form_id); $teacher_master_form = GFAPI::get_form($teacher_master_form_id); $student_public_form['aria_relations'] = $related_forms; $teacher_public_form['aria_relations'] = $related_forms; $student_master_form['aria_relations'] = $related_forms; $teacher_master_form['aria_relations'] = $related_forms; GFAPI::update_form($student_public_form); GFAPI::update_form($teacher_public_form); GFAPI::update_form($student_master_form); GFAPI::update_form($teacher_master_form); $teacher_public_form = GFAPI::get_form($teacher_form_id); $confirmation = 'Congratulations! A new music competition has been '; $confirmation .= 'created. The following forms are now available for '; $confirmation .= ' students and teachers to use for registration: </br>'; $confirmation .= "<a href={$student_form_url}>{$competition_name} Student Registration</a>"; $confirmation .= " was published. </br>"; $confirmation .= "<a href={$teacher_form_url}> {$competition_name} Teacher Registration </a>"; $confirmation .= " was published."; return $confirmation; } else { wp_die("ERROR: No form currently exists that allows the festival chairman\n to create a new music competition \n FormID: {$form[id]} \n func_call {$competition_creation_form_id}"); } }
/** * This function will parse the contents of the csv file and upload content to * the NNMTA music database. * * Using the csv file that the user has uploaded, this function will parse * through the music content for each song and add it to the NNMTA music * database. * * @param Entry Object $entry The entry object from the upload form. * @param Form Object $form The form object that contains $entry. * * @since 1.0.0 * @author KREW */ public static function aria_add_music_from_csv($entry, $form) { // check if the form for uploading exists $music_db_form_id = ARIA_API::aria_get_nnmta_database_form_id(); if ($music_db_form_id === -1) { self::aria_create_nnmta_music_form(); } $num_song_elements_no_catalog = 5; $num_song_elements_with_catalog = $num_song_elements_no_catalog + 1; $num_songs = 0; // locate the full path of the csv file $csv_music_file = ARIA_API::aria_get_music_csv_file_path($entry, $form); //wp_die("Music file path: " . $csv_music_file); // parse csv file and add all music data to an array $all_songs = array(); if (($file_ptr = fopen($csv_music_file, "r")) !== FALSE) { // remove all data that is already in the database //aria_remove_all_music_from_nnmta_database(); // add new music while (($single_song_data = fgetcsv($file_ptr, 1000, ",")) !== FALSE) { $single_song = array(); for ($i = 1; $i <= 5; $i++) { //count($single_song_data); $i++) { $single_song[strval($i)] = $single_song_data[$i - 1]; } $all_songs[] = $single_song; /* // no catalog if (count($single_song_data) === $num_song_elements_no_catalog) { $all_songs[] = array ( '1' => $single_song_data[0], '2' => $single_song_data[1], '3' => $single_song_data[2], '4' => $single_song_data[3], '5' => $single_song_data[4], ); } // with catalog elseif (count($single_song_data) === $num_song_elements_with_catalog) { $all_songs[] = array ( '1' => $single_song_data[0], '2' => $single_song_data[1], '3' => $single_song_data[2], '4' => $single_song_data[3], '5' => $single_song_data[4], '6' => $single_song_data[5], ); } */ } } else { wp_die("Error: File named " . $csv_music_file . " does not exist."); } //wp_die(print_r($all_songs)); // add all song data from array into the database $new_song_ids = GFAPI::add_entries($all_songs, ARIA_API::aria_get_nnmta_database_form_id()); if (is_wp_error($new_song_ids)) { wp_die($new_song_ids->get_error_message()); } // remove filename from upload folder //print_r($all_songs); unlink($csv_music_file); unset($all_songs); }
/** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Plugin_Name_Loader. Orchestrates the hooks of the plugin. * - Plugin_Name_i18n. Defines internationalization functionality. * - Plugin_Name_Admin. Defines all hooks for the admin area. * - Plugin_Name_Public. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-aria-loader.php'; $this->loader = new ARIA_Loader(); /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-plugin-name-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-plugin-name-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-aria-public.php'; // Include all of the ARIA files needed as dependencies. require_once "class-aria-create-competition.php"; require_once "class-aria-music.php"; require_once "class-aria-form-hooks.php"; // Register all of the hooks needed by ARIA // Creating student and teacher forms /* !!! like below, this might not work if aria_get_create_competition_form_id returns a value of -1. !!! */ $this->loader->add_action('gform_confirmation_' . strval(ARIA_API::aria_get_create_competition_form_id()), 'ARIA_Create_Competition', 'aria_create_teacher_and_student_forms', 10, 4); $this->loader->add_action('gform_after_submission', 'ARIA_Form_Hooks', 'aria_after_student_submission', 10, 2); // Adding music upload/download functionality $this->loader->add_action('gform_after_submission_' . strval(ARIA_API::aria_get_song_upload_form_id()), 'ARIA_Music', 'aria_add_music_from_csv', 10, 2); // For before/after student and teacher registration /* note: these values are hardcoded for now can't do this here because we do not know the form ID of the student form before the create competition functionality is invoked */ /* $this->loader->add_action('gform_after_submission_292', 'ARIA_Form_Hooks', 'aria_after_student_submission', 10, 2); */ // Modifying the upload path $this->loader->add_filter('gform_upload_path', 'ARIA_Music', 'aria_modify_upload_path', 10, 2); }