Ejemplo n.º 1
0
 /**
  * The method ::getRows should invoke row filtering.
  */
 public function testGetRows()
 {
     $fieldValues = [1, 3];
     $fieldName = "field" . (string) rand();
     $rows = [];
     // Make one row for each of the field values
     foreach ($fieldValues as $fieldValue) {
         $rows[] = RowBuilder::begin()->addWritable(new Field([], [], 'literal', 'A literal field', $fieldValue), $fieldName)->build();
     }
     $filter = FilterBuilder::begin()->setId("myFilter")->setType(Filter::TYPE_STATIC)->setFieldName($fieldName)->setCondition(FilterStatement::COND_GREATER_THAN)->setCriterion(2)->build();
     $table = TableBuilder::begin()->setId("t" . (string) rand())->addRows($rows)->addFilter($filter)->build();
     $this->assertEquals(1, sizeof($table->getRows()));
 }
Ejemplo n.º 2
0
 /**
  * @param QueryWrapperInterface[]|null $queries
  * @return WritableInterface[]
  */
 protected function makeTables($queries = null)
 {
     /** @var WritableInterface[] $tables */
     $tables = [];
     foreach ($this->queries as $queryIndex => $query) {
         $objects = $query->find();
         /** @var RowInterface[] $rows */
         $rows = [];
         /** @var string $tableName */
         $tableName = StringUtils::slugify($query->getTitleCasedObjectName());
         foreach ($objects as $object) {
             /** @var string $detailurl */
             $detailurl = static::makeUrl([static::MODE_FIELD => static::MODE_DETAIL, static::QUERY_INDEX_FIELD => $queryIndex, static::OBJECT_ID_FIELD => $object->getPrimaryKey()]);
             $rows[] = RowBuilder::begin()->addObject($object)->setOnClick("\n                    athens.multi_panel.loadPanel(1, '{$detailurl}');\n                    athens.multi_panel.openPanel(1);\n                    ")->build();
         }
         /** @var string $adderUrl */
         $adderUrl = static::makeUrl([static::MODE_FIELD => static::MODE_DETAIL, static::QUERY_INDEX_FIELD => $queryIndex]);
         $rows[] = RowBuilder::begin()->addWritable(FieldBuilder::begin()->setLabel("adder")->setType(FieldBuilder::TYPE_LITERAL)->addClass('adder')->setInitial("+ Add another")->build(), "adder")->setOnClick("\n                    athens.multi_panel.loadPanel(1, '{$adderUrl}');\n                    athens.multi_panel.openPanel(1);\n                ")->build();
         $tables[] = SectionBuilder::begin()->setId('object-manager-table-wrapper-' . $tableName)->addLabel(ucwords($tableName))->addWritable(TableBuilder::begin()->setId('object-manager-table-' . $tableName)->addRows($rows)->build())->build();
     }
     return $tables;
 }
Ejemplo n.º 3
0
 public function testVisitExcelPage()
 {
     $writer = new ExcelWriter();
     $id = "t" . (string) rand();
     $label = 'Text Field Label';
     $value1 = (string) rand();
     $value2 = (string) rand();
     $field1 = new Field([], [], "text", $label, $value1);
     $field1Name = "TextField1";
     $row1 = RowBuilder::begin()->addWritable($field1, $field1Name)->setColumnLabel($field1Name, $field1Name)->build();
     $field2 = new Field([], [], "text", $label, $value2);
     $field2Name = "TextField2";
     $row2 = RowBuilder::begin()->addWritable($field2, $field2Name)->build();
     $table = TableBuilder::begin()->setId($id)->addRow($row1)->addRow($row2)->build();
     $page = PageBuilder::begin()->setType(PageBuilder::TYPE_EXCEL)->setId('test-excel-page')->addWritable($table)->build();
     // Get result and strip quotes, for easier analysis
     $tmp = tmpfile();
     $fileLocation = stream_get_meta_data($tmp)['uri'];
     fwrite($tmp, $writer->visitPage($page));
     $objReader = new PHPExcel_Reader_Excel2007();
     $objPHPExcel = $objReader->load($fileLocation);
     $worksheet = $objPHPExcel->getSheet(0);
     $this->assertEquals($label, $worksheet->getCell('A1')->getValue());
     $this->assertEquals($value1, $worksheet->getCell('A2')->getValue());
     $this->assertEquals($value2, $worksheet->getCell('A3')->getValue());
 }