/** * TODO: Comment this */ public static function getIdSeqName($apiName) { return CmaticSchema::getTypeDbTable($apiName) . '_' . CmaticSchema::getFieldDbColumn($apiName, 'id') . '_seq'; }
} if (is_null($tmpValue)) { throw new CmaticApiException(sprintf('Record %d: Invalid value for %s.%s: $s', $index, $typeApiName, $fieldApiName, $value)); } $setClause[] = sprintf('%s = %s', $tmpField, $tmpValue); } // TODO: Move last_mod into triggers? $conn->query(sprintf('update %s set last_mod = now(), %s where %s=%s', $typeDbTable, implode(',', $setClause), CmaticSchema::getFieldDbColumn($typeApiName, 'id'), $recordId)); } } else { if ($op == 'delete') { // Disable deletes it's too scary to allow // TODO: There needs to be some checks to make sure not just anything can be deleted. // Specifically, we should NEVER be able to delete scoring rows if they have scores. // Perhaps this should be set up as a trigger? $recordIds = array(); foreach ($records as $index => $record) { $recordIds[] = $record['id']; } $conn->query(sprintf('delete from %s where %s in (%s)', $typeDbTable, CmaticSchema::getFieldDbColumn($typeApiName, 'id'), implode(',', $recordIds))); } } } $conn->commit(); $conn = null; // What should the response be on a successful set-request? if (isset($newId)) { print "{\"success\": \"true\", newId: {$newId}}"; } else { print '{"success": "true"}'; }
} require_once '../util/Db.php'; require_once '../util/Ex.php'; require_once '../util/TextUtils.php'; $requestParams = TextUtils::undoMagicQuotes($_REQUEST); $type = $requestParams['type']; $table = CmaticSchema::getTypeDbTable($type); if (is_null($table)) { // TODO: Should probably catch this throw new CmaticApiException('Unrecognized type: ' . $requestParams['type']); } // Build out the api field names to return $fieldSelection = array(); foreach (CmaticSchema::getAllFieldsForType($type) as $apiField => $dbColumn) { // Quotes to maintain case $fieldSelection[] = $dbColumn . ' AS "' . $apiField . '"'; } // To filter by a specific FK field, both of these parameters // must be specified. $filterField = $requestParams['filterField']; $filterValue = $requestParams['filterValue']; $filterClause = ''; if (!is_null($filterField) && !is_null($filterValue)) { $filterClause = sprintf(' where %s = %d', CmaticSchema::getFieldDbColumn($type, $filterField), $filterValue); } $conn = PdoHelper::getPdo(); $r = $conn->query(sprintf('select %s from %s%s', implode(', ', $fieldSelection), $table, $filterClause)); $ret = array(); $ret['records'] = $r->fetchAll(PDO::FETCH_ASSOC); $conn = null; echo json_encode($ret);