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


PHP SQLSelect::count方法代码示例

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


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

示例1: checkAndCreateMappings

 /**
  *	Instantiate the appropriate link mappings, making sure they are not referencing the current live URL.
  */
 protected function checkAndCreateMappings()
 {
     $livePages = SiteTree::get()->map()->toArray();
     foreach ($this->linkMappings as $URL => $siteTreeID) {
         // Check that the destination site tree element is live.
         if (isset($livePages[$siteTreeID])) {
             // Check that the URL is not the current live URL.
             $query = new SQLSelect('ID', $this->replayTable, "FullURL = '{$URL}'");
             if ($query->count('ID') == 0) {
                 echo "<div>{$siteTreeID} - {$URL}</div><br>";
                 if ($this->live) {
                     singleton('MisdirectionService')->createPageMapping($URL, $siteTreeID);
                 }
             }
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-misdirection,代码行数:20,代码来源:MisdirectionHistoricalLinkMappingTask.php

示例2: add

 /**
  * Add an item to this many_many relationship
  * Does so by adding an entry to the joinTable.
  *
  * @param mixed $item
  * @param array $extraFields A map of additional columns to insert into the joinTable.
  * Column names should be ANSI quoted.
  */
 public function add($item, $extraFields = array())
 {
     // Ensure nulls or empty strings are correctly treated as empty arrays
     if (empty($extraFields)) {
         $extraFields = array();
     }
     // Determine ID of new record
     if (is_numeric($item)) {
         $itemID = $item;
     } elseif ($item instanceof $this->dataClass) {
         $itemID = $item->ID;
     } else {
         throw new InvalidArgumentException("ManyManyList::add() expecting a {$this->dataClass} object, or ID value", E_USER_ERROR);
     }
     // Validate foreignID
     $foreignIDs = $this->getForeignID();
     if (empty($foreignIDs)) {
         throw new Exception("ManyManyList::add() can't be called until a foreign ID is set", E_USER_WARNING);
     }
     // Apply this item to each given foreign ID record
     if (!is_array($foreignIDs)) {
         $foreignIDs = array($foreignIDs);
     }
     foreach ($foreignIDs as $foreignID) {
         // Check for existing records for this item
         if ($foreignFilter = $this->foreignIDWriteFilter($foreignID)) {
             // With the current query, simply add the foreign and local conditions
             // The query can be a bit odd, especially if custom relation classes
             // don't join expected tables (@see Member_GroupSet for example).
             $query = new SQLSelect("*", "\"{$this->joinTable}\"");
             $query->addWhere($foreignFilter);
             $query->addWhere(array("\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID));
             $hasExisting = $query->count() > 0;
         } else {
             $hasExisting = false;
         }
         // Blank manipulation
         $manipulation = array($this->joinTable => array('command' => $hasExisting ? 'update' : 'insert', 'fields' => array()));
         if ($hasExisting) {
             $manipulation[$this->joinTable]['where'] = array("\"{$this->joinTable}\".\"{$this->foreignKey}\"" => $foreignID, "\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID);
         }
         if ($extraFields && $this->extraFields) {
             // Write extra field to manipluation in the same way
             // that DataObject::prepareManipulationTable writes fields
             foreach ($this->extraFields as $fieldName => $fieldSpec) {
                 // Skip fields without an assignment
                 if (array_key_exists($fieldName, $extraFields)) {
                     $fieldObject = Object::create_from_string($fieldSpec, $fieldName);
                     $fieldObject->setValue($extraFields[$fieldName]);
                     $fieldObject->writeToManipulation($manipulation[$this->joinTable]);
                 }
             }
         }
         $manipulation[$this->joinTable]['fields'][$this->localKey] = $itemID;
         $manipulation[$this->joinTable]['fields'][$this->foreignKey] = $foreignID;
         DB::manipulate($manipulation);
     }
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:66,代码来源:ManyManyList.php

示例3: add

 /**
  * Add an item to this many_many relationship
  * Does so by adding an entry to the joinTable.
  *
  * @param mixed $item
  * @param array $extraFields A map of additional columns to insert into the joinTable.
  * Column names should be ANSI quoted.
  */
 public function add($item, $extraFields = array())
 {
     // Ensure nulls or empty strings are correctly treated as empty arrays
     if (empty($extraFields)) {
         $extraFields = array();
     }
     // Determine ID of new record
     if (is_numeric($item)) {
         $itemID = $item;
     } elseif ($item instanceof $this->dataClass) {
         $itemID = $item->ID;
     } else {
         throw new InvalidArgumentException("ManyManyList::add() expecting a {$this->dataClass} object, or ID value", E_USER_ERROR);
     }
     // Validate foreignID
     $foreignIDs = $this->getForeignID();
     if (empty($foreignIDs)) {
         throw new Exception("ManyManyList::add() can't be called until a foreign ID is set", E_USER_WARNING);
     }
     // Apply this item to each given foreign ID record
     if (!is_array($foreignIDs)) {
         $foreignIDs = array($foreignIDs);
     }
     foreach ($foreignIDs as $foreignID) {
         // Check for existing records for this item
         if ($foreignFilter = $this->foreignIDWriteFilter($foreignID)) {
             // With the current query, simply add the foreign and local conditions
             // The query can be a bit odd, especially if custom relation classes
             // don't join expected tables (@see Member_GroupSet for example).
             $query = new SQLSelect("*", "\"{$this->joinTable}\"");
             $query->addWhere($foreignFilter);
             $query->addWhere(array("\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID));
             $hasExisting = $query->count() > 0;
         } else {
             $hasExisting = false;
         }
         $manipulation = array();
         if ($hasExisting) {
             $manipulation[$this->joinTable]['command'] = 'update';
             $manipulation[$this->joinTable]['where'] = array("\"{$this->joinTable}\".\"{$this->foreignKey}\"" => $foreignID, "\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID);
         } else {
             $manipulation[$this->joinTable]['command'] = 'insert';
         }
         if ($extraFields) {
             foreach ($extraFields as $fieldName => $fieldValue) {
                 if (is_null($fieldValue)) {
                     $manipulation[$this->joinTable]['fields'][$fieldName] = null;
                 } elseif ($fieldValue instanceof DBField) {
                     // rely on writeToManipulation to manage the changes
                     // required for this field.
                     $working = array('fields' => array());
                     // create a new instance of the field so we can
                     // modify the field name to the correct version.
                     $field = DBField::create_field(get_class($fieldValue), $fieldValue);
                     $field->setName($fieldName);
                     $field->writeToManipulation($working);
                     foreach ($working['fields'] as $extraName => $extraValue) {
                         $manipulation[$this->joinTable]['fields'][$extraName] = $extraValue;
                     }
                 } else {
                     $manipulation[$this->joinTable]['fields'][$fieldName] = $fieldValue;
                 }
             }
         }
         $manipulation[$this->joinTable]['fields'][$this->localKey] = $itemID;
         $manipulation[$this->joinTable]['fields'][$this->foreignKey] = $foreignID;
         DB::manipulate($manipulation);
     }
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:77,代码来源:ManyManyList.php


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