[ 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          parent::__construct( $fields );
  36          $this->setup_pos();
  37      }
  38  
  39      /**
  40       * A determinate key for hash lookups.
  41       *
  42       * @since 2.3.0
  43       *
  44       * @return string The key
  45       */
  46  	public function key() {
  47          return $this->term . '_' . $this->part_of_speech;
  48      }
  49  
  50      /**
  51       * Sets up the part of speech captions.
  52       */
  53  	private function setup_pos() {
  54          if ( ! empty( $this->parts_of_speech ) ) {
  55              return;
  56          }
  57  
  58          $this->parts_of_speech = array(
  59              'noun'         => _x( 'noun', 'part-of-speech', 'glotpress' ),
  60              'verb'         => _x( 'verb','part-of-speech', 'glotpress' ),
  61              'adjective'    => _x( 'adjective', 'part-of-speech', 'glotpress' ),
  62              'adverb'       => _x( 'adverb', 'part-of-speech', 'glotpress' ),
  63              'interjection' => _x( 'interjection', 'part-of-speech', 'glotpress' ),
  64              'conjunction'  => _x( 'conjunction', 'part-of-speech', 'glotpress' ),
  65              'preposition'  => _x( 'preposition', 'part-of-speech', 'glotpress' ),
  66              'pronoun'      => _x( 'pronoun', 'part-of-speech', 'glotpress' ),
  67              'expression'   => _x( 'expression', 'part-of-speech', 'glotpress' )
  68          );
  69      }
  70  
  71      /**
  72       * Sets restriction rules for fields.
  73       *
  74       * @since 1.0.0
  75       *
  76       * @param GP_Validation_Rules $rules The validation rules instance.
  77       */
  78  	public function restrict_fields( $rules ) {
  79          $rules->term_should_not_be( 'empty' );
  80          $rules->part_of_speech_should_not_be( 'empty' );
  81          $rules->glossary_id_should_be( 'positive_int' );
  82          $rules->last_edited_by_should_be( 'positive_int' );
  83      }
  84  
  85  	public function by_glossary_id( $glossary_id ) {
  86          return $this->many( "SELECT * FROM $this->table WHERE glossary_id= %d ORDER by term ASC", $glossary_id );
  87      }
  88  
  89  	public function last_modified( $glossary ) {
  90          global $wpdb;
  91  
  92          return $wpdb->get_var( $wpdb->prepare( "SELECT date_modified FROM {$this->table} WHERE glossary_id = %d ORDER BY date_modified DESC LIMIT 1", $glossary->id, 'current' ) );
  93      }
  94  }
  95  
  96  GP::$glossary_entry = new GP_Glossary_Entry();


Generated: Mon Nov 18 01:01:56 2019 Cross-referenced by PHPXref 0.7.1