/** * Gets a row of data from a table * * @param JTable $table JTable instance for a row. * * @return array Associative array of all columns and values for a row in a table. * * @since 3.1 */ public function getRowData($table) { $fields = $table->getFields(); $data = array(); foreach ($fields as &$field) { $columnName = $field->Field; $value = $table->{$columnName}; $data[$columnName] = $value; } return $data; }
/** * Test for getFields method. * * @return void * * @since 12.3 */ public function testGetFields() { $this->assertEquals(array('id1' => (object) array('Field' => 'id1', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => 'PRI'), 'id2' => (object) array('Field' => 'id2', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => 'PRI'), 'title' => (object) array('Field' => 'title', 'Type' => 'TEXT', 'Null' => 'NO', 'Default' => '\'\'', 'Key' => ''), 'asset_id' => (object) array('Field' => 'asset_id', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => ''), 'hits' => (object) array('Field' => 'hits', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => ''), 'checked_out' => (object) array('Field' => 'checked_out', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => ''), 'checked_out_time' => (object) array('Field' => 'checked_out_time', 'Type' => 'TEXT', 'Null' => 'NO', 'Default' => '\'0000-00-00 00:00:00\'', 'Key' => ''), 'published' => (object) array('Field' => 'published', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => ''), 'publish_up' => (object) array('Field' => 'publish_up', 'Type' => 'TEXT', 'Null' => 'NO', 'Default' => '\'0000-00-00 00:00:00\'', 'Key' => ''), 'publish_down' => (object) array('Field' => 'publish_down', 'Type' => 'TEXT', 'Null' => 'NO', 'Default' => '\'0000-00-00 00:00:00\'', 'Key' => ''), 'ordering' => (object) array('Field' => 'ordering', 'Type' => 'INTEGER', 'Null' => 'NO', 'Default' => '\'0\'', 'Key' => ''), 'params' => (object) array('Field' => 'params', 'Type' => 'TEXT', 'Null' => 'NO', 'Default' => '\'\'', 'Key' => '')), $this->object->getFields()); }
/** * Method to get an object containing all of the table columns and values. * * @param JTable $table JTable object. * * @return object Contains all of the columns and values. * * @since 3.2 */ public function getDataObject(JTable $table) { $fields = $table->getFields(); $dataObject = new stdClass(); foreach ($fields as $field) { $fieldName = $field->Field; $dataObject->{$fieldName} = $table->get($fieldName); } return $dataObject; }