Add sha1 feature in Exercice class

This commit is contained in:
Quentin Grosyeux 2013-10-10 05:11:40 +02:00
parent 0640a261d6
commit fffb86e971

View File

@ -105,23 +105,26 @@ class Exercice
{ {
$path = $file['path']; $path = $file['path'];
$name = $file['name']; $name = $file['name'];
$sha1 = $file['sha1'];
if (isset($file['id'])) if (isset($file['id']))
$fid = intval($file['id']); $fid = intval($file['id']);
$db->escape($path); $db->escape($path);
$db->escape($name); $db->escape($name);
$db->escape($sha1);
if (!isset($file['id'])) if (!isset($file['id']))
{ {
$db->query("INSERT INTO exercice_files $db->query("INSERT INTO exercice_files
VALUES (NULL, '".$id."', '".$path."', '".$name."');"); VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$sha1."');");
$this->files[$k]['id'] = $db->insert_id(); $this->files[$k]['id'] = $db->insert_id();
} }
else else
{ {
$db->query("UPDATE exercice_files $db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."' SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
WHERE id = ".$fid); WHERE id = ".$fid);
} }
} }
@ -144,9 +147,9 @@ class Exercice
$this->keys[] = $key; $this->keys[] = $key;
} }
function add_file($path, $name) function add_file($path, $name, $sha1)
{ {
$file = ["path" => $path, "name" => $name]; $file = ["path" => $path, "name" => $name, "sha1" => $sha1];
if (isset($file)) if (isset($file))
$this->files[] = $file; $this->files[] = $file;
} }