コード例 #1
0
ファイル: Image.php プロジェクト: DAICAR/ZfcDatagrid
 public function getFormattedValue(AbstractColumn $column)
 {
     $row = $this->getRowData();
     $value = $row[$column->getUniqueId()];
     $prefix = $this->getPrefix();
     if (is_array($value)) {
         $thumb = $value[0];
         if (isset($value[1])) {
             $original = $value[1];
         } else {
             $original = $thumb;
         }
     } else {
         $thumb = $value;
         $original = $value;
     }
     $linkAttributes = [];
     foreach ($this->getLinkAttributes() as $key => $value) {
         $linkAttributes[] = $key . '="' . $value . '"';
     }
     $attributes = [];
     foreach ($this->getAttributes() as $key => $value) {
         $attributes[] = $key . '="' . $value . '"';
     }
     return '<a href="' . $prefix . $original . '" ' . implode(' ', $linkAttributes) . '><img src="' . $prefix . $thumb . '" ' . implode(' ', $attributes) . ' /></a>';
 }
コード例 #2
0
ファイル: FilterTest.php プロジェクト: DAICAR/ZfcDatagrid
 public function setUp()
 {
     $this->column = $this->getMockBuilder('ZfcDatagrid\\Column\\Select')->disableOriginalConstructor()->getMock();
     $this->column->method('getSelectPart1')->willReturn('myCol');
     $this->column->method('getType')->willReturn(new \ZfcDatagrid\Column\Type\PhpString());
     $this->column->setUniqueId('myCol');
     $this->column->setSelect('myCol');
     $this->column2 = $this->getMockBuilder('ZfcDatagrid\\Column\\Select')->disableOriginalConstructor()->getMock();
     $this->column2->method('getSelectPart1')->willReturn('myCol2');
     $this->column2->method('getType')->willReturn(new \ZfcDatagrid\Column\Type\PhpString());
     $this->column2->setUniqueId('myCol2');
     $this->column2->setSelect('myCol2');
     $this->mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $this->mockConnection = $this->getMock('Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $this->mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true));
     $this->mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($this->mockConnection));
     $this->mockPlatform = $this->getMock('Zend\\Db\\Adapter\\Platform\\PlatformInterface');
     $this->mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $this->mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($this->mockStatement));
     $this->adapter = new Adapter($this->mockDriver, $this->mockPlatform);
     $sql = new Sql($this->adapter, 'foo');
     $select = new Select('myTable');
     $select->columns(['myCol', 'myCol2']);
     $this->filterSelect = new FilterSelect($sql, $select);
 }
コード例 #3
0
ファイル: GenerateLink.php プロジェクト: DAICAR/ZfcDatagrid
 /**
  * @param  AbstractColumn $column
  * @return string
  */
 public function getFormattedValue(AbstractColumn $column)
 {
     $row = $this->getRowData();
     $value = $row[$column->getUniqueId()];
     $routeKey = !is_null($this->getRouteKey()) ? $this->getRouteKey() : $column->getUniqueId();
     $params = $this->getRouteParams();
     $params[$routeKey] = $value;
     $url = (string) $this->getViewRenderer()->url($this->getRoute(), $params);
     return sprintf('<a href="%s">%s</a>', $url, $value);
 }
コード例 #4
0
ファイル: FileSize.php プロジェクト: rezix/ZfcDatagrid
 /**
  * The value should be in bytes
  *
  * @see \ZfcDatagrid\Column\Formatter\AbstractFormatter::getFormattedValue()
  */
 public function getFormattedValue(AbstractColumn $column)
 {
     $row = $this->getRowData();
     $value = $row[$column->getUniqueId()];
     if ('' == $value) {
         return $value;
     }
     $index = 0;
     while ($value >= 1024 && $index < count(self::$prefixes)) {
         $value = $value / 1024;
         $index++;
     }
     return sprintf('%1.2f %sB', $value, self::$prefixes[$index]);
 }
コード例 #5
0
 public function testIsDisplayedException()
 {
     /* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
     $action = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\Action\\AbstractAction');
     $this->setExpectedException('InvalidArgumentException');
     $action->addShowOnValue($this->column, '23', 'UNknownFilter');
     $action->isDisplayed([$this->column->getUniqueId() => '32']);
 }
コード例 #6
0
ファイル: PrepareDataTest.php プロジェクト: rezix/ZfcDatagrid
 public function setUp()
 {
     $this->colId = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->colId->setUniqueId('id');
     $this->colId->setIdentity(true);
     $this->col1 = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->col1->setUniqueId('col1');
     $this->col2 = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->col2->setUniqueId('col2');
     $this->col3 = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->col3->setUniqueId('col3');
     $this->col3->setType(new Type\PhpArray());
     $data = [];
     $data[] = ['id' => '1', 'col1' => 'test', 'col2' => 'n', 'col3' => ['tag1', 'tag2']];
     $data[] = ['id' => '2', 'col1' => 'test', 'col3' => ['tag3', 'tag1']];
     $data[] = ['id' => '3', 'col1' => 'test', 'col2' => 'y', 'col3' => ['tag2', 'tag5']];
     $this->data = $data;
 }
コード例 #7
0
 public function testIsApplyAndOperatorNoDisplay()
 {
     /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
     $style = $this->getMockForAbstractClass('Zf2datatable\\Column\\Style\\AbstractStyle');
     $style->setByValueOperator('AND');
     $style->addByValue($this->column, '23', Filter::EQUAL);
     $style->addByValue($this->column, '23', Filter::NOT_EQUAL);
     $this->assertFalse($style->isApply(array($this->column->getUniqueId() => '23')));
 }
コード例 #8
0
ファイル: FilterTest.php プロジェクト: rezix/ZfcDatagrid
 public function setUp()
 {
     $this->column = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->column->setUniqueId('myCol');
     $this->column->setSelect('myCol');
     $this->column2 = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->column2->setUniqueId('myCol2');
     $this->column2->setSelect('myCol2');
     $this->mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $this->mockConnection = $this->getMock('Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $this->mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true));
     $this->mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($this->mockConnection));
     $this->mockPlatform = $this->getMock('Zend\\Db\\Adapter\\Platform\\PlatformInterface');
     $this->mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $this->mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($this->mockStatement));
     $this->adapter = new Adapter($this->mockDriver, $this->mockPlatform);
     $sql = new Sql($this->adapter, 'foo');
     $select = new Select('myTable');
     $select->columns(['myCol', 'myCol2']);
     $this->filterSelect = new FilterSelect($sql, $select);
 }
コード例 #9
0
 public function testIsDisplayedByColumn()
 {
     /* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
     $action = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\Action\\AbstractAction');
     $columnCompare = clone $this->column;
     $columnCompare->setUniqueId('columnCompare');
     $action->addShowOnValue($this->column, $columnCompare, Filter::GREATER_EQUAL);
     $this->assertEquals([['column' => $this->column, 'value' => $columnCompare, 'comparison' => Filter::GREATER_EQUAL]], $action->getShowOnValues());
     $this->assertTrue($action->hasShowOnValues());
     // Test lower value
     $row = [$this->column->getUniqueId() => 5, $columnCompare->getUniqueId() => 15];
     $this->assertFalse($action->isDisplayed($row));
     // Test greater value
     $row = [$this->column->getUniqueId() => 15, $columnCompare->getUniqueId() => 10];
     $this->assertTrue($action->isDisplayed($row));
     // Test row without compared column
     $row = [$this->column->getUniqueId() => 15];
     $this->assertTrue($action->isDisplayed($row));
 }
コード例 #10
0
 public function testStyleByColumn()
 {
     /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
     $style = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\Style\\AbstractStyle');
     $columnCompare = clone $this->column;
     $columnCompare->setUniqueId('columnCompare');
     $style->addByValue($this->column, $columnCompare, Filter::GREATER_EQUAL);
     $this->assertEquals([['column' => $this->column, 'value' => $columnCompare, 'operator' => Filter::GREATER_EQUAL]], $style->getByValues());
     $this->assertTrue($style->hasByValues());
     // Test lower value
     $row = [$this->column->getUniqueId() => 5, $columnCompare->getUniqueId() => 15];
     $this->assertFalse($style->isApply($row));
     // Test greater value
     $row = [$this->column->getUniqueId() => 15, $columnCompare->getUniqueId() => 10];
     $this->assertTrue($style->isApply($row));
     // Test row without compared column
     $row = [$this->column->getUniqueId() => 15];
     $this->assertTrue($style->isApply($row));
 }
コード例 #11
0
ファイル: Email.php プロジェクト: rezix/ZfcDatagrid
 public function getFormattedValue(AbstractColumn $column)
 {
     $row = $this->getRowData();
     return '<a href="mailto:' . $row[$column->getUniqueId()] . '">' . $row[$column->getUniqueId()] . '</a>';
 }
コード例 #12
0
ファイル: Columns.php プロジェクト: rezix/ZfcDatagrid
 /**
  *
  * @param  Column\AbstractColumn $col
  * @throws \Exception
  * @return array
  */
 private function getStyles(Column\AbstractColumn $col)
 {
     $styleFormatter = [];
     /*
      * First all based on value (only one works) @todo
      */
     foreach ($col->getStyles() as $style) {
         $prepend = '';
         $append = '';
         /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
         foreach ($style->getByValues() as $rule) {
             $colString = $rule['column']->getUniqueId();
             $operator = '';
             switch ($rule['operator']) {
                 case Filter::EQUAL:
                     $operator = '==';
                     break;
                 case Filter::NOT_EQUAL:
                     $operator = '!=';
                     break;
                 default:
                     throw new \Exception('Currently not supported filter operation: "' . $rule['operator'] . '"');
                     break;
             }
             $prepend = 'if (rowObject.' . $colString . ' ' . $operator . ' \'' . $rule['value'] . '\') {';
             $append .= '}';
         }
         $styleString = '';
         switch (get_class($style)) {
             case 'ZfcDatagrid\\Column\\Style\\Bold':
                 $styleString = self::STYLE_BOLD;
                 break;
             case 'ZfcDatagrid\\Column\\Style\\Italic':
                 $styleString = self::STYLE_ITALIC;
                 break;
             case 'ZfcDatagrid\\Column\\Style\\Strikethrough':
                 $styleString = self::STYLE_STRIKETHROUGH;
                 break;
             case 'ZfcDatagrid\\Column\\Style\\Color':
                 $styleString = 'cellvalue = \'<span style="color: #' . $style->getRgbHexString() . ';">\' + cellvalue + \'</span>\';';
                 break;
             case 'ZfcDatagrid\\Column\\Style\\BackgroundColor':
                 // do NOTHING! this is done by loadComplete event...
                 // At this stage jqgrid haven't created the columns...
                 break;
             default:
                 throw new \Exception('Not defined style: "' . get_class($style) . '"');
                 break;
         }
         $styleFormatter[] = $prepend . $styleString . $append;
     }
     return $styleFormatter;
 }
コード例 #13
0
ファイル: HtmlTag.php プロジェクト: DAICAR/ZfcDatagrid
 /**
  * This is needed public for rowClickAction...
  *
  * @param  AbstractColumn $col
  * @return string
  */
 protected function getLinkReplaced(AbstractColumn $col)
 {
     $row = $this->getRowData();
     $link = $this->getLink();
     if ($link == '') {
         return $row[$col->getUniqueId()];
     }
     // Replace placeholders
     if (strpos($link, self::ROW_ID_PLACEHOLDER) !== false) {
         $id = '';
         if (isset($row['idConcated'])) {
             $id = $row['idConcated'];
         }
         $link = str_replace(self::ROW_ID_PLACEHOLDER, rawurlencode($id), $link);
     }
     foreach ($this->getLinkColumnPlaceholders() as $col) {
         $link = str_replace(':' . $col->getUniqueId() . ':', rawurlencode($row[$col->getUniqueId()]), $link);
     }
     return $link;
 }
コード例 #14
0
ファイル: FilterTest.php プロジェクト: DAICAR/ZfcDatagrid
 public function setUp()
 {
     $this->column = $this->getMockForAbstractClass('ZfcDatagrid\\Column\\AbstractColumn');
     $this->column->setUniqueId('myCol');
 }
コード例 #15
0
ファイル: AbstractAction.php プロジェクト: DAICAR/ZfcDatagrid
 /**
  * Get the column row value placeholder
  * $action->setLink('/myLink/something/id/'.$action->getRowIdPlaceholder().'/something/'.$action->getColumnRowPlaceholder($myCol));
  *
  * @param  AbstractColumn $col
  * @return string
  */
 public function getColumnValuePlaceholder(AbstractColumn $col)
 {
     $this->linkColumnPlaceholders[] = $col;
     return ':' . $col->getUniqueId() . ':';
 }
コード例 #16
0
ファイル: Filter.php プロジェクト: rezix/ZfcDatagrid
 /**
  * Apply a filter based on a column
  *
  * @param Column\AbstractColumn $column
  * @param unknown               $inputFilterValue
  */
 public function setFromColumn(Column\AbstractColumn $column, $inputFilterValue)
 {
     $this->column = $column;
     $this->setColumnOperator($inputFilterValue, $column->getFilterDefaultOperation());
 }