/** * @param \yii\db\ActiveRecord $member * @return array */ public static function get($member) { $request =& Yii::$app->request; $offset = (int) $request->getQueryParam('o', 0); $query = Bookmark::find()->where(['memberId' => $member->id]); $count = $query->count(); $bookmarks = $query->orderBy('createdTime DESC')->offset($offset)->limit(20)->all(); return ['bookmarks' => $bookmarks, 'pagination' => Util::getPagination($offset, $count, 20, 'o')]; }
use common\models\SnippetComment; use common\models\Bookmark; use yii\bootstrap\ActiveForm; $this->title = $snippet->name; $geshi = new GeSHi($snippet->code, $language->renderCode); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_tab_width(4); $geshiCode = $geshi->parse_code(); $markdown = new GithubMarkdown(); $markdown->html5 = true; $markdown->enableNewlines = true; $comments = SnippetComment::find()->where(['snippetId' => $snippet->id])->with('member')->orderBy('createdTime ASC')->all(); $hasBookmarked = false; if ($this->context->member) { $hasBookmarked = Bookmark::find()->where(['memberId' => $this->context->member->id, 'snippetId' => $snippet->id])->count(); } if (!$this->context->member && $this->context->params['registrationsOpen']) { ?> <span class="bookmark"> <a href="/login?r=<?php echo $_SERVER['REQUEST_URI']; ?> " title="Login and return here">Login</a> or <a href="/register" title="Register an account">Register</a> to Bookmark this snippet </span> <?php } else { if ($this->context->member) { // We are logged in
/** * /snippets/language-slug/snippet-slug/removebookmark * * @return string */ public function actionRemovebookmark() { if (!$this->parseQueryParams()) { return $this->goHome(); } Bookmark::deleteAll(['memberId' => $this->member->id, 'snippetId' => $this->snippet->id]); $this->notifySuccess('This snippet has been removed from your Bookmarks.'); return $this->redirect('/snippets/' . $this->language->slug . '/' . $this->snippet->slug); }
/** * @return \yii\db\ActiveQuery */ public function getBookmarks() { return $this->hasMany(Bookmark::className(), ['memberId' => 'id']); }