opengbu / gbuonline

GBU Online
5 stars 6 forks source link

Really Dynamic Website #14

Closed Varun-garg closed 9 years ago

Varun-garg commented 9 years ago

I know that content inside a school will be loaded from a database, but It would be really nice if even the school names and related things (timetable links, ebook controller names) etc are generated dynamically (like in admin/user panel)

Example 1

Existing Code

<ul class="dropdown-menu" role="menu">
          <li><a href="<?php echo site_url('schools/soe')?>">SOE</a></li>
          <li><a href="<?php echo site_url('schools/som')?>">SOM</a></li>
          <li><a href="<?php echo site_url('schools/sobt')?>">SOBT</a></li>
          <li><a href="<?php echo site_url('schools/soict')?>">SOICT</a></li>
          <li><a href="<?php echo site_url('schools/soljg')?>">SOLJG</a></li>
          <li><a href="<?php echo site_url('schools/sobsc')?>">SOBSC</a></li>
          <li><a href="<?php echo site_url('schools/sohss')?>">SOHSS</a></li>
          <li><a href="<?php echo site_url('schools/sovsas')?>">SOVSAS</a></li>
</ul>

This can be replaced by.

<ul class="dropdown-menu" role="menu">
 <?php
       $schools_q = $this->db->query("select sc_name from schools");
       foreach ($schools_q->result() as $row) 
       echo '<li><a href="' . site_url('schools/' . $row->sc_name) . '">';
       echo strtoupper($row->sc_name);
       echo '</a></li>' . "\n";
       }
 ?
</ul>

Note : Since front end is not connected to db yet,to run this you will have to add 'database' in libraries array in config/autoload.php (where 'session' is added).

This is just one example we need this to solve real code Redundancy - using loops for views is not the solution. Most of Front End (and 'its' database) work is duplicate

Example 2

In all School pages what Rajat had done -

Existing Code

public function sobsc()
    {
        $data['title'] = 'SOBSC &nbsp;|&nbsp;  GBU Online';
        $data['heading'] = ' School of Buddhist Studies and Civilization';
        $data['message'] = 'Where Buddhist Ethics are applied in real life!!!';
        $this->load->view('pages/link',$data);
        $this->load->view('pages/header');
        $this->load->view('pages/page-heading',$data);
        $this->load->view('pages/schools/sobsc');
        $this->load->view('pages/extras');
        $this->load->view('pages/footer');
    }

    public function soe()
    {
             .....
    }

    public function sovsas()
    {
     ....   
        }

      .... And another 70 similar lines
      ....

This can be replaced by something like

public function load_school( $school_name)
{
    $data['title'] --- from database
    $data['heading'] = from database
    $data['message'] = from database
    $this->load->view('pages/link',$data);
    $this->load->view('pages/header');
    $this->load->view('pages/page-heading',$data);

    $this->load->view('pages/school_info?school_name=' . $school_name);
    $this->load->view('pages/extras');
    $this->load->view('pages/footer');
}

Example 3

Existing structure

In \application\views\pages\schools

sobsc.php 
soe.php    
soict.php  
som.php
sobt.php   
sohss.php  
soljg.php  
sovsas.php

Change this to

school_info.php

In which you can use

$school_name = $_REQUEST['school_name'];
//Now display fetch information from db with $school_name

Example 4

Sarthak has just uploaded ebooks section, and just like Rajat He has written same functions for different schools and same number of views.

Example 5

Since Bhawesh Hasn't uploaded his new code, I will be using what he did earlier

public function sobsc(){
    $query=$this->db->query("select * from schools where sc_name = 'sobsc'");
    return $query->result();

}
public function sobt(){
    $query=$this->db->query("select * from schools where sc_name = 'sob'");
    return $query->result();

}
public function soe(){
    $query=$this->db->query("select * from schools where sc_name = 'soe'");
    return $query->result();

}
public function sohss(){
    $query=$this->db->query("select * from schools where sc_name = 'sohsc'");
    return $query->result();

}
public function soict(){
    $query=$this->db->query("select * from schools where sc_name = 'soict'");
    return $query->result();

}
public function soljg(){
    $query=$this->db->query("select * from schools where sc_name = 'soljg'");
    return $query->result();

}
public function som(){
    $query=$this->db->query("select * from schools where sc_name = 'som'");
    return $query->result();

}
public function sovsas(){
    $query=$this->db->query("select * from schools where sc_name = 'sovas'");
    return $query->result();

}

I mean... come on, this is not a copy and paste game. Change this change it to

public function school_details($school_name){
    $query=$this->db->query("select * from schools where sc_name = '$school_name'");
    return $query->result();   
}
awasthi commented 9 years ago

Yes Varun!

On 10 July 2015 at 17:01, Varun Garg notifications@github.com wrote:

I know that content inside a school will be loaded from a database, but It would be really nice if even the school names and related things (timetable links, ebook controller names etc are generated dynamically (like in admin/user panel) Example 1

Existing Code

This can be replaced by.

Note : Since front end is not connected to db yet,to run this you will have to add 'database' in libraries array in config/autoload.php (where 'session' is added).

This is just one example we need this to solve real code Redundancy - using loops for views is not the solution. Our Complete Front end code of Schools and Ebooks is duplicate Example 2

In all School pages by Rajat hid did this

Existing Code

public function sobsc() { $data['title'] = 'SOBSC  |  GBU Online'; $data['heading'] = ' School of Buddhist Studies and Civilization'; $data['message'] = 'Where Buddhist Ethics are applied in real life!!!'; $this->load->view('pages/link',$data); $this->load->view('pages/header'); $this->load->view('pages/page-heading',$data); $this->load->view('pages/schools/sobsc'); $this->load->view('pages/extras'); $this->load->view('pages/footer'); }

public function soe()
{
         .....
}

public function sovsas()
{
 ....
    }

  .... And another 70 similar lines
  ....

This can be replaced by something like

public function load_school( $school_name) { $data['title'] --- from database $data['heading'] = from database $data['message'] = from database $this->load->view('pages/link',$data); $this->load->view('pages/header'); $this->load->view('pages/page-heading',$data);

$this->load->view('pages/school_info?school_name=' . $school_name);
$this->load->view('pages/extras');
$this->load->view('pages/footer');

}

Example 3

Existing structure

In \application\views\pages\schools

sobsc.php soe.php soict.php som.php sobt.php sohss.php soljg.php sovsas.php

Change this to

school_info.php

In which you can use

$school_name = $__REQUEST['school_name']; //Now display fetch information from db with $school_name

Example 4

Sarthak has just uploaded ebooks section, and just like Rajat He has written same functions for different schools and same number of views. Example 5

Since Bhawesh Hasn't uploaded his new code, I will be using what he did earlier

public function sobsc(){ $query=$this->db->query("select * from schools where sc_name = 'sobsc'"); return $query->result();

} public function sobt(){ $query=$this->db->query("select * from schools where sc_name = 'sob'"); return $query->result();

} public function soe(){ $query=$this->db->query("select * from schools where sc_name = 'soe'"); return $query->result();

} public function sohss(){ $query=$this->db->query("select * from schools where sc_name = 'sohsc'"); return $query->result();

} public function soict(){ $query=$this->db->query("select * from schools where sc_name = 'soict'"); return $query->result();

} public function soljg(){ $query=$this->db->query("select * from schools where sc_name = 'soljg'"); return $query->result();

} public function som(){ $query=$this->db->query("select * from schools where sc_name = 'som'"); return $query->result();

} public function sovsas(){ $query=$this->db->query("select * from schools where sc_name = 'sovas'"); return $query->result();

}

I mean... come on, this is not a copy and paste game. Please change it to

public function school_details($school__name){ $query=$this->db->query("select * from schools where sc_name = '$school_name'"); return $query->result(); }

— Reply to this email directly or view it on GitHub https://github.com/opengbu/gbuonline/issues/14.

अमित अवस्थी व्यवसायिक अध्ययन एवम् अनुप्रयुक्त विज्ञान विद्यालय गौतम बुध विश्वविद्यालय ग्रेटर नोइडा-201308, उत्तर प्रदेश , भारत

Amit K Awasthi Group For Cryptology Reserarch School of Voc Studies and Applied Sciences Gautam Buddha University,

Greater Noida-201308, UP, INDIA

ResearcherID:: http://www.researcherid.com/rid/D-3118-2014 ORCID:: http://orcid.org/0000-0002-5500-0361 SCOPUS ID: http://www.scopus.com/authid/detail.url?authorId=7006541429

rajatsaxena035 commented 9 years ago

Highly respecting your views,

Example 1 : This is just a navbar-dropdown list, and we are linking it to their respective pages. Thats all. If we do the same via database, we would be making "simple" things very complex.

Example 2 : Fully agree with you.

Example 3 :

Thank you - Every person has different views.
Varun-garg commented 9 years ago

I connected clubs section on front end with database in the dynamic way as above (also in extras). Now 9 different functions and 9 views for these clubs are not needed. If anyone feels like he can do something like I did -

clubs.php

public function view($club_name)
    {
        $club_header_info_q = $this->db->query("select c_full_name, tagline from clubs where c_name = '$club_name'");
        $club_header_info = $club_header_info_q->row();
        $data ['title'] = $club_header_info->c_full_name . '&nbsp;|&nbsp;  GBU Online';
        $data ['heading'] = $club_header_info->c_full_name;
        $data['message'] =  $club_header_info->tagline;
        $this->load->view('pages/common/link',$data);
        $this->load->view('pages/common/header');
        $this->load->view('pages/common/page-heading',$data);

        $c_info['c_name'] = $club_name;

        $this->load->view('pages/clubs/club_info',$c_info);
        $this->load->view('pages/common/extras');
        $this->load->view('pages/common/footer');
    }

club_info.php

$query = $this->db->query("select * from clubs where c_name = '$c_name'"); 
$club_details = $query->row();