本文整理汇总了PHP中SQLQuery::Count方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLQuery::Count方法的具体用法?PHP SQLQuery::Count怎么用?PHP SQLQuery::Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLQuery
的用法示例。
在下文中一共展示了SQLQuery::Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveInto
function saveInto(DataObjectInterface $record)
{
$relation = $this->getRelation();
if ($relation) {
$submittedTags = explode($this->getDelimiter(), $this->value);
$tagClass = $this->getTagClass();
$tagLabelField = $this->getTagLabelField();
$tagObjects = DataList::create($tagClass)->filter($tagLabelField, $submittedTags);
if ($tagObjects->Count() < count($submittedTags)) {
// filter out the tags that exist already
$tagsAsKeys = array_flip($submittedTags);
foreach ($tagObjects as $tag) {
$label = $tag->{$tagLabelField};
unset($tagsAsKeys[$label]);
}
foreach ($tagsAsKeys as $label => $value) {
$tagObject = new $tagClass();
$tagObject->{$tagLabelField} = $label;
$tagObject->write();
$tagObjects->add($tagObject);
}
}
$relationList = $this->form->record->{$this->name}();
$oldTags = $relationList->map('ID', $tagLabelField)->toArray();
$relationList->removeAll();
$relationList->addMany($tagObjects->toArray());
if ($this->deleteUnusedTags) {
$deletedTags = array_diff($oldTags, $tagObjects->map('ID', $tagLabelField)->toArray());
if (count($deletedTags) > 0) {
$relationTable = $relation[4];
foreach ($deletedTags as $id => $title) {
$query = new SQLQuery();
$query->select = array('ID', $tagLabelField);
$query->from = array($relationTable);
$query->where = array("ID = " . $id);
$count = $query->Count();
if ($count == 0) {
DataObject::delete_by_id($tagClass, $id);
}
}
}
}
} else {
if ($record->hasField($this->name)) {
$record->setCastedField($this->name, $this->dataValue());
} else {
// @TODO: better error handling
}
}
}