Exemple #1
0
 /**
  * Lists all Tags models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new SearchTags();
     $searchModel->parent_id = \Yii::$app->params['parentTagId'];
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Exemple #2
0
 /**
  * Adding new search tag to the database or incrementing the search tags count by 1.
  * 
  * @param string $searchTag
  * @return integer
  */
 public static function addSearchTagOrIncrementCount($searchTag)
 {
     $count = 0;
     if (!empty($searchTag)) {
         $tagName = strtolower(strip_tags(trim($searchTag)));
         $searchTagRecord = self::isSearchTagExists($tagName);
         if (empty($searchTagRecord->id)) {
             $searchTagObj = new SearchTags();
             $searchTagObj->tag_name = $tagName;
             $searchTagObj->searched_count = 1;
             $searchTagObj->save();
             return $searchTagObj->searched_count;
         }
         // if the search tag already exists then increments its searched count.
         $count = $searchTagRecord->searched_count + 1;
         $searchTagRecord->searched_count = $count;
         $searchTagRecord->save();
     }
     return $count;
 }