<commit_before><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *COPYRIGHT (C) 2016 Campfire. All Rights Reserved.
 * User_model.php is the model for the user
 * Solves SE165 Semester Project Fall 2016
 * @author <NAME>, <NAME>, <NAME>, <NAME>,
 *     <NAME>, <NAME>, <NAME>, <NAME>
*/
class User_model extends CI_Model {

	// constructor for the user_model
	function __construct() {
		parent::__construct();
	}

	// get user for for login validation
	function get_user($email, $pwd) {
		$this->db->where('user_email', $email);
		$this->db->where('user_password', md5($pwd));
		$query = $this->db->get('user');
		return $query->result();
	}

	// get user by ID
	function get_user_by_id($id) {
		$this->db->where('user_id', $id);
		$query = $this->db->get('user');
		return $query->result();
	}

	// insert new user into DB
	function insert_user($user_data, $location_data) {
		// insert values into user and get the user ID
		$user_success = $this->db->insert('user', $user_data);
		$user_id = $this->db->insert_id();
		//Check if location is in database
		$this->db->start_cache();
		$this->db->where('zipcode', $location_data['zipcode']);
		$this->db->where('address_one', '');
		$this->db->where('address_two', '');
		$query = $this->db->get('location');
		$this->db->stop_cache();
		$this->db->flush_cache();
		//If location isnt in database yet
		if ($query->num_rows() == 0){
			// insert values into location and get the location ID
			$location_success = $this->db->insert('location', $location_data);
			$location_id = $this->db->insert_id();
		} else {
			$locResult = $query->result();
			$location_id = $locResult[0]->location_id;
			$location_success = TRUE;
		}
		// Create array of id_data to insert in DB
		$id_data = array(
			'user_id' => $user_id,
			'location_id' => $location_id
		);
		// Call function to insert user_id and location_id into DB
		$id_success = $this->insert_ids($id_data);
		// return true only if all inserts were successful
		return ($user_success && $location_success && $id_success);
	}

	// updates user and location in DB
	function update_user($user_id, $user_data, $location_data) {
		//update user table with new values
		try {
		$this->db->start_cache();
		$this->db->where('user_id', $user_id);
		$user_succes = $this->db->update('user', $user_data);
		$this->db->stop_cache();
		$this->db->flush_cache();
		//Update user location with new value

		//Check if location is in database
		$this->db->start_cache();
		$this->db->where('zipcode', $location_data['zipcode']);
		$this->db->where('street', '');
		$query = $this->db->get('location');
		$this->db->stop_cache();
		$this->db->flush_cache();

		//If location isnt in database yet
		if ($query->num_rows() == 0){
			$this->db->insert('location', $location_data);
		}
		//update the user location table
		$location_success = $this->db->query('UPDATE user_location
							INNER JOIN location
							ON user_location.user_id = '.$user_id.'
							AND location.zipcode = '.$location_data['zipcode'].'
							SET user_location.location_id = location.location_id');

		return true;
		} catch (Exception $e){
			return false;
		}

	}
<commit_msg>bug fix for edit profile zipcode<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *COPYRIGHT (C) 2016 Campfire. All Rights Reserved.
 * User_model.php is the model for the user
 * Solves SE165 Semester Project Fall 2016
 * @author <NAME>, <NAME>, <NAME>, <NAME>,
 *     <NAME>, <NAME>, <NAME>, <NAME>
*/
class User_model extends CI_Model {

	// constructor for the user_model
	function __construct() {
		parent::__construct();
	}

	// get user for for login validation
	function get_user($email, $pwd) {
		$this->db->where('user_email', $email);
		$this->db->where('user_password', <PASSWORD>($pwd));
		$query = $this->db->get('user');
		return $query->result();
	}

	// get user by ID
	function get_user_by_id($id) {
		$this->db->where('user_id', $id);
		$query = $this->db->get('user');
		return $query->result();
	}

	// insert new user into DB
	function insert_user($user_data, $location_data) {
		// insert values into user and get the user ID
		$user_success = $this->db->insert('user', $user_data);
		$user_id = $this->db->insert_id();
		//Check if location is in database
		$this->db->start_cache();
		$this->db->where('zipcode', $location_data['zipcode']);
		$this->db->where('address_one', '');
		$this->db->where('address_two', '');
		$query = $this->db->get('location');
		$this->db->stop_cache();
		$this->db->flush_cache();
		//If location isnt in database yet
		if ($query->num_rows() == 0){
			// insert values into location and get the location ID
			$location_success = $this->db->insert('location', $location_data);
			$location_id = $this->db->insert_id();
		} else {
			$locResult = $query->result();
			$location_id = $locResult[0]->location_id;
			$location_success = TRUE;
		}
		// Create array of id_data to insert in DB
		$id_data = array(
			'user_id' => $user_id,
			'location_id' => $location_id
		);
		// Call function to insert user_id and location_id into DB
		$id_success = $this->insert_ids($id_data);
		// return true only if all inserts were successful
		return ($user_success && $location_success && $id_success);
	}

	// updates user and location in DB
	function update_user($user_id, $user_data, $location_data) {
		//update user table with new values
		try {
		$this->db->start_cache();
		$this->db->where('user_id', $user_id);
		$user_succes = $this->db->update('user', $user_data);
		$this->db->stop_cache();
		$this->db->flush_cache();
		//Update user location with new value

		//Check if location is in database
		$this->db->start_cache();
		$this->db->where('zipcode', $location_data['zipcode']);
		$this->db->where('address_one', '');
		$this->db->where('address_two', '');
		$query = $this->db->get('location');
		$this->db->stop_cache();
		$this->db->flush_cache();

		//If location isnt in database yet
		if ($query->num_rows() == 0){
			$this->db->insert('location', $location_data);
		}
		//update the user location table
		$location_success = $this->db->query('UPDATE user_location
							INNER JOIN location
							ON user_location.user_id = '.$user_id.'
							AND location.zipcode = '.$location_data['zipcode'].'
							SET user_location.location_id = location.location_id');

		return true;
		} catch (Exception $e){
			return false;
		}

	}

{'fraction_non_alphanumeric': 0.18157730673316708, 'fraction_numerical': 0.00451995012468828, 'mean_word_length': 3.989891135303266, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 156, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6253879', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2147, 'n_words': 534}