Ejemplo n.º 1
0
 public function testItemsReturnCorrectNumberOfItems()
 {
     $presenter = new DatagridPresenter();
     $grid = new Datagrid('testgrid', 'testgrid', new DataList('DatagridTest_Person'));
     $presenter->setDatagrid($grid);
     $this->assertEquals(2, $presenter->Items()->count());
 }
Ejemplo n.º 2
0
 /**
  *
  * @return DatagridPresenter
  */
 public function getDatagridPresenter()
 {
     if (!$this->datagridPresenter) {
         $this->datagridPresenter = new $this->dataPresenterClassName();
         $this->datagridPresenter->setDatagrid($this);
     }
     return $this->datagridPresenter;
 }
Ejemplo n.º 3
0
 /**
  *
  * @param bool $xmlSafe
  * @return ArrayList 
  */
 public function Fields($xmlSafe = true)
 {
     $list = $this->parent->FieldList();
     $counter = 0;
     foreach ($list as $fieldName => $fieldTitle) {
         $value = "";
         // TODO Delegates that to DataList
         // This supports simple FieldName syntax
         if (strpos($fieldName, '.') === false) {
             $value = $this->item->XML_val($fieldName) && $xmlSafe ? $this->item->XML_val($fieldName) : $this->item->RAW_val($fieldName);
             // This support the syntax fieldName = Relation.RelatedField
         } else {
             $fieldNameParts = explode('.', $fieldName);
             $tmpItem = $this->item;
             for ($j = 0; $j < sizeof($fieldNameParts); $j++) {
                 $relationMethod = $fieldNameParts[$j];
                 $idField = $relationMethod . 'ID';
                 if ($j == sizeof($fieldNameParts) - 1) {
                     if ($tmpItem) {
                         $value = $tmpItem->{$relationMethod};
                     }
                 } else {
                     if ($tmpItem) {
                         $tmpItem = $tmpItem->{$relationMethod}();
                     }
                 }
             }
         }
         // casting
         if (array_key_exists($fieldName, $this->parent->fieldCasting)) {
             $value = $this->parent->getCastedValue($value, $this->parent->fieldCasting[$fieldName]);
         } elseif (is_object($value) && method_exists($value, 'Nice')) {
             $value = $value->Nice();
         }
         // formatting
         $item = $this->item;
         if (array_key_exists($fieldName, $this->parent->fieldFormatting)) {
             $format = str_replace('$value', "__VAL__", $this->parent->fieldFormatting[$fieldName]);
             $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$item->$1', $format);
             $format = str_replace('__VAL__', '$value', $format);
             eval('$value = "' . $format . '";');
         }
         //escape
         if ($escape = $this->parent->getDatagrid()->fieldEscape) {
             foreach ($escape as $search => $replace) {
                 $value = str_replace($search, $replace, $value);
             }
         }
         $arrayData = new ArrayData(array("Name" => $fieldName, "Title" => $fieldTitle, "Value" => $value));
         $arrayData->iteratorProperties($counter++, count($list));
         $fields[] = $arrayData;
     }
     return new ArrayList($fields);
 }