<commit_before># iep-printing-php
iep-printing-php is the server side part of the [iep-printing](https://github.com/IronCountySchoolDistrict/iep-printing) project. This application uses the pdftk toolkit to fill out pdf files for printing with data collected with the PowerSchool plugin `FormBuilder`.

## Installation
Make sure you have composer installed on your machine. Clone the repository. Run `composer install` in the root folder to install laravel and other dependency packages. Take a look at the [laravel documentation](http://laravel.com/docs/5.0) for specifics on the laravel framework.

Run `composer update` on subsequent updates.

## Configuration
Directories within the `storage` and the `bootstrap/cache` directories should be writable by your web server.

Where the fillable pdf files reside can be configured in `app/iep.php`. The value is defaulted to `storage/forms` directory.

## php-pdftk
Pdftk-php is a php wrapper to the pdftk server toolkit which is what is used to handle all the pdf files. See the [original repo](https://github.com/mikehaertl/php-pdftk) on some of its usage. iep-printing-php extends the class to include the `$fields` property on the object, which is generated from fdf data after the pdf file is loaded.

### Setting fields
Set all the fields at once.

```php
$array = [
  'name' => '<NAME>',
  'dob' => 'Jan 1, 1972'
];

$pdf->setFields($array);

// or

$pdf->fields = $array;
```

Set a single field

```php
$pdf->setField($key, $value);

// or

$pdf->fields[$key] = $value;
```

## How to create logic to fill out a form
This is an example object of what you can expect. This will be json_decode()ed into a standard php class and thats how you can use it.

```json
[
  {
    "form": {
      "id": 123456,
      "title": "IEP: SpEd 05-1  v.150501",
      "description": "PLAFFP",
      "type": "P"
    },
    "response": [
      {
        "field": "iep-meeting",
        "type": "text",
        "response": "01/02/2003"
      },
      {
        "field": "classification",
        "type": "dropdown",
        "response": "Hearing Impariment/Deafness"
      }
    ]
  },
  ...
]
```

The pdf files must be named after the form->title without `IEP:`. In this case iep-printing-php will look for the pdf file named `SpEd 05-1 v.150501.pdf` wherever your forms are stored.

### Blade templates (where the magic happens)
iep-printing-php uses the [laravel's blade templates](http://laravel.com/docs/5.0/templates), not for html, but for creating dynamic scripts by including reusable logic easily.

#### Template naming convention
Create a file in `resources/views/iep/forms` named the form title with `IEP:` and all `.` characters stripped out with the extension `blade.php`. Continuing our example we would name this file `SpEd 05-1 v150501.blade.php`.
<commit_msg>Added server requirements section and more to the config section that explains setting up queues and processing them.<commit_after># iep-printing-php
iep-printing-php is the server side part of the [iep-printing](https://github.com/IronCountySchoolDistrict/iep-printing) project. This application uses the pdftk toolkit to fill out pdf files for printing with data collected with the PowerSchool plugin `FormBuilder`.

## Installation
### Server requirements
- See [laravel requirements](http://laravel.com/docs/5.0#server-requirements)
- [Composer](https://getcomposer.org/)
- [pdftk](https://www.pdflabs.com/tools/pdftk-server/)
- [zip](http://manpages.ubuntu.com/manpages/raring/man1/zip.1.html)
- [beanstalkd](http://kr.github.io/beanstalkd/) (Optional)

### Setup
- Run `git clone` on this repository
- Run `composer install` in the root of the cloned repository
- Run `composer update` on subsequent pulls

### Configuration
Directories within the `storage` and the `bootstrap/cache` directories should be writable by your web server as well as the `public` directory.

Where the fillable pdf files reside can be configured in `app/iep.php`. The value is defaulted to `storage/forms` directory.

By default, iep-printing-php is set up to keep all pdf and zip files it generates. You can either create a cron job that deletes these files in the public folder or change the default driver in `app/queue.php` from null to beanstalkd. By running `php artisan queue:listen` this will delete the files 10 minutes after they are generated.

## php-pdftk
php-pdftk is a php wrapper to the pdftk server toolkit which is what is used to handle all the pdf files. See the [original repo](https://github.com/mikehaertl/php-pdftk) on some of its usage. iep-printing-php extends the class to include the `$fields` property on the object, which is generated from fdf data after the pdf file is loaded.

### Setting fields
Set all the fields at once.

```php
$array = [
  'name' => '<NAME>',
  'dob' => 'Jan 1, 1972'
];

$pdf->setFields($array);

// or

$pdf->fields = $array;
```

Set a single field

```php
$pdf->setField($key, $value);

// or

$pdf->fields[$key] = $value;
```

## How to create logic to fill out a form
This is an example object of what you can expect. This will be json_decode()ed into a standard php class and thats how you can use it.

```json
[
  {
    "form": {
      "id": 123456,
      "title": "IEP: SpEd 05-1  v.150501",
      "description": "PLAFFP",
      "type": "P"
    },
    "response": [
      {
        "field": "iep-meeting",
        "type": "text",
        "response": "01/02/2003"
      },
      {
        "field": "classification",
        "type": "dropdown",
        "response": "Hearing Impariment/Deafness"
      }
    ]
  },
  ...
]
```

**!Important**: Note that the response->field value is the Custom Css Class set in FormBuilder in Powerschool. This is how you will create logic that will actually be able to match fields in FormBuilder to fields in it's corresponding pdf.

The pdf files must be named after the form->title without `IEP:`. In this case iep-printing-php will look for the pdf file named `SpEd 05-1 v.150501.pdf` wherever your forms are stored.

### Blade templates (where the magic happens)
iep-printing-php uses the [laravel's blade templates](http://laravel.com/docs/5.0/templates), not for html, but for creating dynamic scripts by including reusable logic easily.

#### Template naming convention
Create a file in `resources/views/iep/forms` named the form title with `IEP:` and all `.` characters stripped out with the extension `blade.php`. Continuing our example we would name this file `SpEd 05-1 v150501.blade.php`.

{'fraction_non_alphanumeric': 0.11225746843239914, 'fraction_numerical': 0.016014782876501387, 'mean_word_length': 3.6559139784946235, 'pattern_counts': {'":': 24, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4057708', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1932, 'n_words': 805}