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