From dec56918c3a126b5c78178ea6046b021c8724e4e Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Dec 2017 11:59:38 -0500 Subject: [PATCH 1/3] tweet db insert --- www/README.md | 3 +- www/application/config/database.php | 5 ++- www/application/controllers/User_Tweets.php | 34 ++++------------ www/application/models/User_Tweets_Model.php | 43 +++++++++++--------- www/application/views/formsuccess.php | 2 - www/application/views/user.php | 34 +--------------- 6 files changed, 37 insertions(+), 84 deletions(-) diff --git a/www/README.md b/www/README.md index 6a36455..bbd921e 100644 --- a/www/README.md +++ b/www/README.md @@ -7,8 +7,7 @@ For your final project you will work in teams of 2 to build a fully-functioning 2. Login (session management) 3. User profile page with the users’ tweets. 4. View tweets from all users. -5. Ability to “Like” tweets when logged-in -6. Ability to search all tweets. +5. Ability to search all tweets. ### Optional Features 1. DMs diff --git a/www/application/config/database.php b/www/application/config/database.php index 6c634b5..4d3bb20 100755 --- a/www/application/config/database.php +++ b/www/application/config/database.php @@ -70,7 +70,10 @@ | The $query_builder variables lets you determine whether or not to load | the query builder class. */ -$active_group = 'default'; +if ($_SERVER['HTTP_HOST'] == 'web.digitalmediauconn.org') + $active_group = 'production'; +else $active_group = 'default'; + $query_builder = TRUE; $db['default'] = array( diff --git a/www/application/controllers/User_Tweets.php b/www/application/controllers/User_Tweets.php index 870d5f8..e5b6fb6 100644 --- a/www/application/controllers/User_Tweets.php +++ b/www/application/controllers/User_Tweets.php @@ -4,38 +4,18 @@ class User_Tweets extends CI_Controller { function __Construct(){ - parent::__Construct (); -<<<<<<< HEAD - //$this->load->library('session'); -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238 - $this->load->database(); // load database - $this->load->model('User_Tweets_Model'); // load model - $this->output->enable_profiler(TRUE); + parent::__Construct(); + //$this->load->library('session'); + $this->load->database(); // load database + $this->load->model('User_Tweets_Model'); // load model + $this->output->enable_profiler(TRUE); } public function index() { -<<<<<<< HEAD - // load form to tweet - $this->load->helper(array('form', 'url')); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('tweet', 'Tweet', 'required'); - - if ($this->form_validation->run() == FALSE) - $this->load->view('user_tweets'); - echo "false"; - else { - $this->Users_Tweets_Model->addTweet(); - $this->load->view('formsuccess'); - } - - - $this->data['posts'] = $this->Users_Tweets_Model->getPosts(); // calling Post model method getPosts() -======= $this->data['posts'] = $this->User_Tweets_Model->getPosts(); // calling Post model method getPosts() ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238 + $this->load->view('templates/header', NULL); $this->load->view('user', $this->data); // load the view file , we are passing $data array to view file + $this->load->view('templates/footer', NULL); } } diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index f7211f3..d9eb2f4 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -1,32 +1,37 @@ db->select("first_name, last_name, username, tweet, date_time"); + $this->db->from('Users, Tweets'); + $this->db->where('Users.id = Tweets.user_id'); + $this->db->order_by('date_time', 'DESC'); + $query = $this->db->get(); + return $query->result_array(); + } - public function __construct() - { - $this->load->database(); - } - function getPosts(){ -<<<<<<< HEAD:www/application/models/Users_Tweets_Model.php + function addTweet(){ + $this->load->helper('url'); - //$_SESSION['user_id'] = $id; -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238:www/application/models/User_Tweets_Model.php + $slug = url_title($this->input->post('title'), 'dash', TRUE); + $data = array( + 'id' => 500, + 'tweet' => $this->input->post('tweet'), + 'date_time' => 10, + 'user_id' => 1 + ); - $this->db->select("first_name, last_name, username, tweet, date_time"); - $this->db->from('Users, Tweets'); - $this->db->where('Users.id = Tweets.user_id'); - $this->db->order_by('date_time', 'DESC'); - $query = $this->db->get(); - return $query->result_array(); - } + return $this->db->insert('Tweets', $data); - function addTweet(){ + /* $this->load->helper('url'); $data = array( 'tweet' => $this->input->post('tweet') ); + + return $this->db->insert('tweets', $data); + */ } } -?> diff --git a/www/application/views/formsuccess.php b/www/application/views/formsuccess.php index eb2f877..ac1472b 100644 --- a/www/application/views/formsuccess.php +++ b/www/application/views/formsuccess.php @@ -1,3 +1 @@

Your form was successfully submitted!

- -

diff --git a/www/application/views/user.php b/www/application/views/user.php index d8f59ca..bcf8f1e 100644 --- a/www/application/views/user.php +++ b/www/application/views/user.php @@ -1,34 +1,5 @@ - - - - - User Tweets - - - - +

Tweets Feed

- load->library('form_validation'); - echo validation_errors(); - echo form_open('user_tweets'); ?> - -
-
-
-
Tweet
- - - -
- - - -
@@ -43,6 +14,3 @@
- - - From c35b8bbd662df887053ea874353399fd9020f09b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Dec 2017 12:29:38 -0500 Subject: [PATCH 2/3] registration --- www/application/controllers/Register.php | 14 +++++++++++--- www/application/models/User_Tweets_Model.php | 1 - www/application/views/register.php | 14 +++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/www/application/controllers/Register.php b/www/application/controllers/Register.php index 7ff25a4..a9f7707 100644 --- a/www/application/controllers/Register.php +++ b/www/application/controllers/Register.php @@ -1,18 +1,25 @@ load->database(); // load database + $this->load->model('User_Info_Model'); // load model + $this->output->enable_profiler(TRUE); + } + public function index(){ $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); - $this->form_validation->set_rules('name', 'Name', 'required'); + $this->form_validation->set_rules('firstname', 'First Name', 'required'); + $this->form_validation->set_rules('lastname', 'Last Name', 'required'); + $this->form_validation->set_rules('location', 'Location', 'required'); $this->form_validation->set_rules('email', 'Email', 'required'); $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required', array('required' => 'You must provide a %s.')); - $this->form_validation->set_rules('email', 'Email', 'required'); - $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); if ($this->form_validation->run() == FALSE) @@ -21,6 +28,7 @@ public function index(){ // load the homepage once properly submitted // https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods else { + $this->User_Info_Model->addUser(); $this->load->view('formsuccess'); } } diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index d9eb2f4..6292bf0 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -16,7 +16,6 @@ function addTweet(){ $slug = url_title($this->input->post('title'), 'dash', TRUE); $data = array( - 'id' => 500, 'tweet' => $this->input->post('tweet'), 'date_time' => 10, 'user_id' => 1 diff --git a/www/application/views/register.php b/www/application/views/register.php index 82111bb..cb638b4 100644 --- a/www/application/views/register.php +++ b/www/application/views/register.php @@ -3,14 +3,22 @@ echo validation_errors(); echo form_open('register'); ?> -
Name
- - +
First Name
+ + + +
Last Name
+ +
Email Address
+
Location
+ + +
Username
From 14377c9cbb34b522f1d6afec2b9a28c68927400a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Dec 2017 12:32:20 -0500 Subject: [PATCH 3/3] registration complete --- www/application/controllers/User_Tweets.php | 18 ------------------ www/application/models/User_Tweets_Model.php | 18 ------------------ 2 files changed, 36 deletions(-) diff --git a/www/application/controllers/User_Tweets.php b/www/application/controllers/User_Tweets.php index e756de0..e5b6fb6 100644 --- a/www/application/controllers/User_Tweets.php +++ b/www/application/controllers/User_Tweets.php @@ -1,4 +1,3 @@ -<<<<<<< HEAD load->database(); - $this->load->model('User_Tweets_Model'); - $this->output->enable_profiler(TRUE); - } - - public function index(){ - $this->data['posts'] = $this->Users_Tweets_Model2->getPosts(); - $this->load->view('user', $this->data); - } - } ->>>>>>> 41b5a2f810bd6d9f899d79ce9dd4069ec9f97dda diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index 3ef6c63..6292bf0 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -1,6 +1,5 @@ db->select("first_name, last_name, username, tweet, date_time"); @@ -33,22 +32,5 @@ function addTweet(){ return $this->db->insert('tweets', $data); */ } -======= - - function getPosts(){ - - //$this->load->library('session'); - //session_start(); - $user_id = 1; //$this->session->userdata('session_id'); - - $this->db->select("first_name, last_name, username, tweet, date_time, location"); - $this->db->from("Users, Tweets"); - $this->db->where("Users.id = Tweets.user_id and Users.id = $user_id"); - $this->db->order_by('date_time', 'DESC'); - $query = $this->db->get(); - return $query->result_array(); - } - ->>>>>>> 41b5a2f810bd6d9f899d79ce9dd4069ec9f97dda }