Explorar o código

Add method to check is eval result exists - refs BT#13469

Angel Fernando Quiroz Campos %!s(int64=6) %!d(string=hai) anos
pai
achega
0e3890ad3f
Modificáronse 1 ficheiros con 23 adicións e 0 borrados
  1. 23 0
      main/gradebook/lib/be/result.class.php

+ 23 - 0
main/gradebook/lib/be/result.class.php

@@ -290,4 +290,27 @@ class Result
             Database::query($sql);
         }
     }
+
+    /**
+     * Check if exists a result with its user and evaluation.
+     *
+     * @throws \Doctrine\ORM\Query\QueryException
+     *
+     * @return bool
+     */
+    public function exists()
+    {
+        $em = Database::getManager();
+
+        $result = $em
+            ->createQuery(
+                'SELECT COUNT(gr) FROM ChamiloCoreBundle:GradebookResult gr
+                WHERE gr.evaluationId = :eval_id AND gr.userId = :user_id'
+            )
+            ->setParameters(['eval_id' => $this->evaluation, 'user_id' => $this->user_id])
+            ->getSingleScalarResult();
+        $count = (int) $result;
+
+        return $count > 0;
+    }
 }