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


PHP SQLQuery::Count方法代码示例

本文整理汇总了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
         }
     }
 }
开发者ID:nathancox,项目名称:silverstripe-tagitfield,代码行数:50,代码来源:TagItField.php


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