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