function add()
 {
     try {
         $model = new Activities_student();
         $students = new Student();
         $listStudents = $students->selectAll();
         $getStudents = array_column($listStudents, 'Student');
         $activity = new Activity();
         $listActivities = $activity->selectAll();
         $getActivities = array_column($listActivities, 'Activity');
         $this->set('getStudents', $getStudents);
         $this->set('getActivities', $getActivities);
         if (isset($_POST['info']) and $_POST['info']['student_id'] != '' and $_POST['info']['activity_id'] != '') {
             $activity = $_POST['info'];
             $student_id = $activity['student_id'];
             $activity_id = $activity['activity_id'];
             $model->student_id = $student_id;
             $model->activity_id = $activity_id;
             if ($model->save()) {
                 header('Location: ' . 'index.php?url=activities_student/index');
                 die;
             }
         } else {
             $this->set("title", "Error! Empty field!");
         }
     } catch (Exception $e) {
     }
 }
 function view($id)
 {
     $model = new Student();
     $act = new Activities_student();
     $student = $model->select($id);
     $act->where("id", $id);
     $activity = $act->query("SELECT point from activitys\n                                 LEFT JOIN activities_students ON activitys.id = activities_students.activity_id\n                                 WHERE student_id = {$id}");
     $this->set('student', $student);
     $this->set('info', $activity);
 }
 /**
  * @param $section
  * @param $num
  * @param string $string
  */
 private function bestIn($section, $num, $string = "YEAR")
 {
     $st_activity = new Activities_student();
     $students = $st_activity->query("SELECT  first_name,last_name, f_number,  sum(point) point  FROM activities_students\n  LEFT JOIN activitys   ON activities_students.activity_id = activitys.id\n  LEFT JOIN students   ON activities_students.student_id = students.id\nWHERE created_at > DATE_SUB(NOW(), INTERVAL 1 " . "{$string}" . ") AND  `{$section}` = {$num}\nGROUP BY student_id\nORDER BY point DESC");
     $result = array();
     $i = 0;
     foreach ($students as $key => $student) {
         $st = $student['Student']['first_name'] . " " . $student['Student']['last_name'];
         $pt = $student['']['point'];
         array_push($result, array($st => $pt));
     }
     if (!empty($result)) {
         foreach ($result as $name => $point) {
             foreach ($point as $key => $value) {
                 echo "<br>";
                 echo ++$i . ". " . $key . " - " . $value . " points.";
                 echo "<br>";
             }
         }
     } else {
         echo "<br>No active students!";
     }
 }