[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/things/ -> glossary-entry.php (source)

   1  <?php
   2  /**
   3   * Things: GP_Glossary_Entry class
   4   *
   5   * @package GlotPress
   6   * @subpackage Things
   7   * @since 1.0.0
   8   */
   9  
  10  /**
  11   * Core class used to implement the glossary entries.
  12   *
  13   * @since 1.0.0
  14   */
  15  class GP_Glossary_Entry extends GP_Thing {
  16  
  17      var $table_basename           = 'gp_glossary_entries';
  18      var $field_names              = array( 'id', 'glossary_id', 'term', 'part_of_speech', 'comment', 'translation', 'date_modified', 'last_edited_by' );
  19      var $int_fields               = array( 'id', 'glossary_id', 'last_edited_by' );
  20      var $non_updatable_attributes = array( 'id' );
  21  
  22      public $parts_of_speech = array();
  23  
  24      public $id;
  25      public $glossary_id;
  26      public $term;
  27      public $part_of_speech;
  28      public $comment;
  29      public $translation;
  30      public $date_modified;
  31      public $last_edited_by;
  32  
  33  
  34  	public function __construct( $fields = array() ) {
  35          $this->setup_pos();
  36  
  37          parent::__construct( $fields );
  38      }
  39  
  40      /**
  41       * A determinate key for hash lookups.
  42       *
  43       * @since 2.3.0
  44       *
  45       * @return string The key
  46       */
  47  	public function key() {
  48          return $this->term . '_' . $this->part_of_speech;
  49      }
  50  
  51      /**
  52       * Sets up the part of speech captions.
  53       */
  54  	private function setup_pos() {
  55          if ( ! empty( $this->parts_of_speech ) ) {
  56              return;
  57          }
  58  
  59          $this->parts_of_speech = array(
  60              'noun'         => _x( 'noun', 'part-of-speech', 'glotpress' ),
  61              'verb'         => _x( 'verb', 'part-of-speech', 'glotpress' ),
  62              'adjective'    => _x( 'adjective', 'part-of-speech', 'glotpress' ),
  63              'adverb'       => _x( 'adverb', 'part-of-speech', 'glotpress' ),
  64              'interjection' => _x( 'interjection', 'part-of-speech', 'glotpress' ),
  65              'conjunction'  => _x( 'conjunction', 'part-of-speech', 'glotpress' ),
  66              'preposition'  => _x( 'preposition', 'part-of-speech', 'glotpress' ),
  67              'pronoun'      => _x( 'pronoun', 'part-of-speech', 'glotpress' ),
  68              'expression'   => _x( 'expression', 'part-of-speech', 'glotpress' ),
  69              'abbreviation' => _x( 'abbreviation', 'part-of-speech', 'glotpress' ),
  70          );
  71      }
  72  
  73      /**
  74       * Sets restriction rules for fields.
  75       *
  76       * @since 1.0.0
  77       *
  78       * @param GP_Validation_Rules $rules The validation rules instance.
  79       */
  80  	public function restrict_fields( $rules ) {
  81          $rules->term_should_not_be( 'empty' );
  82          $rules->term_should_be( 'consisting_only_of_ASCII_characters' );
  83          $rules->term_should_be( 'starting_and_ending_with_a_word_character' );
  84          $rules->part_of_speech_should_not_be( 'empty' );
  85          $rules->part_of_speech_should_be( 'one_of', array_keys( $this->parts_of_speech ) );
  86          $rules->glossary_id_should_be( 'positive_int' );
  87          $rules->last_edited_by_should_be( 'positive_int' );
  88      }
  89  
  90  	public function by_glossary_id( $glossary_id ) {
  91          return $this->many( "SELECT * FROM $this->table WHERE glossary_id= %d ORDER by term ASC", $glossary_id );
  92      }
  93  
  94      /**
  95       * Retrieves the last modified date of a entry in a glossary.
  96       *
  97       * @since 1.0.0
  98       *
  99       * @param GP_Glossary $glossary The glossary to retrieve the last modified date.
 100       * @return string The last modified date on success, empty string on failure.
 101       */
 102  	public function last_modified( $glossary ) {
 103          return (string) $this->value( "SELECT date_modified FROM {$this->table} WHERE glossary_id = %d ORDER BY date_modified DESC LIMIT 1", $glossary->id, 'current' );
 104      }
 105  }
 106  
 107  GP::$glossary_entry = new GP_Glossary_Entry();


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1