* @version 1.0 * @since 20 Aug 2014 17:20:09 */ require_once 'models/Model.inc.php'; class Response extends Model { // The database fields used by this model. public static $fields = array( 'account_id' => '', 'participant_id' => '', 'question_id' => '', 'response' => '', // 'response_parsed' => '', // 'added_datetime' => '', ); /* * * * @access public * @param * @return * @author Quinn Comendant * @version 1.0 * @since 16 Nov 2014 17:45:40 */ static public function insert($frm) { global $auth, $cache; $db =& DB::getInstance(); $app =& App::getInstance(); // Remove any stale cached list data. $cache->delete('response list'); // Create the record under the user's account, unless an account_id was provided. $account_id = isset($frm['account_id']) && is_numeric($frm['account_id']) ? $frm['account_id'] : $auth->get('account_id'); $added_datetime = isset($frm['added_datetime']) && '0000-00-00 00:00:00' != strToSQLDate($frm['added_datetime']) ? $frm['added_datetime'] : date('Y-m-d H:i:s'); // Insert record data. $app->logMsg(sprintf('%s with data %s', __METHOD__, getDump($frm)), LOG_DEBUG, __FILE__, __LINE__); $db->query(" REPLACE INTO response_tbl ( account_id, participant_id, question_id, response, response_parsed, added_datetime ) VALUES ( '" . $db->escapeString($account_id) . "', '" . $db->escapeString($frm['participant_id']) . "', '" . $db->escapeString($frm['question_id']) . "', '" . $db->escapeString($frm['response']) . "', '" . $db->escapeString(Question::getParsedResponse($frm['question_id'], $frm['response'])) . "', '" . $db->escapeString(strToSQLDate($added_datetime)) . "' ) "); return sha1($frm['participant_id'] . ':' . $frm['question_id']); } }