Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PictureModel extends CI_Model {
- //stdClass Object ( [user_id] => 0 [comment] => Canceriuo [created] => 1447321029 )
- function getComments($id){
- $this->db->select("user_id,comment,created");
- $this->db->from('comments');
- $this->db->where('picture_id', $id);
- $query = $this->db->get();
- $result = $query->result();
- $comments = array();
- //print_r($result[2]->user_id);
- //print_r($result[1]->user_id."on tühi?");
- //print_r(count($result));
- for($i = 0; $i < count($result); ++$i){
- if($result[$i]->user_id == ''){
- $username = 'anonüümne';
- } else {
- $this->db->select('username');
- $this->db->from('users');
- $this->db->where('id', $result[$i]->user_id);
- $query = $this->db->get()->result();
- $username = $query[0]->username;
- }
- array_push($comments, array($username, $result[$i]->comment,$result[$i]->created));
- //print_r($query->result()[0]->comment);
- }
- return $comments;
- }
- function enterComment($id, $comment){
- if (! $comment == ''){
- //id, picture_id, user_id, comment
- $data = array(
- 'user_id' => $this->ion_auth->get_user_id(),
- 'comment' => $comment,
- 'picture_id' => $id,
- 'created' => time()
- );
- $this->db->insert('comments', $data);
- }
- }
- function getPicture($id){
- $this->db->select("id,title,description,location,comments_enabled");
- $this->db->from('pictures');
- $this->db->where('id', $id);
- $query = $this->db->get();
- return $query->result()[0];
- }
- function getTags($id){
- $tags = array();
- for($i = 0; $i < $this->db->get_where('pictures_tags', array('picture_id' => $id))-> num_rows(); ++$i){
- array_push($tags, ($this->db->get_where('tags', array('id' => $this->db->get_where('pictures_tags',
- array('picture_id' => $id))->result()[$i]->tag_id))->result()[0]->tag));
- }
- return $tags;
- }
- }
- ?>
- /// TEINE FAIL
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Picture extends CI_Controller {
- function __Construct(){
- parent::__Construct ();
- $this->load->model('PictureModel'); // load model
- $this->load->helper('form');
- }
- public function photo() {
- $this->data['comments'] = $this->PictureModel->getComments($this->uri->segment(2, 1));
- $this->data['picture'] = $this->PictureModel->getPicture($this->uri->segment(2, 1));
- $this->data['tags'] = $this->PictureModel->getTags($this->uri->segment(2, 1));
- $this->load->view('templates/header');
- $this->load->view('picture', $this->data);
- $this->load->view('templates/footer');
- }
- public function comment($id){
- $this->PictureModel->enterComment($id, $this->input->post('comment'));
- redirect('/picture/'.$id);
- }
- }
- ?>
- /// KOLMAS FAIL
- <div class="col-md-2 col-sm-4"></div>
- <div class="container">
- <div class="panel panel-default">
- <div class="panel-heading">
- <?php echo "<h3>".$picture->title."</h3><br>";?>
- <a class="btn btn-info" href="<?php echo site_url("edit/".$picture->id);?>">Muuda Andmeid</a>
- <a class="btn btn-warning" href="<?php echo $picture->location;?>">Täissuuruses</a>
- </div>
- <div class="panel-body">
- <div class="col-lg-6 col-md-6 col-xs-12"><?php echo $picture->description;?></div>
- <div class="row">
- <div class="col-lg-6 col-md-6 col-xs-12">
- <br>
- <?php echo '<img src="'.$picture->location.'" class="img-responsive">';?>
- </div>
- </div>
- </div>
- <div class="panel-footer"><?php echo implode(', ',$tags);?><br></div>
- </div>
- <?php if ($picture->comments_enabled == 't'){?>
- <div class="panel-group">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h4 class="panel-title">
- <a data-toggle="collapse" href="#collapse1">Kommentaarid<?php echo '('.count($comments).')'; ?></a>
- </h4>
- </div>
- <div id="collapse1" class="panel-collapse collapse">
- <ul class="list-group">
- <li class="list-group-item">
- <?php for($i = 0; $i < count($comments); ++$i){?>
- <div class="panel panel-default">
- <div class="panel-heading">
- <h3 class="panel-title">
- <?php if ($comments[$i][0] == 'anonüümne'){?>
- <?php echo $comments[$i][0];?></h3>
- <?php } else { ?>
- <a href="<?php echo site_url('/profile/'.urlencode($comments[$i][0]));?>">
- <?php echo $comments[$i][0];?></a></h3>
- <?php }?>
- </div>
- <div class="panel-body" style="text:word-wrap"><?php echo $comments[$i][1]; ?></div>
- <div class="panel-footer"><?php echo date("H:i:s d.m.Y", $comments[$i][2]); ?></div>
- </div>
- <?php }?>
- <?php } else { ?>
- <div class="panel-group">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h4 class="panel-title">
- Kommenteerimine on selle pildi jaoks väljalülitatud.
- </h4>
- </div>
- <?php }?>
- </li>
- </ul>
- </div>
- </div>
- </div>
- <?php if($this->ion_auth->logged_in() && $picture->comments_enabled == 't') {?>
- <?php echo form_open('picture/comment/'.$this->uri->segment(2, 1));?>
- <div class="form-group">
- <div class="col-lg-5 col-cs-offset-5">
- <form>
- <label for="comment">Kommenteeri:</label>
- <textarea class="form-control" type="text" rows="5" id="comment" name="comment"></textarea>
- <br>
- <input type="submit" class="btn btn-primary" value="kommenteeri">
- </form>
- </div>
- </div>
- <?php } ?>
- </div>
- <div class="col-md-2 col-sm-4"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement