Esempio n. 1
0
 public function customboolean($name, $checked = null, $options = [], $unset = '0', $value = 1)
 {
     $options = $this->cleanAttributes($options);
     return $this->rawcontent(PkForm::boolean($name, $checked, $options, hpure($unset), hpure($value)));
 }
Esempio n. 2
0
 /**
 *The Templating Injection! Very powerful & flexible, with reusable
 * htmlRenderer mini-templates. Can even have default values. Example:
 * 
 * 
 * #Template:
    $wrap_tpl = new PkHtmlRenderer();
    $wrap_tpl[] = "<div  class='";
    $wrap_tpl['wrapper_class'] = 'col-xs-3 tpm-wrapper'; #Default
    $wrap_tpl[] = "'>\n<div  class='block tpm-label'>\n";
    $wrap_tpl['label']=null|true; #Replace - if null, hpure, if true, raw
    $wrap_tpl[] = "</div>\n<div  class='block tpm-value'>\n";
    $wrap_tpl['input'] = null|true; #Replace - if null, hpure, if true, raw
    $wrap_tpl[] = "</div>\n</div>\n";
 * 
 * #Call:
      PkRenderer::inject([
          'label'=>"First Name",
          'input'=>PkForm::text('fname', null, ['placeholder' => 'First Name','class'=>'pk-inp']),
      ],$wrap_tpl,['input']),
 
 *  
 * @param assoc $arr: The key/values to insert in the template - OR, if not
 *   an array, a "stringish" value (could be a PartialSet) inserted into
 *   $tpl at default "content":  <tt>$tpl['content']=$arr;</tt>
 * @param PartialSet|null: $tpl: A PartialSet/Renderer with indices matching
 * the value keys of the input array
 * @param array $rawkeys - alternate method for specifying a "raw" input
 * 
 * @return PkHtmlRenderer - with data inserted in the template
 */
 public function inject($arr, $tpl = null, $rawkeys = [])
 {
     //pkdebug("ARR:",$arr,"TPL", $tpl);
     if (!is_array($arr) && is_stringish($arr)) {
         $arr = ['content' => $arr];
     }
     if ($tpl instanceof PartialSet) {
         $tpl = $tpl->copy();
     } else {
         $tpl = new PkHtmlRenderer();
     }
     foreach ($arr as $key => $val) {
         $raw = keyVal($key, $tpl) === true || in_array($key, $rawkeys, true);
         if (!$raw) {
             $val = hpure($val);
         }
         $tpl[$key] = $val;
     }
     return $this->content($tpl, true);
 }
Esempio n. 3
0
 /** Should we convert all int attributes with value of '' to null? Let's try
  * 
  * @param array $opts
  * @return type
  * @throws Exception
  */
 public function save(array $opts = [])
 {
     if ($this->useBuildFillableOptions) {
         foreach ($this->fillableOptions as $field => $value) {
             if (is_array($value)) {
                 $allowedVals = array_keys($value);
                 if (!in_array($this->{$field}, $allowedVals)) {
                     unset($this->{$field});
                 }
             }
         }
     }
     if ($this->emptyStringToNull) {
         $this->convertEmptyStringToNullForNumerics();
     }
     #Clean dangerous HTML from specified fields
     foreach (static::$escape_fields as $field) {
         if ($this->{$field}) {
             $this->{$field} = hpure($this->{$field});
         }
     }
     if (!$this->authUpdate()) {
         throw new Exception("Not authorized to update this record");
     }
     $result = parent::save($opts);
     if ($result) {
         $this->postSave($opts);
     }
     return $result;
 }