本文整理汇总了PHP中Bookmark::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Bookmark::setAttributes方法的具体用法?PHP Bookmark::setAttributes怎么用?PHP Bookmark::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bookmark
的用法示例。
在下文中一共展示了Bookmark::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
}
示例2: 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);
}