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