Пример #1
0
 /**
  * @return RowInterface[]
  * @throws \Exception
  */
 public static function makeRows()
 {
     $rows = [];
     for ($i = 0; $i < 100; $i++) {
         $rows[] = RowBuilder::begin()->addWritable(new Field([], [], "literal", "a literal field", rand(1, 100)), Utils::INT_FIELD_NAME)->addWritable(new Field([], [], "literal", "a literal field", (string) rand()), Utils::STRING_FIELD_NAME)->build();
     }
     return $rows;
 }
Пример #2
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()));
 }
Пример #3
0
 /**
  * @expectedException              Exception
  * @expectedExceptionMessageRegExp #You cannot both make a.*#
  */
 public function testBuilderThrowsExceptionSetContentOnAjaxLoaded()
 {
     $row = RowBuilder::begin()->addWritable(new Field([], [], 'literal', 'A literal field', []), "fieldName")->setHighlightable(true)->setOnClick("console.log('Click');")->build();
     RowBuilder::begin()->addLabel('bla');
 }
Пример #4
0
 public function testSearchFilterMakeOptions()
 {
     $filter = FilterBuilder::begin()->setId("search")->setType(Filter::TYPE_SEARCH)->build();
     $field1 = new Field([], [], "text", "Text Field Label", (string) rand());
     $field1Name = "TextField1";
     $field2 = new Field([], [], "text", "Text Field Label", (string) rand());
     $field2Name = "TextField2";
     $row = RowBuilder::begin()->addWritable($field1, $field1Name)->addWritable($field2, $field2Name)->build();
     $filter->rowFilter([$row]);
     $this->assertContains($field1Name, $filter->getOptions());
     $this->assertContains($field2Name, $filter->getOptions());
 }
Пример #5
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;
 }
Пример #6
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());
 }