Esempio n. 1
0
 public function liveSearch($search)
 {
     $searchString = preg_replace("/[^A-Za-z0-9]/", " ", $search);
     if (strlen($searchString) >= 1 && $searchString !== ' ') {
         if (!$this->session->admin) {
             $this->db->where('owner', $this->session->id);
             $this->db->or_where('department', $this->session->department);
         }
         $this->db->select();
         $this->db->like('realname', $searchString, 'both');
         $this->db->or_like('description', $searchString, 'both');
         $this->db->where('publishable', 1);
         $this->db->limit(10);
         $query = $this->db->get('documents');
         if ($query->num_rows() !== 0) {
             foreach ($query->result() as $row) {
                 $fileDataObj = new Document_Model($row->id);
                 $data[] = array('id' => $row->id, 'realname' => $row->realname, 'category' => $fileDataObj->getCategoryName(), 'owner' => $fileDataObj->getOwnerName(), 'description' => $row->description, 'thumbnail' => $fileDataObj->getThumbnail(), 'detailsLink' => site_url() . 'details/' . $row->id);
             }
             echo json_encode($data);
         } else {
             $output = array('status' => 'error', 'msg' => 'No Results Found');
             echo json_encode($output);
         }
     }
 }
Esempio n. 2
0
 /**
  *Get number of files by category
  */
 public function fileCountCategory()
 {
     $this->db->select('id,category,COUNT(*) as cnt');
     $this->db->group_by('category');
     $query = $this->db->get('documents');
     if ($query->num_rows() > 0) {
         $cat = array();
         foreach ($query->result() as $row) {
             $fileObj = new Document_Model($row->id);
             $category = $fileObj->getCategoryName();
             $cat[] = array('category' => $category, 'count' => $row->cnt);
         }
         echo json_encode($cat);
     } else {
         $msg = array('status' => 'error', 'msg' => 'There were no files to gather data on.');
         echo json_encode($msg);
         exit;
     }
 }