edit-modules.php
289 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Edit modules section under the "permissions" tab. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since 4.1.0 |
| 7 | */ |
| 8 | |
| 9 | $modules_data = Hustle_Module_Collection::instance()->get_all_paginated(); |
| 10 | $filter = $modules_data['filter']; |
| 11 | $modules = $modules_data['modules']; |
| 12 | $modules_total = $modules_data['total']; |
| 13 | $entries_per_page = $modules_data['entries_per_page']; |
| 14 | $modules_ids = array(); |
| 15 | |
| 16 | ?> |
| 17 | <div class="sui-box-settings-row"> |
| 18 | |
| 19 | <div class="sui-box-settings-col-1"> |
| 20 | <span class="sui-settings-label"><?php esc_html_e( 'Edit Existing Modules', 'hustle' ); ?></span> |
| 21 | <span class="sui-description"><?php esc_html_e( 'Choose the user roles which can edit the existing modules.', 'hustle' ); ?></span> |
| 22 | </div> |
| 23 | |
| 24 | <div class="sui-box-settings-col-2"> |
| 25 | |
| 26 | <?php |
| 27 | // TABLE: Modules. |
| 28 | $filtered = ! empty( $filter['role'] ) && 'any' !== $filter['role'] || ! empty( $filter['q'] ) |
| 29 | || 4 > count( $filter['types'] ) && ! empty( $filter['types'] ); |
| 30 | |
| 31 | if ( 0 === count( $modules ) && ! $filtered ) { |
| 32 | ?> |
| 33 | |
| 34 | <?php |
| 35 | $this->get_html_for_options( |
| 36 | array( |
| 37 | array( |
| 38 | 'type' => 'inline_notice', |
| 39 | 'icon' => 'info', |
| 40 | 'value' => esc_html__( "You haven't created any module yet.", 'hustle' ), |
| 41 | ), |
| 42 | ) |
| 43 | ); |
| 44 | ?> |
| 45 | |
| 46 | <?php |
| 47 | } else { |
| 48 | |
| 49 | // PAGINATION: Structure. |
| 50 | |
| 51 | $this->render( |
| 52 | 'admin/commons/pagination', |
| 53 | array( |
| 54 | 'total' => $modules_total, |
| 55 | 'entries_per_page' => $entries_per_page, |
| 56 | 'filterclass' => 'sui-pagination-open-filter', |
| 57 | 'filter' => $filter, |
| 58 | 'section' => 'permissions', |
| 59 | ) |
| 60 | ); |
| 61 | |
| 62 | // PAGINATION: Filter. |
| 63 | $values = array( |
| 64 | 'popup' => __( 'Pop-up', 'hustle' ), |
| 65 | 'slidein' => __( 'Slide-in', 'hustle' ), |
| 66 | 'embedded' => __( 'Embed', 'hustle' ), |
| 67 | 'social_sharing' => __( 'Share', 'hustle' ), |
| 68 | ); |
| 69 | ?> |
| 70 | |
| 71 | <form method="get" class="sui-pagination-filter"> |
| 72 | |
| 73 | <input type="hidden" name="page" value="hustle_settings" /> |
| 74 | <input type="hidden" name="section" value="permissions" /> |
| 75 | |
| 76 | <?php // FILTER: Module Type. ?> |
| 77 | <div class="sui-row"> |
| 78 | |
| 79 | <div class="sui-col-12"> |
| 80 | |
| 81 | <div class="sui-form-field"> |
| 82 | |
| 83 | <label class="sui-label"><?php esc_html_e( 'Module type', 'hustle' ); ?></label> |
| 84 | |
| 85 | <?php foreach ( $values as $value => $module ) { ?> |
| 86 | |
| 87 | <label class="sui-checkbox"> |
| 88 | <input type="checkbox" |
| 89 | name="filter[types][]" |
| 90 | value="<?php echo esc_attr( $value ); ?>" |
| 91 | <?php echo empty( $filter['types'] ) || in_array( $value, $filter['types'], true ) ? ' checked="checked"' : ''; ?> |
| 92 | /> |
| 93 | <span aria-hidden="true"></span> |
| 94 | <span><?php echo esc_html( $module ); ?></span> |
| 95 | </label> |
| 96 | |
| 97 | <?php } ?> |
| 98 | |
| 99 | </div> |
| 100 | |
| 101 | </div> |
| 102 | |
| 103 | </div> |
| 104 | |
| 105 | <?php // FILTER: Keyword. ?> |
| 106 | <div class="sui-row"> |
| 107 | |
| 108 | <div class="sui-col-12"> |
| 109 | |
| 110 | <div class="sui-form-field"> |
| 111 | |
| 112 | <label for="hustle-filter-keyword" class="sui-label"><?php esc_html_e( 'Module name has keyword', 'hustle' ); ?></label> |
| 113 | |
| 114 | <div class="sui-control-with-icon"> |
| 115 | |
| 116 | <input type="text" |
| 117 | name="filter[q]" |
| 118 | placeholder="<?php esc_html_e( 'E.g. Discount', 'hustle' ); ?>" |
| 119 | value="<?php echo esc_attr( isset( $filter['q'] ) ? esc_attr( $filter['q'] ) : '' ); ?>" |
| 120 | id="hustle-filter-keyword" |
| 121 | class="sui-form-control" /> |
| 122 | |
| 123 | <span class="sui-icon-magnifying-glass-search" aria-hidden="true"></span> |
| 124 | |
| 125 | </div> |
| 126 | |
| 127 | </div> |
| 128 | |
| 129 | </div> |
| 130 | |
| 131 | </div> |
| 132 | |
| 133 | <?php |
| 134 | // FILTER(S): Role and Sort. |
| 135 | ?> |
| 136 | <div class="sui-row"> |
| 137 | |
| 138 | <?php // FILTER: Role Assigned. ?> |
| 139 | <div class="sui-col-md-6"> |
| 140 | |
| 141 | <div class="sui-form-field"> |
| 142 | |
| 143 | <label class="sui-label"><?php esc_html_e( 'Use role assigned for editing', 'hustle' ); ?></label> |
| 144 | |
| 145 | <select name="filter[role]" id="hustle-select-filter-role"> |
| 146 | <option value="any"><?php esc_html_e( 'Any', 'hustle' ); ?></option> |
| 147 | <?php |
| 148 | foreach ( $roles as $value => $label ) { |
| 149 | if ( Opt_In_Utils::is_admin_role( $value ) ) { |
| 150 | continue; |
| 151 | } |
| 152 | printf( |
| 153 | '<option value="%s" %s>%s</option>', |
| 154 | esc_attr( $value ), |
| 155 | isset( $filter['role'] ) && $filter['role'] === $value ? 'selected="selected"' : '', |
| 156 | esc_html( $label ) |
| 157 | ); |
| 158 | } |
| 159 | ?> |
| 160 | </select> |
| 161 | |
| 162 | </div> |
| 163 | |
| 164 | </div> |
| 165 | |
| 166 | <?php // FILTER: Sort By. ?> |
| 167 | <div class="sui-col-md-6"> |
| 168 | |
| 169 | <div class="sui-form-field"> |
| 170 | |
| 171 | <label class="sui-label"><?php esc_html_e( 'Sort by', 'hustle' ); ?></label> |
| 172 | |
| 173 | <select name="filter[sort]" id="hustle-select-filter-sort"> |
| 174 | <?php |
| 175 | $values = array( |
| 176 | 'module_name' => __( 'Name', 'hustle' ), |
| 177 | 'module_id' => __( 'Id', 'hustle' ), |
| 178 | 'module_type' => __( 'Type', 'hustle' ), |
| 179 | ); |
| 180 | |
| 181 | foreach ( $values as $value => $label ) { |
| 182 | printf( |
| 183 | '<option value="%s" %s>%s</option>', |
| 184 | esc_attr( $value ), |
| 185 | isset( $filter['sort'] ) && $filter['sort'] === $value ? 'selected="selected"' : '', |
| 186 | esc_html( $label ) |
| 187 | ); |
| 188 | } |
| 189 | ?> |
| 190 | </select> |
| 191 | |
| 192 | </div> |
| 193 | |
| 194 | </div> |
| 195 | |
| 196 | </div> |
| 197 | |
| 198 | <?php // FILTER: Footer. ?> |
| 199 | <div class="sui-filter-footer"> |
| 200 | |
| 201 | <div class="sui-actions-right"> |
| 202 | |
| 203 | <input type="submit" |
| 204 | value="<?php esc_attr_e( 'Apply', 'hustle' ); ?>" |
| 205 | class="sui-button" /> |
| 206 | |
| 207 | </div> |
| 208 | |
| 209 | </div> |
| 210 | |
| 211 | </form> |
| 212 | |
| 213 | <?php |
| 214 | if ( 0 === count( $modules ) && $filtered ) { |
| 215 | |
| 216 | $this->get_html_for_options( |
| 217 | array( |
| 218 | array( |
| 219 | 'type' => 'inline_notice', |
| 220 | 'icon' => 'info', |
| 221 | 'value' => esc_html__( "You don't have any module corresponding to these filter parameters.", 'hustle' ), |
| 222 | ), |
| 223 | ) |
| 224 | ); |
| 225 | |
| 226 | } else { |
| 227 | ?> |
| 228 | <table class="sui-table"> |
| 229 | |
| 230 | <thead> |
| 231 | <tr> |
| 232 | <th><?php esc_html_e( 'Module', 'hustle' ); ?></th> |
| 233 | <th><?php esc_html_e( 'User Role', 'hustle' ); ?></th> |
| 234 | </tr> |
| 235 | </thead> |
| 236 | |
| 237 | <tbody> |
| 238 | |
| 239 | <?php |
| 240 | foreach ( $modules as $module ) : |
| 241 | $modules_ids[] = $module->module_id; |
| 242 | ?> |
| 243 | |
| 244 | <tr data-module-id="<?php echo esc_attr( $module->module_id ); ?>"> |
| 245 | <td class="sui-table-item-title"><span class="sui-icon-<?php echo esc_attr( $module->module_type ); ?>"></span> <?php echo esc_html( $module->module_name ); ?></td> |
| 246 | <td><select |
| 247 | form="<?php echo esc_attr( $form_id ); ?>" |
| 248 | class="sui-select-sm sui-select" |
| 249 | name="modules[<?php echo esc_attr( $module->module_id ); ?>][]" |
| 250 | multiple |
| 251 | > |
| 252 | <?php |
| 253 | $current = $module->get_edit_roles(); |
| 254 | foreach ( $roles as $value => $label ) { |
| 255 | $admin = Opt_In_Utils::is_admin_role( $value ); |
| 256 | printf( |
| 257 | '<option value="%s" %s %s>%s</option>', |
| 258 | esc_attr( $value ), |
| 259 | selected( in_array( $value, $current, true ) || $admin, true, false ), |
| 260 | disabled( $admin, true, false ), |
| 261 | esc_html( $label ) |
| 262 | ); |
| 263 | } |
| 264 | ?> |
| 265 | </td></select> |
| 266 | </tr> |
| 267 | |
| 268 | <?php endforeach; ?> |
| 269 | |
| 270 | <?php if ( ! empty( $modules_ids ) ) : ?> |
| 271 | <input |
| 272 | name="modules_ids" |
| 273 | type="hidden" |
| 274 | value="<?php echo esc_attr( join( ',', $modules_ids ) ); ?>" |
| 275 | form="<?php echo esc_attr( $form_id ); ?>" |
| 276 | > |
| 277 | <?php endif; ?> |
| 278 | |
| 279 | </tbody> |
| 280 | |
| 281 | </table> |
| 282 | <?php } ?> |
| 283 | |
| 284 | <?php } ?> |
| 285 | |
| 286 | </div> |
| 287 | |
| 288 | </div> |
| 289 |