Code Duplication    Length = 47-48 lines in 2 locations

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

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