source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/collaborator.php @ 348

Last change on this file since 348 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 4.0 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Collaborator extends MX_Controller {
7
8    public function __construct() {
9        parent::__construct();
10        $this->load->helper('cookie');
11    }
12
13    public function index() {
14        $data=array();
15        $this->load->driver("pp");
16        $admin_info = $this->session->userdata('adminInfo');
17        if ($admin_info) {
18            $data['content'] = $this->getCollaborators();
19            $this->parser->parse('collaborator/index',$data);
20        } else {
21            $this->load->view('login');
22        }
23    }
24    public function getCollaborators($filters=array())
25    {
26        $this->load->driver("pp");
27        $data['current_page'] = $this->uri->segment(4,1);
28        $data['itemsoptions']=array(10,25,50,100);
29        $data['perpage'] = 10;   
30        if ($this->input->post('items'))
31        {
32        $data['perpage'] = $this->input->post('items');   
33        }
34       
35        $data['keyword']='';
36        $sql=" FROM Entities\Tblcollaborator c";
37        if ($this->input->post('keyword'))
38        {
39        $sql.=" WHERE c.full_name LIKE '%".$this->input->post('keyword')."%'";
40        $data['keyword']=$this->input->post('keyword');
41        }
42       
43        $query = $this->doctrine->em->createQuery('SELECT COUNT(c.id) '.$sql);
44        $data['total'] = $query->getSingleScalarResult();
45       
46        $query = $this->doctrine->em->createQuery('SELECT c '.$sql);
47        $query->setFirstResult(($data['current_page']-1)*$data['perpage']);
48        $query->setMaxResults($data['perpage']);
49        $data['collaborators'] = $query->getArrayResult();
50       
51       
52        $this->load->library('pagination');
53        $url = "http://$_SERVER[HTTP_HOST]/admin/cong_tac_vien/trang/";
54        $config['base_url'] = $url;
55        $config['total_rows'] = $data['total'];
56        $config['use_page_numbers'] = TRUE;
57        $config['per_page'] = $data['perpage'];
58        $config['num_tag_open'] = "<li>";
59        $config['num_tag_close'] = "</li>";
60        $config['cur_tag_open'] = "<li class='active'><a>";
61        $config['cur_tag_close'] = '</a></li>';
62        $config['last_link'] = '»';
63        $config['first_link'] = '«';
64        $config['first_tag_open'] = "<li title='Trang đầu tiên'>";
65        $config['first_tag_close'] = '</li>';
66        $config['last_tag_open'] = "<li title='Trang cuối cùng'>";
67        $config['last_tag_close'] = '</li>';
68        $config['next_link'] = '>';
69        $config['next_tag_open'] = "<li title='Trang kế tiếp'>";
70        $config['next_tag_close'] = '</li>';
71        $config['prev_link'] = '<';
72        $config['prev_tag_open'] = "<li title='Trang trước'>";
73        $config['prev_tag_close'] = '</li>';
74        $config['num_links'] = 2;
75        $config['current_page'] = $data['current_page'];
76        $config['ajax_class'] = 'ajax_paging';
77        $this->pagination->initialize($config);
78        $data['paging'] = $this->pagination->create_links();
79
80        if ($this->input->is_ajax_request()) {
81        return $this->pp->parse('modules/admin/views/collaborator/listview', $data);   
82        }
83        return $this->pp->parse('modules/admin/views/collaborator/listview', $data,true);   
84    }
85    public function test() {
86        for ($i = 1; $i <= 500; $i++) {
87            $collaborator = new Entities\Tblcollaborator();
88            $collaborator->setActivated(rand(0, 1));
89            $collaborator->setAuthor(1);
90            $collaborator->setCellphone('0' . (1695061706+$i));
91            $collaborator->setCreatedTime(date("Y-m-d H:i:s"));
92            $collaborator->setFullName("Full Name ".$i);
93            $collaborator->setLoginName("loginname".$i);
94            $collaborator->setPasswd(md5("12345678"));
95            $collaborator->setUpdatedTime(date("Y-m-d H:i:s"));
96            try {
97                $this->doctrine->em->persist($collaborator);
98                $this->doctrine->em->flush();
99                $result['success'] = 1;
100            } catch (Exception $e) {
101
102                echo $e;
103            }
104        }
105    }
106
107}
Note: See TracBrowser for help on using the repository browser.