Last active
September 8, 2017 09:54
-
-
Save suresh-kumara-gist/9d560dffb0b9cf7917d23432794cba72 to your computer and use it in GitHub Desktop.
entity Query drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $query = \Drupal::entityQuery('attendance') | |
| ->condition('type', 'student_attendance_tracking', '=') | |
| // entity refernce field | |
| ->condition('field_course', 433, '>='); | |
| $courseRatings = $query->execute(); | |
| return $courseRatings; | |
| // get all Course Ratings. | |
| function getCourseRatings($groupId) { | |
| $query = \Drupal::entityQuery('attendance') | |
| ->condition('type', 'student_attendance_tracking', '=') | |
| ->condition('field_course', $groupId, '=') | |
| ->condition('field_rfs', "" , '!='); | |
| $courseRatings = $query->execute(); | |
| return $courseRatings; | |
| } | |
| // Sum of votes. | |
| function getSumOfVotes($groupId) { | |
| // Aggregate query SUM,COUNT | |
| $query = \Drupal::entityQueryAggregate('attendance') | |
| ->condition('type', 'student_attendance_tracking', '=') | |
| ->condition('field_course', $groupId, '='); | |
| $query->condition('field_rfs', '', '!='); | |
| $query->aggregate('field_rfs', 'sum'); | |
| $sumOfVotes = $query->execute(); | |
| if (isset($sumOfVotes['0']['field_rfs_sum'])) { | |
| return $sumOfVotes['0']['field_rfs_sum']; | |
| } | |
| return ""; | |
| } | |
| // group by query | |
| function getCourseRatingsStatistics($groupId) { | |
| $query = \Drupal::entityQueryAggregate('attendance') | |
| ->condition('type', 'student_attendance_tracking', '='); | |
| $query->condition('field_course', $groupId, '='); | |
| $query->groupBy('field_rfs'); | |
| $query->condition('field_rfs', '', '!='); | |
| $query ->aggregate('field_rfs', 'count'); | |
| $result = $query->execute(); | |
| return $result; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment