Code Duplication    Length = 47-48 lines in 2 locations

plugin/buycourses/src/buy_course_plugin.class.php 2 locations

@@ 1028-1075 (lines=48) @@
1025
     * @param int $max Optional. The maximum price filter
1026
     * @return array
1027
     */
1028
    private function filterSessionList($name = null, $min = 0, $max = 0)
1029
    {
1030
        if (empty($name) && empty($min) && empty($max)) {
1031
            $auth = new Auth();
1032
            return $auth->browseSessions();
1033
        }
1034
1035
        $itemTable = Database::get_main_table(self::TABLE_ITEM);
1036
        $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
1037
1038
        $min = floatval($min);
1039
        $max = floatval($max);
1040
1041
        $innerJoin = "$itemTable i ON s.id = i.product_id";
1042
        $whereConditions = [
1043
            'i.product_type = ? ' => self::PRODUCT_TYPE_SESSION
1044
        ];
1045
1046
        if (!empty($name)) {
1047
            $whereConditions['AND s.name LIKE %?%'] = $name;
1048
        }
1049
1050
        if (!empty($min)) {
1051
            $whereConditions['AND i.price >= ?'] = $min;
1052
        }
1053
1054
        if (!empty($max)) {
1055
            $whereConditions['AND i.price <= ?'] = $max;
1056
        }
1057
1058
        $sessionIds = Database::select(
1059
            's.id',
1060
            "$sessionTable s INNER JOIN $innerJoin",
1061
            ['where' => $whereConditions]
1062
        );
1063
1064
        if (!$sessionIds) {
1065
            return [];
1066
        }
1067
1068
        $sessions = [];
1069
1070
        foreach ($sessionIds as $sessionId) {
1071
            $sessions[] = Database::getManager()->find('ChamiloCoreBundle:Session', $sessionId);
1072
        }
1073
1074
        return $sessions;
1075
    }
1076
1077
    /**
1078
     * Search filtered courses by name, and range of price
@@ 1084-1130 (lines=47) @@
1081
     * @param int $max Optional. The maximum price filter
1082
     * @return array
1083
     */
1084
    private function filterCourseList($name = null, $min = 0, $max = 0)
1085
    {
1086
        if (empty($name) && empty($min) && empty($max)) {
1087
            return $this->getCourses();
1088
        }
1089
1090
        $itemTable = Database::get_main_table(self::TABLE_ITEM);
1091
        $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
1092
1093
        $min = floatval($min);
1094
        $max = floatval($max);
1095
1096
        $innerJoin = "$itemTable i ON c.id = i.product_id";
1097
        $whereConditions = [
1098
            'i.product_type = ? ' => self::PRODUCT_TYPE_COURSE
1099
        ];
1100
1101
        if (!empty($name)) {
1102
            $whereConditions['AND c.title LIKE %?%'] = $name;
1103
        }
1104
1105
        if (!empty($min)) {
1106
            $whereConditions['AND i.price >= ?'] = $min;
1107
        }
1108
1109
        if (!empty($max)) {
1110
            $whereConditions['AND i.price <= ?'] = $max;
1111
        }
1112
1113
        $courseIds = Database::select(
1114
            'c.id',
1115
            "$courseTable c INNER JOIN $innerJoin",
1116
            ['where' => $whereConditions]
1117
        );
1118
1119
        if (!$courseIds) {
1120
            return [];
1121
        }
1122
1123
        $courses = [];
1124
1125
        foreach ($courseIds as $courseId) {
1126
            $courses[] = Database::getManager()->find('ChamiloCoreBundle:Course', $courseId);
1127
        }
1128
1129
        return $courses;
1130
    }
1131
1132
    /**
1133
     * Generates a random text (used for order references)