本文整理汇总了PHP中Tags::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::save方法的具体用法?PHP Tags::save怎么用?PHP Tags::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findAndAdd
public static function findAndAdd($title, $classify, $logid)
{
$title = zmf::filterInput($title, 't', 1);
if (!$title) {
return false;
}
$info = Tags::model()->find('title=:title AND classify=:classify', array(':title' => $title, ':classify' => $classify));
if (!$info) {
if (Yii::app()->session['checkHasBadword'] == 'yes') {
$status = Posts::STATUS_STAYCHECK;
} else {
$status = Posts::STATUS_PASSED;
}
unset(Yii::app()->session['checkHasBadword']);
$_data = array('title' => $title, 'name' => zmf::pinyin($title), 'classify' => $classify, 'status' => $status, 'cTime' => time(), 'length' => mb_strlen($title, 'GBK'));
$modelB = new Tags();
$modelB->attributes = $_data;
if ($modelB->save()) {
$tagid = $modelB->id;
}
} else {
$tagid = $info['id'];
}
if ($tagid && $logid) {
$_info = TagRelation::model()->find('tagid=:tagid AND logid=:logid AND classify=:classify', array(':tagid' => $tagid, ':logid' => $logid, ':classify' => $classify));
if (!$_info) {
$_tagre = array('tagid' => $tagid, 'logid' => $logid, 'classify' => $classify, 'cTime' => zmf::now());
$modelC = new TagRelation();
$modelC->attributes = $_tagre;
$modelC->save();
}
}
return $tagid;
}
示例2: addTags
private static function addTags($model)
{
// add tags
if (!empty($_POST['tags'])) {
$taglist = explode(',', $_POST['tags']);
if ($taglist !== false) {
foreach ($taglist as &$tag) {
if ($tag === '') {
continue;
}
if (substr($tag, 0, 1) != '#') {
$tag = '#' . $tag;
}
$tagModel = new Tags();
$tagModel->taggedBy = 'API';
$tagModel->timestamp = time();
$tagModel->type = get_class($model);
$tagModel->itemId = $model->id;
$tagModel->tag = $tag;
$tagModel->itemName = $model->name;
$tagModel->save();
X2Flow::trigger('RecordTagAddTrigger', array('model' => $model, 'tags' => $tag));
}
}
}
}
示例3: addAction
public function addAction()
{
if ($this->_status['response']['status'] && $this->_checkToken()) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 301;
}
$post = ['entry' => true];
if ($this->_status['response']['status'] && !$this->_getPost($post)) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 201;
$this->_status['response']['detail'] = $post['empty'];
}
$templateList = ['title' => null, 'tag' => null, 'category' => null, 'content' => null];
$conditions = ['content'];
if ($this->_status['response']['status'] && !$this->_mergeArray($this->_post['entry'], $templateList, $conditions)) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 202;
$this->_status['response']['detail'] = $conditions;
}
if (!$this->_status['response']['status']) {
return $this->response->setJsonContent($this->_status);
}
$posts = new Posts();
$posts->assign(['author' => $this->_id, 'title' => $this->_post['entry']['title'], 'content' => $this->_post['entry']['content']]);
if (!$posts->save()) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 102;
return $this->response->setJsonContent($this->_status);
}
if (!empty($this->_post['entry']['tag'])) {
if (is_string($this->_post['entry']['tag'])) {
$this->_post['entry']['tag'] = (array) $this->_post['entry']['tag'];
}
foreach ($this->_post['entry']['tag'] as $tag) {
$tags = new Tags();
$tags->assign(['posts_id' => $posts->id, 'tag' => $tag]);
if (!$tags->save()) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 102;
return $this->response->setJsonContent($this->_status);
}
}
}
if (!empty($this->_post['entry']['category'])) {
if (is_string($this->_post['entry']['category'])) {
$this->_post['entry']['category'] = (array) $this->_post['entry']['category'];
}
foreach ($this->_post['entry']['category'] as $category) {
$categories = new Categories();
$categories->assign(['posts_id' => $posts->id, 'category' => $category]);
if (!$categories->save()) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 102;
return $this->response->setJsonContent($this->_status);
}
}
}
return $this->response->setJsonContent($this->_status);
}
示例4: getTagByName
public function getTagByName($name)
{
$tag = Tags::findFirst(['conditions' => 'name = :name:', 'bind' => ['name' => $name]]);
if (null == $tag) {
$tag = new Tags();
$tag->name = $name;
$tag->save();
}
return $tag;
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Tags();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Tags'])) {
$model->attributes = $_POST['Tags'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例6: afterSave
public function afterSave($event)
{
$attribute = $this->attribute;
if ($this->owner->{$attribute}) {
$model = $this->getModel();
if ($model) {
$model->tags = $this->owner->{$attribute};
$model->save();
} else {
$model = new Tags();
$model->attributes = array('model' => $this->owner->tableName(), 'pk' => $this->owner->id, 'tags' => $this->owner->{$attribute});
$model->save();
}
}
}
示例7: createAction
/**
* Creates a new tag
*/
public function createAction()
{
if (!$this->request->isPost()) {
return $this->dispatcher->forward(array("controller" => "tags", "action" => "index"));
}
$tag = new Tags();
$tag->id = $this->request->getPost("id");
$tag->tag = $this->request->getPost("tag");
if (!$tag->save()) {
foreach ($tag->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array("controller" => "tags", "action" => "new"));
}
$this->flash->success("tag was created successfully");
return $this->dispatcher->forward(array("controller" => "tags", "action" => "index"));
}
示例8: newAction
public function newAction()
{
$response = new ApiResponse();
if ($this->request->isPost()) {
$tag = new Tags();
$tag->id = uniqid();
$tag->name = $this->request->getPost('name');
if ($this->request->hasFiles() == true) {
$baseLocation = 'files/';
foreach ($this->request->getUploadedFiles() as $file) {
$photos = new Photos();
$unique_filename = $tag->id;
$photos->size = $file->getSize();
$photos->original_name = $file->getName();
$photos->file_name = $unique_filename;
$photos->extension = $file->getExtension();
$location = $baseLocation . $unique_filename . "." . $file->getExtension();
$photos->public_link = $location;
try {
if (!$photos->save()) {
$response->setResponseError($photos->getMessages());
} else {
//Move the file into the application
$file->moveTo($location);
$tag->icon = $photos->public_link;
}
} catch (PDOException $e) {
$response->setResponseError($e->getMessage());
}
}
}
try {
if ($tag->save() == false) {
$response->setResponseError($tag->getMessages());
} else {
$response->setResponseMessage($tag->id);
}
} catch (PDOException $e) {
$response->setResponseError($e->getMessage());
}
} else {
$response->setResponseError('Wrong HTTP Method');
}
return $response;
}
示例9: actionCreate
public function actionCreate($id = '')
{
$this->checkPower('addTag');
if ($id) {
$model = Tags::model()->findByPk($id);
if (!$model) {
$this->message(0, '该标签不存在');
}
} else {
$model = new Tags();
$model->classify = 'posts';
}
if (isset($_POST['Tags'])) {
$model->attributes = $_POST['Tags'];
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
}
示例10: addTags
/**
* Adds tags to a post
*/
public function addTags($tags)
{
foreach ($tags as $t) {
$t = trim($t);
$tag = Tags::findFirst(array("tag = '{$t}'"));
if (!$tag) {
$tag = new Tags();
$tag->tag = $t;
$tag->save();
}
$postTag = PostTags::findFirst(array("conditions" => "posts_id = ?1 AND tags_id = ?2", "bind" => array(1 => $this->id, 2 => $tag->id)));
if (!$postTag) {
$postTag = new PostTags();
$postTag->posts_id = $this->id;
$postTag->tags_id = $tag->id;
$postTag->save();
}
unset($tag);
unset($postTag);
}
}
示例11: checkAndWriteTag
/**
* 检查传入的标签是否已存在,不存在则创建,并检查是否已存在对应关系,不存在则创建
* @param type $id
* @param type $crumb
*/
public function checkAndWriteTag($id, $crumb, $tagid = 0)
{
if (!$tagid) {
$_crumb = strip_tags(trim($crumb));
$_taginfo = Tags::model()->find('title=:title', array(':title' => $_crumb));
if (!$_taginfo) {
$_tagdata = array('title' => $_crumb, 'name' => zmf::pinyin($_crumb), 'classify' => 'posts', 'cTime' => time(), 'status' => 1);
$model_tag = new Tags();
$model_tag->attributes = $_tagdata;
$_tagid = $model_tag->save(false);
} else {
$_tagid = $_taginfo['id'];
}
} else {
$_tagid = $tagid;
}
$_tagrel = array('logid' => $id, 'tagid' => $_tagid, 'classify' => 'posts');
$reinfo = TagRelation::model()->find('logid=:logid AND tagid=:tagid AND classify="posts"', array(':logid' => $id, ':tagid' => $_tagid));
if (!$reinfo) {
$model_tagrel = new TagRelation();
$model_tagrel->attributes = $_tagrel;
$model_tagrel->save(false);
}
}
示例12: template
template($tpl_file);
exit;
}
if ($do == "search" && !empty($_GET['q'])) {
$conditions[] = "Tag.name like '%" . trim($_GET['q']) . "%'";
}
if ($do == "del" && !empty($id)) {
$tag->del($id);
}
}
if (isset($_POST['del']) && !empty($_POST['id'])) {
$tag->del($_POST['id']);
}
if (isset($_POST['save']) && !empty($_POST['data']['tag'])) {
if (isset($_POST['id'])) {
$id = intval($_POST['id']);
}
if ($id) {
$tag->save($_POST['data']['tag'], "update", $id);
} else {
$tag->save($_POST['data']['tag']);
}
}
$amount = $tag->findCount(null, $conditions);
$page = new Pages();
$page->setPagenav($amount);
//$joins[] = "LEFT JOIN {$tb_prefix}members m ON m.id=Tag.member_id";
$result = $tag->findAll("Tag.*", $joins, $conditions, "Tag.id DESC ", $page->firstcount, $page->displaypg);
setvar("Items", $result);
setvar("ByPages", $page->getPagenav());
template($tpl_file);
示例13: actionSave_article
public function actionSave_article()
{
$idArticle = null;
// Проверки на доступ к странице
if (Yii::app()->user->isGuest) {
$this->redirect($this->createAbsoluteUrl('default/index'));
}
if (isset($_POST['cancel'])) {
$this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
}
if (isset($_POST['delete'])) {
$this->actionDelete_article();
$this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
}
// Автокомплитер тегов
if (isset($_GET['q'])) {
$lastTag = end(explode(",", $_GET['q']));
$criteria = new CDbCriteria();
$criteria->condition = 'textTag LIKE :tag';
$criteria->params = array(':tag' => '%' . trim(htmlspecialchars($lastTag)) . '%');
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$criteria->limit = $_GET['limit'];
}
$tags = Tags::model()->findAll($criteria);
if ($tags) {
$resStr = '';
foreach ($tags as $tag) {
$resStr .= $tag->textTag . "\n";
}
echo $resStr;
}
exit;
}
// Редактирование или добавление новой
if (isset($_GET['idArticle'])) {
$idArticle = $_GET['idArticle'];
$model = Articles::model()->findByPk($_GET['idArticle']);
$model['tagArray'] = AuxiliaryFunctions::getTagsList($model->tagstoarticles, false);
} else {
$model = new Articles('create');
}
// Нажата кнопка "Редактировать" или "Добавить"
if (isset($_POST['Articles'])) {
$oldFile = null;
$oldFile = $model->photo;
$fileName = null;
// Генерим имя фото
if ('' != $_FILES['Articles']['name']['image']) {
$fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']);
$_POST['Articles']['photo'] = $fileName;
$oldFile = $model->photo;
}
$model->attributes = $_POST['Articles'];
if (empty($model->idUser)) {
$model->idUser = Users::getIdUserForAdmin();
}
if ($model->validate()) {
if ($model->save()) {
$idArticle = $model->idArticle;
if ($fileName) {
AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile);
}
// Теги для статьи
if (isset($_POST['textTag'])) {
$tagsArray = explode(",", $_POST['textTag']);
$idArray = array();
foreach ($tagsArray as $item) {
$tagId = null;
if (!empty($item)) {
$item = trim(htmlspecialchars($item));
} else {
continue;
}
$tagResult = Tags::model()->findByAttributes(array('textTag' => $item));
if (null === $tagResult) {
$newTag = new Tags();
$newTag->textTag = $item;
if ($newTag->save()) {
$tagId = $newTag->idTag;
}
} else {
$tagId = $tagResult->idTag;
}
$idArray[] = $tagId;
}
if ($idArray) {
foreach ($idArray as $item) {
$item = (int) $item;
$idArticle = (int) $idArticle;
if (!TagsToArticles::model()->exists('idArticle = :idArticle AND idTag = :idTag', array(':idArticle' => $idArticle, ':idTag' => $item))) {
$newTags2Art = new TagsToArticles();
$newTags2Art->idArticle = $idArticle;
$newTags2Art->idTag = (int) $item;
$newTags2Art->save();
}
}
}
}
$this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
}
//.........这里部分代码省略.........
示例14: foreach
* This is done by:
* 1) Getting/creating the tag
* 2) Creating an imageTag
* 3) Saving the imageTag
*/
foreach ($data as $tagRow) {
$name = $filter->sanitize($tagRow['name'], 'string');
//Get tag if it exists already
$tag = Tags::findFirst("name = '" . $name . "' AND category_id = '" . $tagRow['category_id'] . "'");
if (!$tag) {
$tag = new Tags();
}
$tag->name = $name;
$tag->category_id = $tagRow['category_id'];
//If the tag could not be saved, dump the error messages
if (!$tag->save()) {
echo 'could not save tag.';
var_dump($tagRow);
var_dump($tag->getMessages());
$app->response->setStatusCode('500');
$app->response->send();
}
$tag->refresh();
//Create an imageTag for each tag
$imagesTags = new ImagesTags();
$imagesTags->tag_id = $tag->id;
$imagesTags->image_id = $image->id;
$imagesTags->x = $tagRow['x'];
$imagesTags->y = $tagRow['y'];
$imagesTags->user_id = $user->getFbId();
//If the imageTag could not be saved, dump the error message
示例15: save_product
/**
* Save a product in the database (Create if need be)
*
* @param string $passkey
* @param int $intRowid
* @param string $strCode
* @param string $strName
* @param string $blbImage
* @param string $strClassName
* @param int $blnCurrent
* @param string $strDescription
* @param string $strDescriptionShort
* @param string $strFamily
* @param int $blnGiftCard
* @param int $blnInventoried
* @param double $fltInventory
* @param double $fltInventoryTotal
* @param int $blnMasterModel
* @param int $intMasterId
* @param string $strProductColor
* @param string $strProductSize
* @param double $fltProductHeight
* @param double $fltProductLength
* @param double $fltProductWidth
* @param double $fltProductWeight
* @param int $intTaxStatusId
* @param double $fltSell
* @param double $fltSellTaxInclusive
* @param double $fltSellWeb
* @param string $strUpc
* @param int $blnOnWeb
* @param string $strWebKeyword1
* @param string $strWebKeyword2
* @param string $strWebKeyword3
* @param int $blnFeatured
* @param string $strCategoryPath
* @return string
*/
public function save_product($passkey, $intRowid, $strCode, $strName, $blbImage, $strClassName, $blnCurrent, $strDescription, $strDescriptionShort, $strFamily, $blnGiftCard, $blnInventoried, $fltInventory, $fltInventoryTotal, $blnMasterModel, $intMasterId, $strProductColor, $strProductSize, $fltProductHeight, $fltProductLength, $fltProductWidth, $fltProductWeight, $intTaxStatusId, $fltSell, $fltSellTaxInclusive, $fltSellWeb, $strUpc, $blnOnWeb, $strWebKeyword1, $strWebKeyword2, $strWebKeyword3, $blnFeatured, $strCategoryPath)
{
if (!$this->check_passkey($passkey)) {
return self::FAIL_AUTH;
}
// We must preservice the Rowid of Products within the Web Store
// database and must therefore see if it already exists
$objProduct = Product::model()->findByPk($intRowid);
if (!$objProduct) {
$objProduct = new Product();
$objProduct->id = $intRowid;
}
$strName = trim($strName);
$strName = trim($strName, '-');
$strName = substr($strName, 0, 255);
$strCode = trim($strCode);
$strCode = str_replace('"', '', $strCode);
$strCode = str_replace("'", '', $strCode);
if (empty($strName)) {
$strName = 'missing-name';
}
if (empty($strDescription)) {
$strDescription = '';
}
$objProduct->code = $strCode;
$objProduct->title = $strName;
//$objProduct->class_name = $strClassName;
$objProduct->current = $blnCurrent;
$objProduct->description_long = $strDescription;
$objProduct->description_short = $strDescriptionShort;
//$objProduct->family = $strFamily;
$objProduct->gift_card = $blnGiftCard;
$objProduct->inventoried = $blnInventoried;
$objProduct->inventory = $fltInventory;
$objProduct->inventory_total = $fltInventoryTotal;
$objProduct->master_model = $blnMasterModel;
if ($intMasterId > 0) {
$objProduct->parent = $intMasterId;
} else {
$objProduct->parent = null;
}
$objProduct->product_color = $strProductColor;
$objProduct->product_size = $strProductSize;
$objProduct->product_height = $fltProductHeight;
$objProduct->product_length = $fltProductLength;
$objProduct->product_width = $fltProductWidth;
$objProduct->product_weight = $fltProductWeight;
$objProduct->tax_status_id = $intTaxStatusId;
$objProduct->sell = $fltSell;
$objProduct->sell_tax_inclusive = $fltSellTaxInclusive;
//If we're in TaxIn Mode, then SellWeb has tax and we reverse it.
if (_xls_get_conf('TAX_INCLUSIVE_PRICING', 0) == 1) {
if ($fltSellWeb != 0) {
//Tax in with a sell on web price
$objProduct->sell_web_tax_inclusive = $fltSellWeb;
//LS sends tax in web already
$objProduct->sell_web = Tax::StripTaxesFromPrice($fltSellWeb, $intTaxStatusId);
} else {
//We use our regular prices and copy them price
$objProduct->sell_web_tax_inclusive = $fltSellTaxInclusive;
$objProduct->sell_web = $fltSell;
}
//.........这里部分代码省略.........