当前位置: 首页>>代码示例>>PHP>>正文


PHP Bookmark::model方法代码示例

本文整理汇总了PHP中Bookmark::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Bookmark::model方法的具体用法?PHP Bookmark::model怎么用?PHP Bookmark::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bookmark的用法示例。


在下文中一共展示了Bookmark::model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeSave

 protected function beforeSave()
 {
     $folderModel = Folder::model()->findByPk($this->folder_id);
     $existingBookmarkModel = Bookmark::model()->findSingleByAttributes(array('user_id' => \GO::user()->id, 'folder_id' => $folderModel->id));
     if (!empty($existingBookmarkModel)) {
         throw new \Exception(str_replace('%fn', $folderModel->name, \GO::t('bookmarkAlreadyExists', 'files')));
     }
     return parent::beforeSave();
 }
开发者ID:ajaboa,项目名称:crmpuan,代码行数:9,代码来源:Bookmark.php

示例2: addDel

 /**
  * Add or Delete Bookmark.
  */
 public function addDel($postId)
 {
     $row = Bookmark::model()->find('postId=:postId and userId=:userId', array(':postId' => $postId, ':userId' => Yii::app()->user->id));
     if (empty($row)) {
         $row = new Bookmark();
         $row->postId = $postId;
         $row->userId = Yii::app()->user->id;
         $row->save();
         return true;
     } else {
         $row->delete();
         return false;
     }
 }
开发者ID:Greka163,项目名称:Yii-blog-new,代码行数:17,代码来源:Bookmark.php

示例3: actionSet

 public function actionSet()
 {
     $book_id = (int) $_POST["book_id"];
     $orig_id = (int) $_POST["orig_id"];
     $pk = array("user_id" => Yii::app()->user->id, "book_id" => $book_id);
     if ($orig_id) {
         $pk["orig_id"] = $orig_id;
     }
     $bm = Bookmark::model()->findByAttributes($pk);
     if (!$bm) {
         $bm = new Bookmark();
         $bm->user_id = Yii::app()->user->id;
         $bm->book_id = $book_id;
         if ($orig_id) {
             $bm->orig_id = $orig_id;
         }
     }
     if (isset($_POST["note"])) {
         $post = $_POST;
         unset($post["book_id"]);
         unset($post["orig_id"]);
         $bm->setAttributes($post);
         $bm->watch = (int) $_POST["watch"];
         $new_ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE user_id = :user_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id)) + 1;
         if ($orig_id) {
             // А есть ли закладка на перевод?
             if (!Yii::app()->db->createCommand("SELECT 1 FROM bookmarks WHERE user_id = :user_id AND book_id = :book_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id))) {
                 Yii::app()->db->createCommand("INSERT INTO bookmarks (user_id, book_id, ord) VALUES (:user_id, :book_id, :ord)")->execute(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id, ":ord" => $new_ord));
             }
         } else {
             $bm->ord = $new_ord;
         }
         if (!$bm->save()) {
             throw new CHttpException(500, $bm->getErrorsString());
         }
         echo json_encode(array("book_id" => (int) $bm->book_id, "orig_id" => (int) $bm->orig_id, "note" => $bm->note, "status" => "set"));
     } else {
         $this->renderPartial("set", array("bm" => $bm));
     }
 }
开发者ID:norayr,项目名称:notabenoid,代码行数:40,代码来源:BookmarksController.php

示例4: set

 /**
  * Ставит закладку на перевод/фрагмент
  * Если закладка была, то редактируется $note (если указано)
  * Если не было, то создаётся с min(ord) - 1
  **/
 public static function set($book_id, $orig_id = null, $note = null)
 {
     if (Yii::app()->user->isGuest) {
         return false;
     }
     $pk = array("user_id" => Yii::app()->user->id, "book_id" => $book_id);
     if ($orig_id) {
         $pk["orig_id"] = $orig_id;
     }
     $bm = Bookmark::model()->findByAttributes($pk);
     if (!$bm) {
         $bm = new Bookmark();
         $bm->user_id = Yii::app()->user->id;
         $bm->book_id = $book_id;
         if ($orig_id) {
             $bm->orig_id = $orig_id;
         }
         $bm->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE user_id = :user_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id)) + 1;
     }
     if ($note !== null) {
         $bm->note = $note;
     }
     return $bm->save();
 }
开发者ID:norayr,项目名称:notabenoid,代码行数:29,代码来源:Bookmark.php

示例5: actionBookmark_set

 public function actionBookmark_set()
 {
     if (!is_array($_POST["B"])) {
         throw new CHttpException(500, "Неверный запрос.");
     }
     // Есть ли уже такая закладка?
     $bookmark = Bookmark::model()->findByAttributes(array("user_id" => Yii::app()->user->id, "typ" => substr($_POST["B"]["typ"], 0, 1), "obj_id" => (int) $_POST["B"]["obj_id"]));
     if (!$bookmark) {
         $bookmark = new Bookmark();
         $bookmark->user_id = Yii::app()->user->id;
     }
     $bookmark->setAttributes($_POST["B"]);
     if ($bookmark->typ == "o") {
         $orig = Orig::model()->with("chap.book")->findByPk($bookmark->obj_id);
         if (!$orig) {
             throw new CHttpException(404, "Фрагмент оригинала удалён.");
         }
         $bookmark->url = $orig->url;
     } elseif ($bookmark->typ == "c") {
         $chap = Chapter::model()->with("book")->findByPk($bookmark->obj_id);
         if (!$chap) {
             throw new CHttpException(404, "Глава удалена");
         }
         $bookmark->url = $chap->url;
     } elseif ($bookmark->typ == "b") {
         $book = Book::model()->findByPk($bookmark->obj_id);
         if (!$book) {
             throw new CHttpException(404, "Глава удалена");
         }
         $bookmark->url = $book->url;
     } else {
         throw new CHttpException(500, "Неверный запрос. Если вам интересны грязные подробности, то я не знаю, что такое тип закладки '{$bookmark->typ}'.");
     }
     if ($bookmark->isNewRecord) {
         $bookmark->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE typ = :typ AND user_id = :user_id")->queryScalar(array(":typ" => $bookmark->typ, ":user_id" => Yii::app()->user->id)) + 1;
     }
     if (!$bookmark->save()) {
         throw new CHttpException(500, $bookmark->getErrorsString());
     }
     $json = array("id" => $bookmark->id, "title" => $bookmark->title);
     echo json_encode($json);
 }
开发者ID:norayr,项目名称:notabenoid,代码行数:42,代码来源:MyController.php


注:本文中的Bookmark::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。