Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Drilldown which is a Dropdown with indented list structure

// use with setModel and make sure that the model does have a hasMany() reference to iself with the parent_id in order to recursively indent.
// E.g. in model: $this->hasMany('Category','id_parent');
// on page: $f->addField('drilldown','category')->setModel('Model_Category');
  • Loading branch information...
commit 7764098138d0ac7d13892e8da24846b72580638d 1 parent c783547
si4dev authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 misc/lib/Form/Field/drilldown.php
57 misc/lib/Form/Field/drilldown.php
View
@@ -0,0 +1,57 @@
+<?php
+
+// use with setModel and make sure that the model does have a hasMany() reference to iself with the parent_id
+// in order to recursively indent.
+// E.g. in model: $this->hasMany('Category','id_parent');
+// on page: $f->addField('drilldown','category')->setModel('Model_Category');
+
+class Form_Field_Drilldown extends Form_Field_Dropdown {
+ public $drill_ref;
+ public $indent_phrase='---';
+
+ function getValueList(){
+
+ if($this->model){
+ $title=$this->model->getTitleField();
+ $id=$this->model->id_field;
+ if ($this->empty_text){
+ $res=array(''=>$this->empty_text);
+ } else {
+ $res = array();
+ }
+
+ $this->drill_ref=preg_replace('/((^(model_)?)|(_))([a-z])/e', '\'$4\'.strtoupper(\'$5\')', $this->model->short_name); // model_some_thing -> Some_Thing
+
+ if (!isset ($this->model->elements[$this->drill_ref]))
+ throw $this->exception("No ref found, make sure to use hasMany() in model to itself for parent id")
+ ->addMoreInfo('ref',$this->drill_ref);
+
+ if(!$this->model->loaded()) $this->model->tryLoad(1);
+ $res=$this->drill();
+ return $this->value_list=$res;
+ }
+
+ if($this->empty_text && isset($this->value_list[''])){
+ $this->value_list['']=$this->empty_text;
+ }
+ return $this->value_list;
+ }
+
+
+ function drill($prefix='') {
+ $r=array();
+
+ $r[$this->model->id]=$prefix.$this->model->get($this->model->getTitleField());
+ $childs=$this->model->ref($this->drill_ref);
+ foreach($childs as $child) {
+ $this->model=$childs;
+ foreach($this->drill($prefix.$this->indent_phrase) as $key=>$value) { // cannot do array_merge as merge will renumber
+ $r[$key]=$value;
+ }
+ }
+
+ return $r;
+ }
+
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.