Code Duplication    Length = 47-48 lines in 2 locations

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

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