function render() { # Should generate via PHPExcel $excel = new PHPExcel(); $sheet = $excel->getActiveSheet(); # Write out headers foreach ($this->f->cols as $index => $column) { $sheet->setCellValueByColumnAndRow($index, 1, $column->header); } # Write out actual data foreach ($this->f->data as $rowIndex => $row) { foreach ($this->f->cols as $colIndex => $col) { $str = $this->byName[$col->name]->makeCSVPart(isget($row[$col->name])); if (is_scalar($str)) { $sheet->setCellValueByColumnAndRow($colIndex, $rowIndex + 2, (string) $str); } else { if (!is_null($str)) { throw new Exception('Invalid CSV part!'); } } } } # Create and return a writer object $objWriter = PHPExcel_IOFactory::createWriter($excel, 'CSV'); return $objWriter; }
function writeArray($parts, $response, $csrfToken = null) { $config = Config::get(); $hashes = new Hashes(); # Unless we're in debug mode, serve minified versions of things like semantic. # Don't bother minifying styles.css and client.js, because their size is tiny # compared to these libraries. $assetMap = $config['debug'] ? [] : ['lib/semantic.css' => 'lib/semantic.min.css', 'lib/semantic.js' => 'lib/semantic.min.js', 'lib/jquery.js' => 'lib/jquery.min.js', 'lib/jquery.inputmask.bundle.js' => 'lib/jquery.inputmask.bundle.min.js']; foreach ($parts as $part) { if (is_string($part)) { $response->append($part); } else { if (isset($part['asset'])) { $part = $part['asset']; $fileName = isget($assetMap[$part], $part); $response->append(preg_replace_callback('/^(.*)\\.(.*)$/', function ($parts) use($fileName, $config, $hashes) { return htmlspecialchars($config['asset-prefix'] . $parts[1] . '.hash-' . $hashes->get($fileName) . '.' . $parts[2], ENT_QUOTES | ENT_HTML5); }, $fileName)); } else { if (isset($part['csrf'])) { $response->append(htmlspecialchars($csrfToken, ENT_QUOTES | ENT_HTML5)); } else { if (isset($part['header'])) { $response->header($part['header'], $part['value']); } else { throw new Exception("Invalid HTML component!"); } } } } } }
public function test_inception() { $this->assertEquals('inception', isget($dream['within_a_dream']['within_a_dream']['within_a_dream']['...'], 'inception'), 'We have to go deeper!'); }
function listValidate($minItems, $maxItems, $name, $items) { return $this->ifOk(function ($list) use($minItems, $maxItems, $name, $items) { $result = Result::ok([]); # Get the indices of the list to test $indices = array_unique(array_merge(array_keys($list[0]), array_keys($list[1]))); sort($indices); # First, determine how many items are in the list, in total. $number = count($indices); # Make sure the number of items provided is between $minItems and $maxItems if ($number < $minItems) { return Result::error([$name => 'Please provide at least ' . $minItems . ' items']); } if ($number > $maxItems) { return Result::error([$name => 'Please provide at most ' . $maxItems . ' items']); } # For each item in the list... foreach ($indices as $index) { # Validate all of the fields within the list $validationResult = Result::ok(new ClientData(isget($list[0][$index], []), isget($list[1][$index], [])))->groupValidate($items); # Combine the result of this validation with the data validated # in previous iterations of the loop. $result = $result->ifOk(function ($soFar) use($validationResult, $index) { return $validationResult->ifOk(function ($fieldResult) use($soFar, $index) { # Combine two successes $soFar[$index] = $fieldResult; return Result::ok($soFar); })->ifError(function ($fieldError) { # If validation fails in one iteration, the end result # must be an error. return Result::error([]); }); })->ifError(function ($errorSoFar) use($validationResult, $index, $name) { return $validationResult->ifError(function ($fieldError) use($errorSoFar, $index, $name) { # Combine two errors, putting things in a format the client JS code can understand. foreach ($fieldError as $k => $v) { $k = explode('[', $k); $kStart = $k[0]; $kRest = count($k) > 1 ? '[' . implode('[', array_slice($k, 1)) : ''; $errorSoFar[$name . '[' . $index . '][' . $kStart . ']' . $kRest] = $v; } return Result::error($errorSoFar); })->ifOk(function ($fieldResult) use($errorSoFar) { # Error + success = original error return Result::error($errorSoFar); }); }); } # If it's a success, name the resulting data properly # for storage in the database. $result = $result->ifOk(function ($x) use($name) { return Result::ok([$name => array_values($x)]); }); return $result; }); }
function __construct($args, $context) { $this->form = $args['byTag']['fields']; $this->title = isset($args['title']) ? $args['title'] : 'Form'; $this->successMessage = isset($args['success-message']) ? $args['success-message'] : 'The form was submitted successfully.'; $this->outputs = $args['byTag']['outputs']; $this->views = $args['byTag']['views']; $this->allowFraming = isget($args['allow-framing'], false); }
static function increment($formID) { self::update(); $counts = self::$data; $counts->{$formID} = isget($counts->{$formID}, 0) + 1; self::$data = $counts; self::write(); }