Exemplo n.º 1
0
 /**
  * Attach headword.
  * @param string|Headword $headword
  * @return \static
  */
 public function headword($headword)
 {
     if ($headword instanceof Headword) {
         return $this->andWhere(['headword_guid' => $headword->guid]);
     }
     if (is_string($headword)) {
         $headword = Headword::find()->where(['word' => $headword])->one();
         if (!$headword) {
             return $this;
         }
         return $this->andWhere(['headword_guid' => $headword->guid]);
     }
 }
Exemplo n.º 2
0
 /**
  * Headwords generator.
  * @param string|\rhoone\extension\Extension|\rhoone\models\Extension|mixed $class
  * `string` if extension class.
  * @param string[] $words
  * @throws InvalidParamException
  */
 public function getHeadwords($class = null, $words = [])
 {
     // Method One:
     if ($class === null || $class === false || is_string($class) && empty($class)) {
         $query = Headword::find();
     } else {
         $extensions = ExtensionManager::getModels($class);
         $guids = [];
         foreach ($extensions as $extension) {
             $guids[] = $extension->guid;
         }
         $query = Headword::find()->guid($guids);
     }
     if (is_array($words) && !empty($words)) {
         $query = $query->word($words);
     }
     foreach ($query->all() as $headword) {
         (yield $headword);
     }
     // Method Two:
     //return Headword::find()->all();
 }
Exemplo n.º 3
0
 /**
  * 
  * @param string $word
  * @param Extension $extension
  * @return boolean
  */
 public static function remove($word, $extension)
 {
     $headword = Headword::find()->where(['word' => $word, 'extension_guid' => $extension->guid])->one();
     if (!$headword) {
         Yii::warning($word . ' does not exist.', __METHOD__);
         return false;
     }
     return $headword->delete() == 1;
 }