public function actionLikeRepo() { $check_repo = GithubRepos::find()->where(['id_repos' => $_GET['id']])->one(); if ($_GET['vid'] == 'ins' && empty($check_repo)) { // save repo's like-status in local BD $user = new GithubRepos(); $user->id_repos = $_GET['id']; $user->status_repos = 1; $user->save(); } else { if ($_GET['vid'] == 'del' && !empty($check_repo)) { // delete repo's like-status in local BD $user = GithubRepos::findOne($_GET['id']); $user->delete(); } } }
// homepage echo '<div class="col-md-4">'; echo Html::a($item_proj['homepage'], Url::to($item_proj['homepage'])); echo '</div>'; // owner echo '<div class="col-md-4">'; echo Html::a($item_owner['login'], Url::to(['git/user', 'id' => $item_owner['login']])); echo '</div>'; echo '</div>'; echo '<div class="row">'; // description echo '<div class="col-md-12">' . $item_proj['description'] . '</div>'; echo '</div>'; echo '<div class="row">'; // watchers echo '<div class="col-md-4">watchers: ' . $item_proj['watchers'] . '</div>'; // forks echo '<div class="col-md-4">forks: ' . $item_proj['forks'] . '</div>'; // empty echo '<div class="col-md-3"></div>'; // like-status $status = GithubRepos::find()->where(['id_repos' => $item_proj['id']])->one(); $status = $status['status_repos']; $vid = $status == 1 ? 'del' : 'ins'; $img = $status == 1 ? '/img/like.png' : '/img/unlike.png'; echo \Yii::$app->view->renderFile('@app/views/ajax/like.php', ['id' => $item_proj['id'], 'user' . $item_proj['id'] => '<a href="/ajax/like?sub=repo&id=' . $item_proj["id"] . '&vid=' . $vid . '"> <img id="repo-like" src="' . $img . '" alt=""> </a>']); echo '</div>'; echo "<p></div>"; }