Example #1
0
/** Seems nutty, but take two associative arrays of attribute arrays, and
 * merge them with the above method, only for the given keys
 * @param type $keys
 * @param type $arr1
 * @param type $arr2
 */
function merge_att_arrs($keys, $arr1=[], $arr2 = []) {
  if (!$keys) return [];
  if (ne_string($keys)) {
    return merge_attributes(keyVal($keys,$arr1), keyVal($keys,$arr2));
  }
  $out = [];
  foreach ($keys as $key) {
    $out[$key] = merge_attributes(keyVal($key,$arr1), keyVal($key,$arr2));
  }
  return $out;
}
Example #2
0
 /**
 * Wraps two elements, each in a containing element, the wraps the pair in
 * a third, containing element. The optional attributes are MERGED with the
 * default attributes, but the default attributes can be set on construct.
 * @param html $val
 * @param html $lbl
 * @param array $args - optional attributes for each of the 3 elements, keyed:
      'labelAttributes' => []
      'valueAttributes' => []
      'wrapperAttributes' => []
 *   
 */
 public function pair($val, $lbl = null, $args = [])
 {
     $defaults = ['labelAttributes' => $this->labelAttributes, 'valueAttributes' => $this->valueAttributes, 'wrapperAttributes' => $this->wrapperAttributes];
     if (ne_string($args)) {
         #If just a string, it's the wrapper class
         $args = ['wrapperAttributes' => ['class' => $args]];
     }
     $labelAttributes = merge_att_arrs('labelAttributes', $defaults, $args);
     $valueAttributes = merge_att_arrs('valueAttributes', $defaults, $args);
     $wrapperAttributes = merge_att_arrs('wrapperAttributes', $defaults, $args);
     $labelTag = keyVal('tag', $labelAttributes, 'div');
     unset($labelAttributes['tag']);
     $wrapTag = keyVal('tag', $wrapperAttributes, 'div');
     unset($wrapperAttributes['tag']);
     $valueTag = keyVal('tag', $valueAttributes, 'div');
     unset($valueAttributes['tag']);
     $pkt = new self();
     $pkt->{$labelTag}($lbl, $labelAttributes);
     $pkt->{$valueTag}($val, $valueAttributes);
     return $this->fresh()->{$wrapTag}($pkt, $wrapperAttributes);
 }
Example #3
0
 /**
  * Outputs an html table row
  * @param array|string $data - the array of columns to output (string if only one)
  *   BUT if an element of $data is an array, is ['val'=>$value,'coltag'=>$tag,'colatts'=>$attributes]
  * @param string|array $opts
  *   if string, the th or (default) td tag to use for the columns
  * @return html table row string
  */
 public function tablerow($data = [], $opts = 'td')
 {
     //pkdebug("Data:",$data);
     if (!is_array($data)) {
         $data = [$data];
     }
     if (is_string($opts)) {
         $opts = ['coltag' => $opts];
     }
     if (is_array($opts)) {
         $coltag = keyVal('coltag', $opts, 'td');
         $rowclass = keyVal('row_class', $opts);
         if (ne_string($rowclass)) {
             $rowclass = " class='{$rowclass}'";
         }
     }
     //$this[]="<tr>\n";
     $this->rawcontent("<tr {$rowclass}>\n");
     foreach ($data as $idx => $datum) {
         if (!is_array($datum)) {
             $datum = ['value' => $datum];
         }
         $value = keyVal('value', $datum);
         $lcoltag = keyVal('coltag', $datum, $coltag);
         $latts = keyVal('colatts', $datum);
         //pkdebug( "About to return:  <$lcoltag $latts>$value</$lcoltag>\n");
         $this->rawcontent("  <{$lcoltag} {$latts}>{$value}</{$lcoltag}>\n");
     }
     //$this[]="</tr>\n";
     return $this->rawcontent("</tr>\n");
 }
Example #4
0
 /** Takes packaged HTML for a jQuery dialog, encodes it into an element
  * data-dialog-encoded attribute, assigns the jQuery class, & returns it,
  * ready to click on & pop.
  * @param type $dlg
  * @param type $args
  */
 public function encodeDlgInEl($dlg, $args = [])
 {
     if (!$args) {
         $args = [];
     }
     if (ne_string($args)) {
         $args = ['class' => $args];
     }
     $defaults = ['class' => 'pkmvc-button', 'content' => 'Click', 'tag' => 'div'];
     $requiredClass = 'js-dialog-button';
     $params = array_merge($defaults, $args);
     $extraClass = keyVal('extra_class', $params);
     unset($params['extra_class']);
     $content = $params['content'];
     unset($params['content']);
     $tag = $params['tag'];
     unset($params['tag']);
     $atts = merge_attributes($params, "{$requiredClass} {$extraClass}");
     $atts['data-dialog-encoded'] = html_encode($dlg);
     return PkRenderer::$tag($content, $atts);
 }
Example #5
0
function dollar_format($num, $opts = 0, $hide0 = false) {
  if ($opts === null) $db=1; else $db=0;
  if (!is_array($opts)) {
    if (is_intish($opts) && ($opts !== true)) $opts = ['prec' => $opts];
    else if (ne_string($opts) || ($opts === true))
        $opts = ['wrap_class' => $opts];
    else $opts = [];
  }
  $prec = keyVal('prec', $opts, 0);
  $wrap_class = keyVal('wrap_class', $opts);
  if ($wrap_class === true) $wrap_class = "dollar-format";
  $hide0 = keyVal('hide0', $opts, $hide0);
  if (is_array($num)) {
    $num = array_sum($num);
  }
  //if($db)pkdebug('hide0', $hide0, 'num', $num, 'wrap-class',$wrap_class,'prec',$prec);
  if (($num === null) || ($num === '') || ($hide0 && !$num)) return '';
  $formatted = '$' . number_format($num, $prec);
  if (!$wrap_class) return $formatted;
  if ($num < 0) {
    $wrap_class.= ' negative-dollar-value';
  }
  return "<div class='pk-dollar-value $wrap_class'>$formatted</div>\n";
}
Example #6
0
 /** 
  If the key of displayvalues is a method, the class it points to must implement
  the PkDisplayValueInterface - then the method is called, with the optional args,
  and the result of the method is processed by the DisplayValueInterface class
  and THAT result is returned. Dollar or Percent Formatting, for example.
 */
 public function displayValueMethod($methodName, $args = [])
 {
     if (!ne_string($methodName)) {
         return null;
     }
     //$class=get_class($this);
     $refmaps = static::getDisplayValueFields(true);
     foreach ($refmaps as $fn => $rc) {
         if (!ne_string($fn) || !ne_string($rc) || !class_exists($rc) || !in_array('PkExtensions\\PkDisplayValueInterface', class_implements($rc))) {
             continue;
         }
         if ($fn === $methodName) {
             $value = call_user_func_array([$this, $methodName], $args);
             return $rc::displayValue($value);
         }
     }
 }