Skip to content
Snippets Groups Projects
Commit fd4ed5bb authored by xamgore's avatar xamgore
Browse files

Bug fix, disciplines couldn't be deleted

The bug was in the strange behaviour of sql functions. The return value is presented in a table with strange column name. So I have just renamed it to `res`.
parent 2a27aad5
Branches
Tags
No related merge requests found
......@@ -53,7 +53,7 @@ class Controller_Api_Discipline extends Controller_Api_Handler {
throw new LogicException(Error::ILLEGAL_ACCESS);
if ($discipline->isLocked)
throw new LogicException(Error::DISCIPLINE_IS_LOCKED);
if (Model_Rating::countRatings($discipline) > 0)
if (Model_Rating::count($discipline) > 0)
throw new LogicException(Error::DISCIPLINE_IS_LOCKED);
$discipline->delete();
......
......@@ -33,7 +33,7 @@ abstract class Controller_Api_Handler extends Controller_Handler {
} catch (LogicException $e) {
$answer = ['error' => [
'code' => (int) $e->getCode(),
'message' => 'One of the parameters specified was missing or invalid: ' . $e->getMessage(),
'message' => (string) $e->getMessage(),
// 'request' => $this->request->params // like http://vk.com/dev/captcha_error
]];
}
......
......@@ -84,11 +84,12 @@ class Model_Rating extends Model
* @param Model_Discipline $discipline
* @return int
*/
public static function countRatings(Model_Discipline &$discipline) {
$sql = "SELECT `Discipline_CountRatings`(:id);";
public static function count(Model_Discipline &$discipline) {
$sql = "SELECT `Discipline_CountRatings`(:id) AS `res`;";
$count = DB::query(Database::SELECT, $sql)
->param(':id', $discipline->ID)
->execute()[0];
->execute()
->get('res');
return (int) $count;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment