Ejemplo n.º 1
0
/**
 * 
 * @param type $items
 * @param type $opts
 */
function grid_layout($items, $opts=[]) {
  $defaults = [
    'num_columns' => 12,
    'items_per_row' => 3,
    'row_class' => '',
    'col_class' => '',#Additional column class
  ];
  $params = getParamsOrDefault($opts, $defaults);
  extract($params);
  if ($items instanceOf PartialSet) {
    $numitems = $items->sizeOf();
  } else {
    $numitems = count($items);
  }
  $item_width = $num_columns/$items_per_row;
  $numcols = count($items);
  $colclass = "col-xs-$item_width $col_class";
  $grout = new PkHtmlRenderer();
  $grout->rawdiv(RENDEROPEN,"row $row_class");
    foreach ($items as $i=>$item) {
      $grout->rawdiv($item,$colclass);
      if (($i+1 <$numitems) && !(($i+1) % $items_per_row) ) {
        $grout->RENDERCLOSE();
        $grout->rawdiv(RENDEROPEN,"row $row_class");
      }
    }
  $grout->RENDERCLOSE();
  return $grout;
}
Ejemplo n.º 2
0
  /** For use in Query Forms - makes a full query control
   * from the field name and comparison type, with $params
   * 
   * For now, only handle simple _crit, _val comparisons
   * with $params['basename']
   * 
   * @param assoc array $params:
   *   @paramParam: string 'basename' (required): The basename of the field to search - like,
   *   'annual_income' - will build a criteria select box called "annual_income_crit'
   *      ("<", ">", etc)
   *    and a value input box named 'annual_income_val'
   * 
   * @paramParam string 'label' (optional, suggested) - the label for the control
   * 
   * 
   * @return string HTML to make the control
   */
   
  public static function htmlQueryControl($params=[]) {
    $basename = $params['basename'];
    $queryDef = static::getFullQueryDef($basename);
    //pkdebug("queryDef:", $queryDef);
    $criteriaSet = keyVal('criteriaSet', $params);
    if (!$criteriaSet) {
      $criteriaSet = keyVal('criteriaSet', $queryDef);
    //pkdebug("criteriaSet:", $criteriaSet);
      if (!$criteriaSet) {
        $criteria = keyVal('criteria', $queryDef);
        if (ne_arrayish($criteria)) {
          $criteriaSet = keyVal('criteriaSet',$criteria);
    //pkdebug("criteriaSet:", $criteriaSet);
        }
      }
      if (!$criteriaSet) { #No custom criteriaSet, so default
        $comptype = keyVal('comptype', $queryDef, 'numeric');
        $criteriaSet = PkMatch::getCriteriaSets($comptype);
    //pkdebug("criteriaSet:", $criteriaSet);
      }
    }
    //pkdebug("criteriaSet:", $criteriaSet);
    $params['criteriaSet'] = $criteriaSet;
    /*
    $fieldDefArr = keyVal('field_defs', $queryDef);
    if (ne_array($fieldDefArr)) {
      $fieldNames = array_keys($fieldDefArr);
    } else {
      $fieldNames = [$basename.'_crit', $basename.'_val'];
    }
    $critName  = null;
    $valName  = null;
    foreach ($fieldNames as $i => $fieldName) {
      if (removeEndStr($fieldName, '_crit')) {
        $critName = $fieldName;
        unset ($fieldNames[$i]);
      }
      if (removeEndStr($fieldName, '_val')) {
        $valName = $fieldName;
        unset ($fieldNames[$i]);
      }
    }
     * 
     */
    $tmpCtl =  PkHtmlRenderer::buildQuerySet($params);
    //pkdebug("TMPCTL: \n$tmpCtl\n");

    return PkHtmlRenderer::buildQuerySet($params);
    //pkdebug("The QueryDef for [ $basename ]:", $fieldDef);
  }
 public function select($name, $list = [], $selected = null, $options = [])
 {
     if (is_arrayish($name)) {
         $name = keyVal('name', $name);
         $list = keyVal('list', $name, $list);
         $selected = keyVal('selected', $name, $selected);
         $options = keyVal('options', $name, $options);
     }
     $options = $this->cleanAttributes($options);
     $selected = $options['selected'] = $this->fieldValueTemplate($name);
     $options['name'] = keyVal('name', $options, $name);
     $options['data-selected'] = $selected;
     return parent::select($name, $list, $selected, $options);
 }
Ejemplo n.º 4
0
 /**
  * Make an Ajax clickable component, assuming JS support.
  *
  * Makes an arbitrary DOM element that has the data attribute:
  * <tt>data-pk-ajax-element</tt>
  * so clicking will automatically perform an AJAX call.
  * The URL for the call will be in 'data-ajax-url', and so on 
  * @param  array|string  $options:
  *   In simplest form, $options is a string with the ajax-url to call.
  *   Then just render a button, with content/label $content
  *   If is_array($options), can contain all arguments - 
  *    - Normal HTML attributes, plus optionally:
  *   'params' => [$key1=>$val2, $key2=>$val2,] data param arr for AJAX
  * 
  * 
  *  'attr-target' => string: 'name of attribute target_to_recieve_response
  *  'selector-target' => string: The selector that matches this element or child - replace inner HTML with response
  *  'func-target' => string: The name of the JS function to be called with fn(click_target, data, func_arg)
  * 
  *   'attr-arg' => mixed - scalar or array use after AJAX to set the named attribute with.
  *         If an array, expect the AJAX return is a key to the array, to get the value
  *   'selector-arg' => mixed - scalar or array use after AJAX to set the
  *       inner HTML of the matched element with. If array, AJAX return key to the array, to get the value
  * 
  *   'func-arg' => mixed - scalar or array to be passed to the JS function from this component
  * 
  *   If no targets are set, the return from the AJAX call does nothing
  * 
  * @param string $tag - the HTML element to make clickable
  * @param  string $content - the content of the HTML element, if it's a content type
  * 
  * @return \Illuminate\Support\HtmlString
  */
 public function ajaxElement($options = [], $content = null, $ajax_url = null, $tag = 'button')
 {
     if (is_string($options)) {
         $options = ['ajax-url' => $options];
     }
     $options[] = 'data-pk-ajax-element';
     $content = keyVal('content', $options, $content);
     unset($options['content']);
     $options['data-ajax-url'] = keyVal('ajax-url', $options, $ajax_url);
     unset($options['ajax-url']);
     if (empty($options['data-ajax-url'])) {
         throw new \Exception("No AJAX URL for AJAX Element");
     }
     $tag = keyVal('tag', $options, $tag);
     if ($tag === 'button') {
         $options['type'] = keyVal('type', $options, 'button');
     }
     if (empty($options['params'])) {
         $options['data-ajax-params'] = '';
     } else {
         $options['data-ajax-params'] = http_build_query($options['params']);
     }
     unset($options['params']);
     $options['data-attr-target'] = keyVal('attr-target', $options);
     unset($options['attr-target']);
     $options['data-selector-target'] = keyVal('selector-target', $options);
     unset($options['selector-target']);
     $options['data-func-target'] = keyVal('func-target', $options);
     unset($options['func-target']);
     #JSON encode target-args - but convert empty array to empty obj manually
     if (array_key_exists('func-arg', $options)) {
         if ($options['func-arg'] === []) {
             $options['data-func-arg'] = '{}';
         } else {
             $options['data-func-arg'] = json_encode($options['func-arg']);
         }
         unset($options['func-arg']);
     }
     #JSON encode target-args - but convert empty array to empty obj manually
     if (array_key_exists('attr-arg', $options)) {
         if ($options['attr-arg'] === []) {
             $options['data-attr-arg'] = '{}';
         } else {
             $options['data-attr-arg'] = json_encode($options['attr-arg']);
         }
         unset($options['attr-arg']);
     }
     #JSON encode target-args - but convert empty array to empty obj manually
     if (array_key_exists('selector-arg', $options)) {
         if ($options['selector-arg'] === []) {
             $options['data-selector-arg'] = '{}';
         } else {
             $options['data-selector-arg'] = json_encode($options['selector-arg']);
         }
         unset($options['selector-arg']);
     }
     pkdebug('options', $options);
     if (PkHtmlRenderer::contentTag($tag)) {
         return $this->toHtmlString("<{$tag}" . $this->html->attributes($options) . '>' . $content . "</{$tag}>\n");
     }
     if (PkHtmlRenderer::selfClosingTag($tag)) {
         #Ignore content
         return $this->toHtmlString("<{$tag}" . $this->html->attributes($options) . ' />');
     }
     throw new PkException("Invalid args to ajaxElement");
 }
Ejemplo n.º 5
0
 /** Just the simplest of table generators for q & d output. If $header 
  * 
  * @param 2 dimen array, $data - even if empty.
  * @param array|scalar|null $header
  */
 public function mkTbl($data = [], $header = null, $args = null)
 {
     if ($header && is_simple($header)) {
         $header = [$header];
     }
     $fullRow = count($header) === 1 ? ['colspan' => 99] : [];
     $thb = new PkHtmlRenderer();
     foreach ($header as $th) {
         $thb->rawth($th, $fullRow);
     }
     $trb = PkRenderer::tr($thb);
     foreach ($data as $dr) {
         $tdb = new PkHtmlRenderer();
         foreach ($dr as $td) {
             $tdb->rawtd($td);
         }
         $trb->tr($tdb);
     }
     return PkRenderer::table($trb, $this->defaultTblClass);
 }
<?php

/** Blade Template, with PkHtmlRenderer & PkMultiSubformRenderer - for scrolling subforms (Cart=>items) */
use PkExtensions\Models\PkModel;
use App\Models\Client;
use PkExtensions\PkHtmlRenderer;
use PkExtensions\PkMultiSubformRenderer;
use App\References\DiagnosisRef;
$out = new PkHtmlRenderer();
$infoout = new PkHtmlRenderer();
$diagnoses = $client->diagnoses;
$diagrows = [];
foreach ($diagnoses as $diagnosis) {
    $diagrows[] = ['diagnosiscode_id' => $diagnosis->diagnosiscode_id, 'id' => $diagnosis->id];
}
$diagsf = new PkMultiSubformRenderer(['basename' => 'diagnoses', 'tpl_fields' => ['id', 'diagnosiscode_id']]);
//Test adding attributes
$diagsf->append_atts('create_button', 'tst-create-btn-class');
$diagsf->append_atts('deletable_dataset', 'row');
#To put the Delete button in a row
$diagsf->append_atts('delete_button_wrap', 'col-xs-3');
#To put the Delete button in a row
$diagsf->append_atts('js_template', ['class' => 'tst-add-class-arr']);
$diagsf->subform_data = $diagrows;
$diagsf->hidden('id');
//$diagsf->text('diagnosiscode_id');
$diagsf->select('diagnosiscode_id', DiagnosisRef::getSelectList(true, true));
$out[] = PkForm::model($client);
$infoout->wrap(['value' => PkForm::text('fname', null, ['placeholder' => 'First Name']), 'raw' => true, 'label' => 'Client First Name', 'labelAttributes' => 'block tpm-label', 'valueAttributes' => 'block tpm-value', 'wrapperAttributes' => 'col-xs-4 tpm-wrapper']);
#Note arguement 'true' to ::getRefArr(true) - prepends null=>'None' to array
$infoout->wrap(['value' => PkForm::select('insurance_status_id', App\References\InsuranceStatusRef::getRefArr(true), null), 'raw' => true, 'label' => 'Insurance Status', 'labelAttributes' => 'block tpm-label', 'valueAttributes' => 'block tpm-value', 'wrapperAttributes' => 'col-xs-4 tpm-wrapper']);