public function init() { parent::init(); $api = new GitHubApi(); //$token = new MyToken('833e3c356b24acecf75b52aa815ab48c82ad21ef'); //$api->setToken($token); //$api->getToken(); // contributors' info http://developer.github.com/v3/users/#get-a-single-user $this->user = $api->get('/users/:username', ['username' => $this->user]); $this->user = (array) $api->decode($this->user); // define contributors' status $this->status = GithubUsers::find()->where(['id_user' => $this->user['id']])->one(); $this->status = $this->status['status_user']; }
public function actionLikeUser() { $check_user = GithubUsers::find()->where(['id_user' => $_GET['id']])->one(); if ($_GET['vid'] == 'ins' && empty($check_user)) { // save contributor's like-status in local BD $user = new GithubUsers(); $user->id_user = $_GET['id']; $user->status_user = 1; $user->save(); } else { if ($_GET['vid'] == 'del' && !empty($check_user)) { // delete contributor's like-status in local BD $user = GithubUsers::findOne($_GET['id']); $user->delete(); } } }
echo 'homepage: '; echo Html::a($proj['homepage'], Url::to($proj['homepage'])); echo '<br/>'; echo 'Github repo: '; echo Html::a($proj['html_url'], Url::to($proj['html_url'])); echo '<br/>'; echo 'created at: ' . $proj['created_at'] . '<br/>'; echo '</div>'; // contributor's info echo '<div class="col-md-6 contributor-info">'; echo '<div id="head-user">Contributors: </div>'; foreach ($contributor as $key => $value) { echo '<div class="row contributor-info-line">'; echo '<div class="col-md-6 contributor-info-ref" >'; $contributor_info = (array) $value; echo Html::a($contributor_info['login'], Url::to(['git/user', 'id' => $contributor_info['login']])); echo '<br/></div>'; echo '<div class="col-md-6">'; // like-status $status = GithubUsers::find()->where(['id_user' => $contributor_info['id']])->one(); $status = $status['status_user']; $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' => $contributor_info['id'], 'user' . $contributor_info['id'] => '<a href="/ajax/like?sub=user&id=' . $contributor_info["id"] . '&vid=' . $vid . '"> <img id="user-like" src="' . $img . '" alt=""> </a>']); echo '</div>'; echo '</div>'; } echo '</div>'; echo '</div>';