public function countlikesdisall1($field_iddis)
 {
     $criteriadis = new CDbCriteria();
     $criteriadis->select = 'count(id) as count';
     // only select the 'title' column
     $criteriadis->condition = 'field_id=:field_id and status=:status';
     $criteriadis->params = array(':field_id' => $field_iddis, ':status' => 2);
     $modeldis = Likedislikedis::model()->find($criteriadis);
     return $modeldis->count;
 }
 public function actionLikedislikedis()
 {
     $field_iddis = Yii::app()->request->getParam('field_id');
     //$user_id = yii::app()->user->GetId();
     $user_ipdis = Yii::app()->request->userHostAddress;
     $criteriadis = new CDbCriteria();
     $criteriadis->select = '*';
     // only select the 'title' column
     //$criteria->condition='field_id=:field_id and user_ip=:user_ip';
     //$criteria->condition='field_id=:field_id and user_id=:user_id';
     //$criteria->params=array(':field_id'=>$field_id,':user_id'=>$user_id);
     $criteriadis->condition = 'field_id=:field_id and user_ip=:user_ip';
     $criteriadis->params = array(':field_id' => $field_iddis, ':user_ip' => $user_ipdis);
     $modeldis = Likedislikedis::model()->find($criteriadis);
     //$model1 = Likedislike::model()->find($criteria);
     if (count($modeldis) == 0) {
         $modeldis = new Likedislikedis();
         $modeldis->field_id = $field_iddis;
         $modeldis->user_ip = $user_ipdis;
         //$model->user_id = $user_id;
         $modeldis->status = 2;
         $modeldis->add_timestamp = time();
         $displaynowdis = '<img id="dis-like" src="' . Yii::app()->request->baseUrl . '/css/img/dislike-ico-h.png">';
     } else {
         if ($modeldis->status == 0 || $modeldis->status == 1) {
             $modeldis->status = 2;
             $modeldis->edit_timestamp = time();
             $displaynowdis = '<img id="dis-like" src="' . Yii::app()->request->baseUrl . '/css/img/dislike-ico-h.png">';
         } else {
             $modeldis->status = 0;
             $modeldis->edit_timestamp = time();
             $displaynowdis = '<img id="like" src="' . Yii::app()->request->baseUrl . '/css/img/dislike-ico.png">';
         }
     }
     if ($modeldis->save()) {
         $datadis['status'] = true;
         $datadis['displaytext'] = $displaynowdis;
     } else {
         $datadis['status'] = false;
     }
     $datadis['count'] = Yii::app()->getModule('likedislikedis')->countlikesdis($field_iddis);
     echo json_encode($datadis);
 }
 public function actionVideoDelete($id)
 {
     if (!is_numeric($id)) {
         exit;
     }
     $ModelVideo = CmsvideoVideo::model()->findByPk($id);
     $ModelSlider = Slider::model()->findByAttributes(array('slider_idvideo' => $id));
     $ModelTags = new Tags();
     if (!empty($ModelVideo->video_image) || !empty($ModelVideo->video_thumb)) {
         $ModelVideo->DeleteVideoImage($id);
     }
     $TagDelete = $ModelTags::model()->findAll('tag_idvideo LIKE :Id', array(':Id' => '%"' . $id . '"%'));
     foreach ($TagDelete as $TagValue) {
         $TagName = $ModelTags->ReplaceTagName($TagValue->tag_slug);
         if (Tags::model()->exists('tag_slug = :TagName', array(":TagName" => $TagName))) {
             $SelectTag = $ModelTags::model()->findByAttributes(array('tag_slug' => $TagName));
             $TagArr1 = unserialize($SelectTag->tag_idvideo);
             if (count(array_keys($TagArr1)) <= 1) {
                 $ModelTags::model()->deleteByPk($SelectTag->tag_id);
             } else {
                 $TagArr2[] = $id;
                 $TagDelDiff = array_diff($TagArr1, $TagArr2);
                 $NewTag = serialize($TagDelDiff);
                 $ModelTags::model()->updateByPk($SelectTag->tag_id, array('tag_idvideo' => $NewTag));
             }
         }
     }
     CmsvideoVideo::model()->deleteByPk($id);
     Likedislikedis::model()->deleteAll('field_id = :IdVideo', array(':IdVideo' => $id));
     if (count($ModelSlider) > 0) {
         $ModelSlider->DeleteSliderImage($ModelSlider->slider_id);
         $ModelSlider::model()->deleteByPk($ModelSlider->slider_id);
     }
     // $this->redirect(array('admin/videos'));
     $this->redirect(Yii::app()->request->urlReferrer);
 }