private function renderString($row, $template) { $result = $template; // First, replace any arrays (format: [[array_name template]]) if (preg_match_all("/\\[\\[([a-zA-Z_0-9]*)\\s(.+?)\\]\\]/", $result, $matches)) { // Iterate through each array template that was matched for ($i = 0; $i < count($matches[0]); $i++) { if (!isset($matches[1]) || !isset($matches[1][$i])) { continue; } if (!isset($matches[2]) || !isset($matches[2][$i])) { continue; } // Get array name and template $array_name = $matches[1][$i]; $array_template = $matches[2][$i]; //error_log($array_name . ":" . $array_template); // Check that array name exists in $row and is of type 'array' if (!isset($row[$array_name]) || gettype($row[$array_name]) != "array") { continue; } //error_log("$array_name is a valid array element"); // Construct the rendered array template $array_result = ""; // This loop iterates over the elements in the array foreach ($row[$array_name] as $array_idx => $array_el) { // Each element in the array must itself be an array if (gettype($array_el) != "array") { continue; } //error_log("Replacing hooks in $array_template"); $array_instance = replaceKeyHooks($array_el, $array_template); // Append the array instance to the overall array result $array_result .= $array_instance; } // Ok, now replace the entire array placeholder with the rendered array $result = str_replace($matches[0][$i], $array_result, $result); } } // Then, replace all remaining scalar values $result = replaceKeyHooks($row, $result); return $result; }
private function renderButton($button_name) { $button = $this->_buttons[$button_name]; $display = isset($button['display']) ? $button['display'] : "show"; if ($display == "hidden") { return ""; } $button_data = array(); $button_data['name'] = $button_name; $button_data['label'] = isset($button['label']) ? $button['label'] : $button_name; $button_data['icon'] = isset($button['icon']) ? $button['icon'] : ""; $button_data['size'] = isset($button['size']) ? $button['size'] : "md"; $button_data['style'] = isset($button['style']) ? $button['style'] : "primary"; $data = isset($button['data']) ? $button['data'] : array(); $button_data['data_disp'] = ""; foreach ($data as $data_name => $data_val) { $button_data['data_disp'] .= "data-{$data_name}='{$data_val}' "; } $button_data['disabled'] = $display == "disabled" ? "disabled" : ""; $type = isset($button['type']) ? $button['type'] : "button"; if ($type == "submit") { $result = "\n <div class='vert-pad'>\n <button name='{{name}}' type='submit' class='btn btn-block btn-{{size}} btn-{{style}}' {{data_disp}} data-loading-text='Please wait...' {{disabled}}><i class='{{icon}}'></i> {{label}}</button>\n </div>"; } else { if ($type == "launch") { $result = "\n <div class='vert-pad'>\n <button name='{{name}}' type='button' class='btn btn-block btn-{{size}} btn-{{style}}' {{data_disp}} {{disabled}} data-toggle='modal'><i class='{{icon}}'></i> {{label}}</button>\n </div>"; } else { if ($type == "cancel") { $result = "\n <div class='vert-pad'>\n <button name='{{name}}' type='button' class='btn btn-block btn-{{size}} btn-{{style}}' {{data_disp}} {{disabled}} data-dismiss='modal'><i class='{{icon}}'></i> {{label}}</button>\n </div>"; } else { $result = "\n <div class='vert-pad'>\n <button name='{{name}}' type='button' class='btn btn-block btn-{{size}} btn-{{style}}' {{data_disp}} {{disabled}}><i class='{{icon}}'></i> {{label}}</button>\n </div>"; } } } return replaceKeyHooks($button_data, $result); }