Пример #1
0
/** Builds a templatable many to one subform, whith exit/create/delete of items.
 * @param string $subform - standard view/template specifier, like
 *  <tt>'project.forms.edititems-subform'</tt>
 * @param array $args - Associatice array of optional args
 * 'templatable_data_sets_class' => optional additional classes to add to the templatable-data-sets div.
 * 'params' => optional array of additional parameters to be passed to the subform
 * 'collection_name' => the relationship name used by it's owning class, like 'items'
 * 'item_name' => The name the subform uses for it's variable/model
 * 'collection' => the collection of existing instances, like, $project->items;
 * 'create_button_label' => How to label the "New Item" button
 * 'create_button_class' => additional classes to add to the create/new button
 */
function multiSubform($subform, $args = [])
{
    $templatable_data_sets_class = keyValOrDefault('templatable_data_sets_class', $args);
    $collection = keyValOrDefault('collection', $args, []);
    if (!is_iterable($collection)) {
        $collection = [];
    }
    $item_name = keyValOrDefault('item_name', $args, 'item');
    $collection_name = keyValOrDefault('collection_name', $args, 'items');
    $create_button_label = keyValOrDefault('create_button_label', $args, 'New Item');
    $params[$collection_name] = keyValOrDefault($collection_name, $args);
    $params = keyValOrDefault('params', $args, []);
    $out = "\n<div class='templatable-data-sets {$templatable_data_sets_class}'>\n";
    $out .= "<input type='hidden' name='{$collection_name}' value='' />\n";
    $idx = -1;
    if (count($collection)) {
        foreach ($collection as $idx => $data) {
            $params = $params;
            $params[$item_name] = $data;
            $params['idx'] = $idx;
            $out .= view($subform, $params) . "\n";
        }
    }
    $out .= "\n    <div class='js btn create-new-data-set pkmvc-button'\n      data-itemcount='" . ++$idx . "'>{$create_button_label}\n  </div>\n";
    $out .= "<fieldset class='template-container hidden' disabled >\n";
    $params['idx'] = "__CNT_TPL__";
    $params[$item_name] = new Universal();
    $out .= view($subform, $params);
    $out .= "\n</fieldset>\n";
    $out .= "</div>\n";
    return $out;
}
Пример #2
0
 /** Build a template HTML to create and delete one-to-many relations in a form
  * 
  * @param string $subform - standard view/template specifier, like
  *  <tt>'project.forms.edititems-subform'</tt>
  * @param array $args - Associatice array of optional args
  * 'templatable_data_sets_class' => optional additional classes to add to the templatable-data-sets div.
  * 'params' => optional array of additional parameters to be passed to the subform
  * 'collection_name' => the relationship name used by it's owning class, like 'items'
  * 'item_name' => The name the subform uses for it's variable/model
  * 'dataset' => the collection of existing instances, like, $project->items;
  * 'create_button_label' => How to label the "New Item" button
  * 'create_button_class' => additional classes to add to the create/new button
  */
 public function __construct($subform, $args = [])
 {
     $this->templatable_data_sets_class = keyValOrDefault('templatable_data_sets_class', $args, '');
     $this->dataset = keyValOrDefault('dataset', $args, []);
     $this->item_name = keyValOrDefault('item_name', $args, 'item');
     $this->collection_name = keyValOrDefault('collection_name', $args, 'items');
     $this->create_button_label = keyValOrDefault('create_button_label', $args, 'New Item');
     $this->params[$this->collection_name] = keyValOrDefault($this->collection_name, $args);
     if (!is_iterable($this->dataset)) {
         $this->dataset = [];
     }
     $this->subform = $subform;
     $this->params = keyValOrDefault('params', $args, []);
 }
Пример #3
0
 /** Not an action - but checks if the POST/Submission is for an
  * array/collection of models without an owner. It does this by checking
  * if the POST key 'modelset' exists - which should have the value of the
  * fully qualified 'App\Models\Item' model name or whatever.
  * @return false | ModelName
  */
 public function isModelSetSubmit()
 {
     if (Request::method() !== 'POST') {
         return false;
     }
     $data = Request::all();
     return keyValOrDefault('modelset', $data, false);
 }
Пример #4
0
/** Just shorter */
function keyVal($key = '', $container = [], $default = null, $forceAttrGet = false) {
  return keyValOrDefault($key, $container, $default, $forceAttrGet);
}
Пример #5
0
 /**
  * Returns the "description" for a given $refArray and index.
  * @param array $refVar - reference array of int keys to Enum names/labels
  * like, <tt>[1=>"Mixed Construction Debris", 2=>"Source Separated",]</tt>
  * @param mixed $idx - key for the ref array
  * @return string - the name/label, or "Not Set"
  */
 public function showRefItemName(array $refVar, $idx = null)
 {
     if (!is_array($refVar) || !$idx) {
         return "Not Set";
     }
     return keyValOrDefault($idx, $refVar, "Not Set");
 }