/** * Loop through a $question['mc_option'] array to save to the db * * @param $mc_option = array(); of all question['mc_option'] data * @since 0.0.1 */ protected function save_mc_options($mc_options) { if (!empty($mc_options)) { // loop through the questions and save each one foreach ($mc_options as $mc_option) { // create a new object $mc_option_obj = new Enp_quiz_Save_mc_option(); // pass to save_mc_options so we can decide // if we should insert or update the mc_option $mc_option_obj->save_mc_option($mc_option); } } }
/** * Save a mc_option array in the database * Often used in a foreach loop to loop over all mc_options * If ID is passed, it will update that ID. * If no ID or ID = 0, it will insert * * @param $mc_option = array(); of mc_option data * @return ID of saved mc_option or false if error * @since 0.0.1 */ protected function save_mc_option($mc_option) { self::$mc_option = $mc_option; // check to see if the id exists if (self::$mc_option['mc_option_id'] === 0) { // It doesn't exist yet, so insert it! $this->insert_mc_option(); } else { // we have a mc_option_id, so update it! $this->update_mc_option(); } }