Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- /**
- * @property CI_Loader $load
- * @property CI_Form_validation $form_validation
- * @property CI_Input $input
- * @property CI_Email $email
- * @property CI_DB_active_record $db
- * @property CI_DB_forge $dbforge
- *
- * @property CI_Session $session
- */
- class Listing{
- public $settings = array(
- 'id' => '',
- 'class' => '',
- 'width' => '900px',
- 'colcount' => 4,
- 'gutter' => 20, //in px
- 'margins' => 'auto', //left and right from the grid
- 'cellclass' => 'gridcell', //CSS class for the cells of the grid
- 'cellid' => 'gc', //followed by the number
- 'viewchange' => false
- );
- public $values;
- public function grid($data = array()){
- $this->_initiate('grid',$data);
- // If there are no values given, noting to show, so return error
- if(!$this->values){
- return array('html' => ci()->lang->line('g.no_data'),'css' => '');
- }
- $output = array(
- 'html' => '',
- 'css' => ''
- );
- $output['html'] .= '<div id="'.$this->settings['id'].'" class="grid'.($this->settings['class'] != ''?' '.$this->settings['class']:'').'">';
- $i = 0;
- foreach($this->values as $v){
- $i++;
- // Check if it is the last cell of the row, then dont add the gutter
- if(($i%$this->settings['colcount']) == 0)
- $gutter = '';
- else
- $gutter = 'style="margin-right:'.$this->settings['gutter'].'px"';
- $output['html'] .= '<div id="'.$this->settings['cellid'].$i.'" class="'.$this->settings['cellclass'].'"'.$gutter.'>'.$v.'</div>';
- }
- $output['html'] .= '</div>';
- // CSS Calculation
- $colwidth = ($this->settings['width']-($this->settings['gutter']*($this->settings['colcount']-1)))/$this->settings['colcount'];
- // Gridid CSS
- $output['css'] .= '#'.$this->settings['id'].'{';
- $output['css'] .= 'width:'.$this->settings['width'].';';
- // Add px if margins is not set to auto
- $output['css'] .= 'margin-left:'.$this->settings['margins'].($this->settings['margins'] != 'auto'?'px':'').';';
- $output['css'] .= 'margin-right:'.$this->settings['margins'].($this->settings['margins'] != 'auto'?'px':'').';';
- $output['css'] .= '}';
- //Gridcell CSS
- $output['css'] .= '#'.$this->settings['id'].' .' . $this->settings['cellclass'] . '{';
- $output['css'] .= 'width:'.round($colwidth).'px;';
- $output['css'] .= 'float:left;';
- $output['css'] .= '}';
- return $output;
- }
- public function listview($data = array()){
- }
- public function details($data = array()){
- }
- private function _initiate($type,$data){
- // Get cached files if they're available and it's a viewchange
- if(isset($data['viewchange'])){
- if(ci()->session->flashdata('listingview')){
- $data = unserialize($this->session->flashdata('listingview'));
- }else{
- $this->values = false;
- return false;
- }
- }
- // Overwrite default settings
- if(isset($data['settings'])){
- $this->settings = array_merge($this->settings,$data['settings']);
- }
- if($this->settings['id'] == '')
- $this->settings['id'] = substr(md5(strtotime(time())),0,10);
- $this->settings['id'] = $type . '-' . $this->settings['id'];
- if(isset($data['values'])){
- $this->values = $data['values'];
- }else{
- $this->values = false;
- return false;
- }
- //Save values for viewchange
- ci()->session->set_flashdata('listingview',serialize($data));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment