Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Shemona Singh authored and Shemona Singh committed Dec 5, 2017
2 parents 837ee50 + ff4ff6e commit a0ba5f6
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 86 deletions.
10 changes: 10 additions & 0 deletions www/application/controllers/All_Tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ function __Construct(){

public function index() {
$this->data['posts'] = $this->All_Tweets_Model->getPosts(); // calling Post model method getPosts()

$this->load->view('templates/header', NULL);
$this->load->view('home', $this->data); // load the view file , we are passing $data array to view file
$this->load->view('templates/footer', NULL);
}

function search_keyword(){
$keyword = $this->input->post('keyword');
$data['results'] = $this->All_Tweets_Model->search($keyword);

$this->load->view('templates/header');
$this->load->view('home', $data); // load the view file , we are passing $data array to view file
$this->load->view('templates/footer');
}

}
20 changes: 18 additions & 2 deletions www/application/controllers/Login.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

class Login extends CI_Controller {
function __Construct(){
parent::__Construct();
$this->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('username', 'Username', 'required');
Expand All @@ -15,7 +21,17 @@ public function index(){
// load the homepage if login successful
// https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods
else {
$this->load->view('formsuccess');
//check if user in db
$user = $this->User_Info_Model->isRegistered();

// if yes get user id, launch session, send to home
if($user !== []){
$data['user'] = $user;
redirect('/all_tweets');
}
// if no, refresh login
else $this->load->view('login', $data);

}
}
}
4 changes: 3 additions & 1 deletion www/application/controllers/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public function index(){

// load the homepage once properly submitted
// https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods

// add user to db, launch session, send to home
else {
$this->User_Info_Model->addUser();
$this->load->view('formsuccess');
redirect('/all_tweets');
}
}
}
20 changes: 20 additions & 0 deletions www/application/controllers/User_Tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ public function index() {
$this->load->view('templates/footer', NULL);
}

public function create(){
$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->data['posts'] = $this->User_Tweets_Model->getPosts(); // calling Post model method getPosts()
$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);
}
else
{
$this->User_Tweets_Model->addTweet();
redirect("/user_tweets");
}

}

}
10 changes: 10 additions & 0 deletions www/application/models/All_Tweets_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ function getPosts(){
return $query->result_array();
}

function search($keyword){
$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');
$this->db->like('tweet', $keyword);
$query = $this->db->get();
return $query->result_array();
}

}
?>
16 changes: 16 additions & 0 deletions www/application/models/Search_Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
Class Search_Model Extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database(); // load database
}

function search($keyword)
{
$this->db->like('tweet', $keyword);
$query = $this->db->get('Tweets');
return $query->result();
}
}
13 changes: 11 additions & 2 deletions www/application/models/User_Info_Model.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?php
class User_Info_Model extends CI_Model {
// login
function getUserID(){
function isRegistered(){
$username = $this->input->post('username');
$password = $this->input->post('password');

$this->db->select('*');
$this->db->from('Users');
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
// new user
// register
function addUser(){
$this->load->helper('url');

Expand Down
32 changes: 9 additions & 23 deletions www/application/models/User_Tweets_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,13 @@ function getPosts(){
return $query->result_array();
}

function addTweet(){
$this->load->helper('url');

$slug = url_title($this->input->post('title'), 'dash', TRUE);

$data = array(
'tweet' => $this->input->post('tweet'),
'date_time' => 10,
'user_id' => 1
);

return $this->db->insert('Tweets', $data);

/*
$this->load->helper('url');
$data = array(
'tweet' => $this->input->post('tweet')
);
return $this->db->insert('tweets', $data);
*/
}

function addTweet(){
$this->load->helper('url');
$data = array(
'tweet' => $this->input->post('tweet'),
'user_id' => 2 // UPDATE THIS WITH SESSION DATA
);

return $this->db->insert('Tweets', $data);
}
}
36 changes: 35 additions & 1 deletion www/application/views/home.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
error_reporting(0);

// shouldn't need the title and links below
?>

<title>Twitter Clone</title>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">

<div class="home container">
<h1>All Tweets</h1>
<?php foreach($posts as $post){?>

<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('all_tweets/search_keyword'); ?>
<input type="text" name = "keyword" />
<input type="submit" value = "Search" />
</form>

<?php foreach($results as $row){ ?>
<div class="tweet-container">
<div class="row">
<div class="col-md-6">
<?php echo "<h3>" . $row['first_name'] . " " . $row['last_name'] . "</h3>"; ?>
<?php echo "<h4>" . "@" . $row['username'] . "</h4>";?>
</div>
<div class="col-md-3 date">
<?php echo $row['date_time'];?>
</div>
</div>
<div class="row tweet italic">
<div class="col-md-12">
<?php echo "\"" . $row['tweet'] . "\"";?>
</div>
</div>
</div>
<?php } ?>

<?php foreach($posts as $post){ ?>
<div class="tweet-container">
<div class="row">
<div class="col-md-6">
Expand Down
31 changes: 14 additions & 17 deletions www/application/views/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
$this->load->library('form_validation');
echo validation_errors();
echo form_open('login'); ?>
<?php
var_dump($user);
?>

<div class="container">
<div class="row">
<div class="col-md-2 col-md-offset-5">
<h1>Twitter</h1>
<img src="../img/twitter.png" alt="Twitter icon.">
<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<?php echo form_error('username'); ?>
<h1>Twitter</h1>
<!--<img src="../img/twitter.png" alt="Twitter icon.">-->
<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<?php echo form_error('username'); ?>

<h5>Password</h5>
<input type="password" name="password" value="<?php echo set_value('password'); ?>" size="50" />
<?php echo form_error('password'); ?>
<h5>Password</h5>
<input type="password" name="password" value="<?php echo set_value('password'); ?>" size="50" />
<?php echo form_error('password'); ?>

<br><br>
<div><input class="btn" type="submit" value="Submit"/></div>
</form>
</div>
</div>
</div>
<br><br>
<div><input type="submit" value="Submit"/></div>
</form>
1 change: 0 additions & 1 deletion www/application/views/profile.php

This file was deleted.

2 changes: 1 addition & 1 deletion www/application/views/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$this->load->library('form_validation');
echo validation_errors();
echo form_open('register'); ?>

<h1>Register</h1>
<h5>First Name</h5>
<input type="text" name="firstname" value="<?php echo set_value('firstname'); ?>" size="50" />
<?php echo form_error('firstname'); ?>
Expand Down
2 changes: 1 addition & 1 deletion www/application/views/templates/footer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<em>&copy; 2017 Stumper and Singh Studios</em>
<em>&copy; 2017 Singh and Stumper Studios</em>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</body>
Expand Down
14 changes: 7 additions & 7 deletions www/application/views/templates/header.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>

<html lang="en">
<head>
<title>Twitter Clone</title>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<meta charset="utf-8">
</head>
<body>
<head>
<title>Twitter Clone</title>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<meta charset="utf-8">
</head>
<body>
19 changes: 5 additions & 14 deletions www/application/views/tweet.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('tweet'); ?>

<h2><?php echo $title; ?></h2>

<div class="container">
<div class="row">
<div class="col-md-2 col-md-offset-5">
<h5>Tweet</h5>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50" />
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input class="btn" type="submit" value="Submit"/></div>
</div>
</div>
</div>
<h5>Tweet</h5>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50" />
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input type="submit" value="Submit"/></div>
</form>
48 changes: 32 additions & 16 deletions www/application/views/user.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<h1>Tweets Feed</h1>
<div class="container">
<div class="row">
<?php foreach($posts as $post){?>
<div class="col-md-4">
<?php echo $post['first_name'];?>
<?php echo $post['last_name'];?>
<?php echo $post['username'];?>
</div>
<div class="col-md-8">
<?php echo $post['tweet'];?>
<?php echo $post['date_time'];?>
</div>
<?php }?>
</div>
</div>
<div class="home container">
<h1>My Tweets</h1>

<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('user_tweets/create'); ?>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50"/>
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input type="submit" value="Tweet"/></div>
</form>


<?php foreach($posts as $post){ ?>
<div class="tweet-container">
<div class="row">
<div class="col-md-6">
<?php echo "<h3>" . $post['first_name'] . " " . $post['last_name'] . "</h3>"; ?>
<?php echo "<h4>" . "@" . $post['username'] . "</h4>";?>
</div>
<div class="col-md-3 date">
<?php echo $post['date_time'];?>
</div>
</div>
<div class="row tweet italic">
<div class="col-md-12">
<?php echo "\"" . $post['tweet'] . "\"";?>
</div>
</div>
</div>
<?php }?>
</div>

0 comments on commit a0ba5f6

Please sign in to comment.