Commit 25a687eb authored by EXT Anthony Geourjon's avatar EXT Anthony Geourjon
Browse files

Merge branch...

Merge branch '473-ameliorer-l-affichage-de-l-icone-nouvelles-annotations-dans-la-page-de-choix-des-rapports-2' into 499-faire-le-calcul-du-nombre-d-annotations-lues-dans-le-tableau-de-bord-a-partir-de-la-table

SELECT id_annotation, COUNT(id_user) AS nbReading
FROM `link_annotation_learner` RIGHT JOIN annotation USING (id_annotation)
WHERE id_report = 8
GROUP by id_annotation
parents 15e404c3 36e80fb0
......@@ -46,3 +46,5 @@ storage/cache/
tests/_output
patch
.env.dev
.idea/
......@@ -2,6 +2,7 @@
namespace App;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
/**
......@@ -83,4 +84,21 @@ class Annotation extends Model
$this->save();
$this->timestamps = true;
}
/**
* Save reading of the annotation by user
* @param $id_user
*/
public function saveReadingByUser($id_user)
{
$isAlreadyRead = DB::table('link_annotation_learner')
->where('id_user', $id_user)
->where('id_annotation',$this->id_annotation);
if(!$isAlreadyRead->get()->count()){
DB::table('link_annotation_learner')->insert(['id_annotation' => $this->id_annotation, 'id_user' => $id_user]);
}
}
}
......@@ -105,7 +105,7 @@ class AnnotationController extends Controller
}
/**
* Delete the contents of the annotation.
* Trace the reading of the annotation.
*
* @param \Illuminate\Http\Request $request
* @param \App\Annotation $annotation
......@@ -125,6 +125,7 @@ class AnnotationController extends Controller
}
abort_if($user->cannot('view', $annotation), Helper::pullPolicyErrorCode());
Trace::logAction(Trace::CHECK_ANNOTATION, $parameters);
$annotation->saveReadingByUser($user->id_user);
return response()->json([]);
}
......
......@@ -902,16 +902,15 @@ ORDER BY labdoc.id_report_part, labdoc.position"
* @return int
*/
public function getNbNewAnnotations($id_user){
$sql_msgs = "SELECT COUNT(id_annotation) AS nb_annot FROM annotation"
. " JOIN link_report_learner lrl USING(id_report) LEFT JOIN labdoc USING(id_labdoc)"
. " WHERE (UNIX_TIMESTAMP(update_time) > last_synchro OR last_synchro IS NULL)"
. " AND deleted IS NULL AND lrl.id_report = ? AND id_user = ?";
$new_annotations = DB::selectOne(DB::raw($sql_msgs), [$this->id_report, $id_user]);
$sql_msgs = " SELECT COUNT(id_annotation) AS nb_annot "
. "FROM annotation JOIN link_report_learner lrl USING(id_report) LEFT JOIN labdoc USING(id_labdoc) "
. "WHERE lrl.id_report = ? AND id_user = ? AND deleted IS NULL "
. "AND id_annotation NOT IN (SELECT id_annotation FROM `link_annotation_learner` WHERE id_user = ? )";
$new_annotations = DB::selectOne(DB::raw($sql_msgs), [$this->id_report, $id_user, $id_user]);
// dd($new_annotations);
return $new_annotations->nb_annot;
}
/**
* Amount of non-deleted modified LD in a report for specific user
*
......
ALTER TABLE annotation ENGINE = InnoDB;
CREATE TABLE link_annotation_learner (
`id_annotation` int(10) UNSIGNED NOT NULL,
`id_user` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id_annotation`,`id_user`),
FOREIGN KEY (`id_user`) REFERENCES `user` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`id_annotation`) REFERENCES annotation (`id_annotation`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO link_annotation_learner ( id_annotation, id_user )
SELECT DISTINCT TRIM(BOTH '"' FROM JSON_EXTRACT(CAST(attributes AS CHAR(255) CHARSET utf8), '$.id_annotation')), id_user
FROM trace
WHERE id_action = 14;
Supports Markdown
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