setup_pos(); parent::__construct( $fields ); } /** * A determinate key for hash lookups. * * @since 2.3.0 * * @return string The key */ public function key() { return $this->term . '_' . $this->part_of_speech; } /** * Sets up the part of speech captions. */ private function setup_pos() { if ( ! empty( $this->parts_of_speech ) ) { return; } $this->parts_of_speech = array( 'noun' => _x( 'noun', 'part-of-speech', 'glotpress' ), 'verb' => _x( 'verb', 'part-of-speech', 'glotpress' ), 'adjective' => _x( 'adjective', 'part-of-speech', 'glotpress' ), 'adverb' => _x( 'adverb', 'part-of-speech', 'glotpress' ), 'interjection' => _x( 'interjection', 'part-of-speech', 'glotpress' ), 'conjunction' => _x( 'conjunction', 'part-of-speech', 'glotpress' ), 'preposition' => _x( 'preposition', 'part-of-speech', 'glotpress' ), 'pronoun' => _x( 'pronoun', 'part-of-speech', 'glotpress' ), 'expression' => _x( 'expression', 'part-of-speech', 'glotpress' ), 'abbreviation' => _x( 'abbreviation', 'part-of-speech', 'glotpress' ), ); } /** * Sets restriction rules for fields. * * @since 1.0.0 * * @param GP_Validation_Rules $rules The validation rules instance. */ public function restrict_fields( $rules ) { $rules->term_should_not_be( 'empty' ); $rules->term_should_be( 'consisting_only_of_ASCII_characters' ); $rules->term_should_be( 'starting_and_ending_with_a_word_character' ); $rules->part_of_speech_should_not_be( 'empty' ); $rules->part_of_speech_should_be( 'one_of', array_keys( $this->parts_of_speech ) ); $rules->glossary_id_should_be( 'positive_int' ); $rules->last_edited_by_should_be( 'positive_int' ); } public function by_glossary_id( $glossary_id ) { return $this->many( "SELECT * FROM $this->table WHERE glossary_id= %d ORDER by term ASC", $glossary_id ); } /** * Retrieves the last modified date of a entry in a glossary. * * @since 1.0.0 * * @param GP_Glossary $glossary The glossary to retrieve the last modified date. * @return string The last modified date on success, empty string on failure. */ public function last_modified( $glossary ) { return (string) $this->value( "SELECT date_modified FROM {$this->table} WHERE glossary_id = %d ORDER BY date_modified DESC LIMIT 1", $glossary->id, 'current' ); } } GP::$glossary_entry = new GP_Glossary_Entry();