00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/DataAccess.php';
00026
00027
00028
00029
00030
00031 define('FILTER_BY_OWNER', 1);
00032
00033
00034
00035
00046
00047 class FF_DataAccess_Assignment_mysql extends FF_DataAccess {
00048
00049
00056 function FF_DataAccess_Assignment_mysql()
00057 {
00058 FF_DataAccess::FF_DataAccess();
00059 $this->table = $this->o_registry->getConfigParam('data/assignments_table', 'homework_assignments');
00060 }
00061
00062
00063
00064
00073 function update($in_data)
00074 {
00075 $in_data['open_time'] = empty($in_data['open_time']) ? $this->timestampToISODate(0) : $this->timestampToISODate($in_data['open_time']);
00076 $in_data['late_time'] = $this->timestampToISODate($in_data['late_time']);
00077 $in_data['close_time'] = empty($in_data['close_time']) ? $this->timestampToISODate(0) : $this->timestampToISODate($in_data['close_time']);
00078 return parent::update($in_data);
00079 }
00080
00081
00082
00083
00092 function add($in_data)
00093 {
00094 $in_data['open_time'] = empty($in_data['open_time']) ? 0 : $this->timestampToISODate($in_data['open_time']);
00095 $in_data['late_time'] = $this->timestampToISODate($in_data['late_time']);
00096 $in_data['close_time'] = empty($in_data['close_time']) ? 0 : $this->timestampToISODate($in_data['close_time']);
00097 return parent::add($in_data);
00098 }
00099
00100
00101
00102
00112 function getDataByPrimaryKey($in_id, $in_fields = '*')
00113 {
00114 return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00115 }
00116
00117
00118
00119
00131 function getListData($in_where, $in_orderByField, $in_orderByDir, $in_fields = '*')
00132 {
00133 return parent::getListData($in_where, $in_orderByField, $in_orderByDir, $this->_getSelectFields());
00134 }
00135
00136
00137
00138
00151 function getListFilter($in_searchString, $in_searchFields, $in_filter, $in_filterData)
00152 {
00153 $s_filter = '';
00154 if ($in_filter == FILTER_BY_OWNER) {
00155 $s_filter = 'owner_id = ' . $this->o_data->quoteSmart($in_filterData['ownerId']) . ' AND ';
00156 }
00157
00158 $s_filter .= '(' . parent::getListFilter($in_searchString, $in_searchFields, $in_filter, $in_filterData) . ')';
00159 return $s_filter;
00160 }
00161
00162
00163
00164
00171 function getClassOptions()
00172 {
00173 $s_query = 'SELECT CONCAT(crscode,"-",secno) AS a, CONCAT(crscode,"-",secno) AS b
00174 FROM studentinfo.importclasses
00175 WHERE start_date <= DATE_ADD(NOW(), INTERVAL 14 DAY) AND end_date >= NOW()
00176 ORDER BY a';
00177 return $this->o_data->getAssoc($s_query);
00178 }
00179
00180
00181
00182
00189 function getSessionOptions()
00190 {
00191 $s_query = 'SELECT start_date, start_date
00192 FROM studentinfo.importclasses
00193 WHERE start_date >= DATE_SUB(NOW(), INTERVAL 100 DAY)
00194 GROUP BY start_date
00195 ORDER BY start_date';
00196 return $this->o_data->getAssoc($s_query);
00197 }
00198
00199
00200
00201
00210 function getDescriptionsById($in_ids) {
00211 $s_where = '';
00212 foreach ($in_ids as $s_id) {
00213 $s_where .= 'id = ' . $this->o_data->quoteSmart($s_id) . ' OR ';
00214 }
00215
00216 $s_where .= '0';
00217 $s_query = "SELECT CONCAT(name, ' (', course_code, ')')
00218 FROM $this->table
00219 WHERE $s_where ORDER BY name";
00220 return $this->o_data->getCol($s_query, 0);
00221 }
00222
00223
00224
00225
00236 function updateCourseCodes($in_ids, $in_course, $in_ownerId)
00237 {
00238 $s_where = '';
00239 foreach ($in_ids as $s_id) {
00240 $s_where .= 'id = ' . $this->o_data->quoteSmart($s_id) . ' OR ';
00241 }
00242
00243 $s_where .= '0';
00244 $s_query = "UPDATE $this->table SET course_code = ? WHERE owner_id = ? AND ($s_where)";
00245 $o_result =& $this->o_data->query($s_query, array($in_course, $in_ownerId));
00246 return !PEAR::isError($o_result);
00247 }
00248
00249
00250
00251
00262 function updateSession($in_ids, $in_session, $in_ownerId)
00263 {
00264 $s_where = '';
00265 foreach ($in_ids as $s_id) {
00266 $s_where .= 'id = ' . $this->o_data->quoteSmart($s_id) . ' OR ';
00267 }
00268
00269 $s_where .= '0';
00270 $s_query = "UPDATE $this->table SET session = ? WHERE owner_id = ? AND ($s_where)";
00271 $o_result =& $this->o_data->query($s_query, array($in_session, $in_ownerId));
00272 return !PEAR::isError($o_result);
00273 }
00274
00275
00276
00277
00290 function updateTimes($in_ids, $in_updateSeconds, $in_ownerId, $in_type)
00291 {
00292 $s_where = '';
00293 foreach ($in_ids as $s_id) {
00294 $s_where .= 'id = ' . $this->o_data->quoteSmart($s_id) . ' OR ';
00295 }
00296
00297 $s_where .= '0';
00298 $s_field = $in_type . '_time';
00299 $s_query = "UPDATE $this->table
00300 SET $s_field = DATE_ADD($s_field, INTERVAL ! SECOND)
00301 WHERE $s_field \!= 0 AND owner_id = ? AND ($s_where)";
00302 $o_result =& $this->o_data->query($s_query, array($in_updateSeconds, $in_ownerId));
00303 return !PEAR::isError($o_result);
00304 }
00305
00306
00307
00308
00315 function getNextId()
00316 {
00317
00318 $this->o_data->setOption('seqname_format', '%s');
00319 return $this->o_data->nextId($this->o_registry->getConfigParam('data/sequence_table'));
00320 }
00321
00322
00323
00324
00332 function _getSelectFields()
00333 {
00334 return 'id, name, session, UNIX_TIMESTAMP(open_time) AS open_time, UNIX_TIMESTAMP(late_time) AS late_time, UNIX_TIMESTAMP(close_time) AS close_time, owner_id, course_code';
00335 }
00336
00337
00338 }
00339 ?>