/
surveys_dynamic_model.php
130 lines (112 loc) · 3.66 KB
/
surveys_dynamic_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php if ( ! defined('BASEPATH')) die('No direct script access allowed');
class Surveys_dynamic_model extends CI_Model {
function getAllRecords($iSurveyID,$condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}
$data = $this->db->get('survey_'.$iSurveyID);
return $data;
}
function getSomeRecords($fields,$iSurveyID,$condition=FALSE,$order=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
if ($condition != FALSE)
{
$this->db->where($condition);
}
if ($order != FALSE)
{
$this->db->order_by($order);
}
$data = $this->db->get('survey_'.$iSurveyID);
return $data;
}
/**
* Get the records with ids from $iFrom to $iFrom + $iCount
* @param $iSurveyID ID of the survey
* @param $iFrom Beginning of the range
* @param $iCount Number of rows
* @param $sSortCol Sort the elements by this colum
* @param $sSortOrder Order of the sort
* @return mixed
*/
function getRecordsInRange($iSurveyID, $iFrom, $iCount, $sSortCol, $sSortOrder)
{
$this->db->order_by($sSortCol, $sSortOrder);
return $this->db->get('survey_'.$iSurveyID, $iCount, $iFrom);
}
function quotaCompletedCount($iSurveyID,$querycond)
{
//Used by get_quotaCompletedCount()
$querysel = "SELECT count(id) as count FROM ".db_table_name('survey_'.$iSurveyID)." WHERE ".implode(' AND ',$querycond)." "." AND submitdate IS NOT NULL";
return $this->db->query($querysel);
}
/**
* Insert a new response
* @param int $iSurveyID ID of the survey
* @param array $data The response
* @return mixed
*/
function insertRecords($iSurveyID, $data)
{
return $this->db->insert('survey_'.$iSurveyID, $data);
}
/**
* Get data from certain columns for a response
* @param array $aFields Array containing field names
* @param int $iSurveyID ID of the survey
* @param int $iResponseID ID of the response
* @return mixed
*/
function getFieldsForID($aFields, $iSurveyID, $iResponseID)
{
foreach ($aFields as $field)
{
$this->db->select($field);
}
$this->db->where('id', $iResponse);
return $this->db->get('survey_'.$iSurveyID);
}
/**
* Get a response from the database
* @param int $iSurveyID ID of the survey
* @param int $iResponseID ID of the response
* @return mixed
*/
function getResponse($iSurveyID, $iResponseID)
{
$this->db->where('id', $iResponseID);
return $this->db->get('survey_'.$iSurveyID);
}
function deleteRecords($iSurveyID,$condition)
{
$this->db->where($condition);
return $this->db->delete('survey_'.$iSurveyID);
}
function deleteResponse($iSurveyID, $iResponseID)
{
$this->db->where('id', $iResponseID);
return $this->db->delete('survey_'.$iSurveyID);
}
function getResponseCount($iSurveyID)
{
return $this->db->count_all_results('survey_'.$iSurveyID);
}
/**
* Update a response
* @param int $iSurveyID ID of the survey
* @param int $iResponseID ID of the response
* @param array $aData Array containg response data
* @return mixed
*/
function updateResponse($iSurveyID, $iResponseID, $aData)
{
$this->db->where('id', $iResponseID);
$this->db->update('survey_'.$iSurveyID, $aData);
}
}