Tripal Plant PopGen Submit
|
Go to the source code of this file.
Functions | |
tpps_compare_files ($fid_1, $fid_2, $file_1_id_name, $file_2_id_name, $file_1_no_header=FALSE, $file_2_no_header=FALSE) | |
tpps_convert_colname ($column) | |
tpps_file_generator ($fid, array $options=array()) | |
tpps_file_headers ($fid, $no_header=FALSE) | |
tpps_file_iterator ($fid, $function, array &$options=array()) | |
tpps_file_len ($fid) | |
tpps_file_len_helper ($row, array &$options=array()) | |
tpps_file_validate_columns (array &$form_state, array $required_groups, array $file_element) | |
tpps_file_width ($fid) | |
tpps_flat_generator ($location, array $options=array()) | |
tpps_flat_width ($location, $delim=',') | |
tpps_get_archive_files ($archive) | |
tpps_get_location ($location) | |
tpps_get_path_extension ($path) | |
tpps_increment_hex ($hex) | |
tpps_parse_file ($fid, $max_rows=0, $no_header=FALSE, $columns=NULL) | |
tpps_parse_file_column ($fid, $column, $no_header=FALSE) | |
tpps_parse_file_column_helper ($row, array &$options) | |
tpps_parse_file_helper ($row, array &$options) | |
tpps_rename_file ($fid, $new_name, array $options=array()) | |
tpps_rmdir ($dir) | |
tpps_save_file_columns (array &$form, array &$form_state) | |
tpps_xlsx_generator ($location, array $options=array()) | |
tpps_xlsx_get_cell_value (&$reader, $cell_type, array &$strings=array()) | |
tpps_xlsx_get_dimension ($location) | |
tpps_xlsx_get_row (&$reader, array &$strings=array(), $plain=TRUE, $columns=NULL) | |
tpps_xlsx_get_rows (array &$readers, array &$strings=array(), $plain=TRUE, $columns=NULL) | |
tpps_xlsx_get_strings ($strings_location) | |
tpps_xlsx_translate_date ($date) | |
tpps_xlsx_width ($location) | |
Defines useful functions for file management.
Definition in file file_utils.inc.
tpps_compare_files | ( | $fid_1, | |
$fid_2, | |||
$file_1_id_name, | |||
$file_2_id_name, | |||
$file_1_no_header = FALSE , |
|||
$file_2_no_header = FALSE |
|||
) |
Compares two file columns.
Returns the array of items that are found in file 1, column file_1_id_name, and are not found in file 2, column file_2_id_name.
int | $fid_1 | File 1 identifier. |
int | $fid_2 | File 2 identifier. |
mixed | $file_1_id_name | Name of column to check in file 1. String or integer. |
mixed | $file_2_id_name | Name of column to check in file 2. String or integer. |
Definition at line 379 of file file_utils.inc.
tpps_convert_colname | ( | $column | ) |
This function will convert a hexadecimal column id to an integer.
Here are a few examples of column keys and their converted integers: echo tpps_convert_colname('A'); // 0 echo tpps_convert_colname('B'); // 1 echo tpps_convert_colname('AA'); // 26 echo tpps_convert_colname('AB'); // 27 echo tpps_convert_colname('BA'); // 52
string | $column | The capital alphabetical key for the column. |
Definition at line 251 of file file_utils.inc.
tpps_file_generator | ( | $fid, | |
array | $options = array() |
||
) |
This function selects the appropriate generator for a file.
The generator is selected based on the file extension. If the extension is not recognized, throws an exception.
int | $fid | The Drupal managed file id for the file. |
array | $options | Additional options to be passed to the generator. |
Definition at line 1074 of file file_utils.inc.
tpps_file_headers | ( | $fid, | |
$no_header = FALSE |
|||
) |
Returns the headers of a TPPS file.
int | $fid | The Drupal managed file id of the file. |
bool | $no_header | Whether or not the no_header option has been set for the file. |
Definition at line 972 of file file_utils.inc.
tpps_file_iterator | ( | $fid, | |
$function, | |||
array & | $options = array() |
||
) |
Iterates over a file and applies a function to each generator result.
This function should be used in place of tpps_parse_file() wherever possible, as it uses much less memory and is much faster.
int | $fid | The Drupal managed file id of the file. |
string | $function | The funciton to be applied to each item returned by the generator. |
array | $options | Options that will be passed to both $function and the generator. |
Definition at line 1011 of file file_utils.inc.
tpps_file_len | ( | $fid | ) |
Returns the number of lines or rows in a file.
int | $fid | The Drupal managed file identifier of the file. |
Definition at line 65 of file file_utils.inc.
tpps_file_len_helper | ( | $row, | |
array & | $options = array() |
||
) |
This is the helper function for tpps_file_len().
This function is passed to the tpps_file_iterator during tpps_file_len, and increments the count attribute of the options array. It also checks whether a skip_prefix was provided, and skips lines if necessary.
mixed | $row | The item yielded by the TPPS file generator. |
array | $options | Additional options set when calling tpps_file_iterator(). |
Definition at line 92 of file file_utils.inc.
tpps_file_validate_columns | ( | array & | $form_state, |
array | $required_groups, | ||
array | $file_element | ||
) |
This function validates that the file contains all of the required groups.
A "required group" is a column type that must be present within the file for the file to be considered valid. For instance, a required group for a plant accession file would be the "Location" group. The required groups array should satisfy the structure: array( '<group name>="">' => array( '<type>' => array(<column option="" index>="">[, <column option="" index>="">...])[, '<type>' => array(<column option="" index>="">[, <column option="" index>="">...])...] )[, '<group name>="">' => array( '<type>' => array(<column option="" index>="">[, <column option="" index>="">...])[, '<type>' => array(<column option="" index>="">[, <column option="" index>="">...])...] )...] ) where <group name>=""> is the name of the required group, <type> is the name of the set of options that could satisfy the required group, and each of the <column option="" index>="">s is a key within the file element['column-options'] field.
array | $form_state | The state of the form that the file is part of. |
array | $required_groups | The required column option groups for the file. |
array | $file_element | The managed_file element of the file within the form. |
Definition at line 442 of file file_utils.inc.
tpps_file_width | ( | $fid | ) |
This function returns the width of a file.
The process of finding the width of the file is done with the use of helper functions, and this function returns the results.
int | $fid | The Drupal managed file identifier of the file to be parsed. |
Definition at line 115 of file file_utils.inc.
tpps_flat_generator | ( | $location, | |
array | $options = array() |
||
) |
This function is s generator for flat files.
If the 'max_rows' option is set, the generator stop after max_rows items are yielded. If the 'columns' option is set, then each item yielded by the generator will contain only the specified columns from the row.
string | $location | The location of the file on the server. |
array | $options | Additional options detailing how to parse the file. |
Definition at line 1234 of file file_utils.inc.
tpps_flat_width | ( | $location, | |
$delim = ',' |
|||
) |
This function gets the length of the longest line of a flat file.
string | $location | The location of the file. |
string | $delim | The delimeter for each line in the file. Defaults to ','. |
Definition at line 179 of file file_utils.inc.
tpps_get_archive_files | ( | $archive | ) |
Extracts an archive from a path or Drupal file object.
mixed | $archive | The archive to be extracted. Can be a path or Drupal file object. |
Definition at line 911 of file file_utils.inc.
tpps_get_location | ( | $location | ) |
Gets true file path from a uri or Drupal file stream.
If the file is compressed, extracts the archive and returns the path of the extracted file.
string | $location | The uri or file stream of the file we want the location of. |
Definition at line 640 of file file_utils.inc.
tpps_get_path_extension | ( | $path | ) |
Gets the file extension from a path.
string | $path | The path of the file we want the extension of. |
Definition at line 661 of file file_utils.inc.
tpps_increment_hex | ( | $hex | ) |
This function increments a hexidecimal key.
The function expects a hexidecimal encoding of a capital alphabetical key. For example, you might pass "$hex = unpack('H*', 'A')[1];". This function is intended to be used for parsed file keys. Here are some examples: echo pack('H*', tpps_increment_hex(unpack('H*', 'A')[1])); // B echo pack('H*', tpps_increment_hex(unpack('H*', 'AA')[1])); // AB echo pack('H*', tpps_increment_hex(unpack('H*', 'Z')[1])); // AA echo pack('H*', tpps_increment_hex(unpack('H*', 'AZ')[1])); // BA echo pack('H*', tpps_increment_hex(unpack('H*', 'ZZZ')[1])); // AAAA.
string | $hex | The hexidecimal encoding of a capital alphabetical key. |
Definition at line 216 of file file_utils.inc.
tpps_parse_file | ( | $fid, | |
$max_rows = 0 , |
|||
$no_header = FALSE , |
|||
$columns = NULL |
|||
) |
This function parses a file and returns an array of its content.
The process of actually parsing the file is done with the use of helper functions, and this function returns the results.
int | $fid | The Drupal managed file identifier of the file to be parsed. |
int | $max_rows | The maximum number of rows to read from the file. |
bool | $no_header | Whether or not the file has a "no_header" flag set. |
Definition at line 25 of file file_utils.inc.
tpps_parse_file_column | ( | $fid, | |
$column, | |||
$no_header = FALSE |
|||
) |
Parses a single column from a file.
int | $fid | The Drupal managed file identifier of the file to be parsed. |
string | $column | The alphabetical key of the column to be parsed. |
bool | $no_header | Whether or not the no_header options has been set to true for the file. |
Definition at line 334 of file file_utils.inc.
tpps_parse_file_column_helper | ( | $row, | |
array & | $options | ||
) |
This function processes a single row of a file.
This function populates the content attribute of the options array with the data in a single column. This function is meant to be used with tpps_file_iterator().
mixed | $row | The item yielded by the TPPS file generator. |
array | $options | Additional options set when calling tpps_file_iterator(). |
Definition at line 357 of file file_utils.inc.
tpps_parse_file_helper | ( | $row, | |
array & | $options | ||
) |
This function processes a single row of a file.
This function populates the content attribute of the options array with content returned by the TPPS file generator. It is used by both the tpps_parse_file and the tpps_file_headers functions. This function is meant to be used with tpps_file_iterator().
mixed | $row | The item yielded by the TPPS file generator. |
array | $options | Additional options set when calling tpps_file_iterator(). |
Definition at line 52 of file file_utils.inc.
tpps_rename_file | ( | $fid, | |
$new_name, | |||
array | $options = array() |
||
) |
Renames a Drupal managed file.
If the "preserve" option is set to true, then the new file will be created as a copy of the old one. Otherwise, the old file will be removed.
int | $fid | The Drupal managed file identifier of the file to be renamed. |
string | $new_name | The new name of the file. |
array | $options | Additional options to be used when renaming the file. |
Definition at line 279 of file file_utils.inc.
tpps_rmdir | ( | $dir | ) |
Recursively removes a directory.
We want to clean out the temporary tpps_xlsx directory when we are done with an excel file, so we need to recursively remove all of the links and sub- directories. Use this function with caution.
string | $dir | The directory to be removed. |
Definition at line 884 of file file_utils.inc.
tpps_save_file_columns | ( | array & | $form, |
array & | $form_state | ||
) |
Saves file column selections to the values of the form_state.
This function is called before the form is validated so that the column options can be saved whenever the user makes a selection.
array | $form | The form being validated. |
array | $form_state | The state of the form being validated. |
Definition at line 533 of file file_utils.inc.
tpps_xlsx_generator | ( | $location, | |
array | $options = array() |
||
) |
This function is a generator for xlsx files.
If the 'max_rows' option is set, the generator stop after max_rows items are yielded. If the 'columns' option is set, then each item yielded by the generator will contain only the specified columns from the row.
string | $location | The location of the file on the server. |
array | $options | Additional options detailing how to parse the file. |
Definition at line 1112 of file file_utils.inc.
tpps_xlsx_get_cell_value | ( | & | $reader, |
$cell_type, | |||
array & | $strings = array() |
||
) |
Returns a cell value from an XML file.
This function recieves an XMLReader object, a cell type attribute, and a location for a strings XML file, and returns the value of the current cell. If the cell type is a string, then the function returns the string from the strings file with the matching string id. Otherwise, it returns the inner XML from the 'v' element within the cell. If no 'v' element can be found before the end of the cell, it returns NULL.
object | $reader | The XMLReader object being used to read the XML file. |
string | $cell_type | The 't' attribute of the current cell. |
array | $strings | The cached strings for the current XML file. |
Definition at line 827 of file file_utils.inc.
tpps_xlsx_get_dimension | ( | $location | ) |
Returns the dimension string of an xlsx file.
If the dimension string cannot be found, returns NULL.
string | $location | The location of the file. |
Definition at line 682 of file file_utils.inc.
tpps_xlsx_get_row | ( | & | $reader, |
array & | $strings = array() , |
||
$plain = TRUE , |
|||
$columns = NULL |
|||
) |
Retrieves a single "row" from an XML file.
This function recieves an XMLReader object and a location for a strings XML file, and returns an array of cell values. If the $plain parameter is set to FALSE, then the function will return TRUE when the XMLReader cursor is on the next row element. If no row element can be found, the function returns FALSE.
object | $reader | The XMLReader object being used to read the XML file. |
array | $strings | The cached strings for the current XML file. |
bool | $plain | Whether or not to attempt to return an array of cell values, or just TRUE. |
mixed | $columns | An array of columns to return. If NULL, return all columns. |
Definition at line 755 of file file_utils.inc.
tpps_xlsx_get_rows | ( | array & | $readers, |
array & | $strings = array() , |
||
$plain = TRUE , |
|||
$columns = NULL |
|||
) |
Retrieves rows from array of readers.
This function recieves an array of XMLReader objects and an array of cached strings, and returns an array of rows produced by tpps_xlsx_get_row() from each reader.
array | $readers | The array of XMLReader objects. |
array | $strings | The cached strings for the current XML file. |
bool | $plain | Whether or not to attempt to return an array of cell values, or just TRUE. |
mixed | $columns | An array of columns to return. If NULL, return all columns. |
Definition at line 714 of file file_utils.inc.
tpps_xlsx_get_strings | ( | $strings_location | ) |
Retrieves strings from an excel strings XML file.
string | $strings_location | The location of the strings XML file. |
Definition at line 853 of file file_utils.inc.
tpps_xlsx_translate_date | ( | $date | ) |
Translates the date from an .xlsx file.
This function may seem strange at first, but skips $date = 60 on purpose. Day 60 in Excel's encoding represents 2/29/1900, which is not a real date.
mixed | $date | The date to be translated. |
Definition at line 791 of file file_utils.inc.
tpps_xlsx_width | ( | $location | ) |
This function gets the length of the longest line of an xlsx file.
string | $location | The location of the file. |
Definition at line 145 of file file_utils.inc.