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


PHP Field::getTable方法代码示例

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


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

示例1: testField

 public function testField()
 {
     $f = new Field('test', 1);
     $this->assertEquals('test', $f->getName());
     $this->assertEquals(1, $f->getTable());
     $f = new AllFields();
     $this->assertEquals(0, $f->getTable());
     $f = new AllFields(2);
     $this->assertEquals(2, $f->getTable());
     try {
         $f = new Field(array('1'));
         $this->fail('first parameter should be string (array is not allowed)');
     } catch (InvalidArgumentException $e) {
     }
     try {
         $f = new Field('foo', 'bar');
         $this->fail('second parameter has to be numeric');
     } catch (InvalidArgumentException $e) {
     }
 }
开发者ID:NinjaKC,项目名称:MySQL-Query-Builder,代码行数:20,代码来源:OtherTest.php

示例2: checkFieldTable

 /**
  * Check that the given Field's table exists and create it if it doesn't
  *
  * @param Field $field
  *
  */
 protected function checkFieldTable(Field $field)
 {
     // if(!$this->wire('config')->debug) return;
     $database = $this->wire('database');
     $table = $database->escapeTable($field->getTable());
     if (empty($table)) {
         return;
     }
     $exists = $database->query("SHOW TABLES LIKE '{$table}'")->rowCount() > 0;
     if ($exists) {
         return;
     }
     try {
         if ($field->type && count($field->type->getDatabaseSchema($field))) {
             if ($field->type->createField($field)) {
                 $this->message("Created table '{$table}'");
             }
         }
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
 }
开发者ID:avatar382,项目名称:fablab_site,代码行数:28,代码来源:Fields.php

示例3: deleteOptionsByID

 /**
  * Delete the given option IDs
  *
  * @param Field $field
  * @param array $ids
  * @return int Number of options deleted
  *
  */
 public function deleteOptionsByID(Field $field, array $ids)
 {
     $database = $this->wire('database');
     $table = $database->escapeTable($field->getTable());
     $cleanIDs = array();
     foreach ($ids as $key => $id) {
         $cleanIDs[] = (int) $id;
     }
     // convert to SQL ready string
     $cleanIDs = implode(',', $cleanIDs);
     // delete from field_[fieldName] table
     $sql = "DELETE FROM `{$table}` WHERE data IN({$cleanIDs})";
     $query = $database->prepare($sql);
     $query->execute();
     $cnt = $query->rowCount();
     $this->message("Deleted {$cnt} rows from table {$table}", Notice::debug);
     // delete from fieldtype_options table
     $table = self::optionsTable;
     $sql = "DELETE FROM `{$table}` WHERE fields_id=:fields_id AND option_id IN({$cleanIDs})";
     $query = $database->prepare($sql);
     $query->bindValue(':fields_id', $field->id);
     $query->execute();
     $cnt = $query->rowCount();
     $this->message("Deleted {$cnt} rows from table {$table}", Notice::debug);
     $this->message(sprintf($this->_n('Deleted %d option', 'Deleted %d options', $cnt), $cnt));
     return $cnt;
 }
开发者ID:posixpascal,项目名称:TrooperCMS,代码行数:35,代码来源:SelectableOptionManager.php

示例4: getNumRows

 /**
  * Return a count of database rows populated the given field
  *
  * @param Field $field
  * @param array $options Optionally specify any of the following options:
  * 	template: Specify a Template object, ID or name to isolate returned rows specific to pages using that template. 
  * 	page: Specify a Page object, ID or path to isolate returned rows specific to that page. 
  * 	countPages: Specify boolean true to make it return a page count rather than a row count (default=false). 
  * 		There will only potential difference between rows and pages counts with multi-value fields. 
  * 	getPageIDs: Specify boolean true to make it return an array of matching Page IDs rather than a count (overrides countPages).
  * @return int|array Returns array only if getPageIDs option set. 
  * @throws WireException If given option for page or template doesn't resolve to actual page/template.
  *
  */
 public function getNumRows(Field $field, array $options = array())
 {
     $defaults = array('template' => 0, 'page' => 0, 'countPages' => false, 'getPageIDs' => false);
     $options = array_merge($defaults, $options);
     $database = $this->wire('database');
     $table = $database->escapeTable($field->getTable());
     $useRowCount = false;
     $schema = $field->type->getDatabaseSchema($field);
     if (empty($schema)) {
         // field has no schema or table (example: FieldtypeConcat)
         if ($options['getPageIDs']) {
             return array();
         }
         return 0;
     }
     if ($options['template']) {
         // count by pages using specific template
         if ($options['template'] instanceof Template) {
             $template = $options['template'];
         } else {
             $template = $this->wire('templates')->get($options['template']);
         }
         if (!$template) {
             throw new WireException("Unknown template: {$options['template']}");
         }
         if ($options['getPageIDs']) {
             $sql = "SELECT DISTINCT {$table}.pages_id FROM {$table} " . "JOIN pages ON pages.templates_id=:templateID AND pages.id=pages_id ";
         } else {
             if ($options['countPages']) {
                 $sql = "SELECT COUNT(DISTINCT pages_id) FROM {$table} " . "JOIN pages ON pages.templates_id=:templateID AND pages.id=pages_id ";
             } else {
                 $sql = "SELECT COUNT(*) FROM pages " . "JOIN {$table} ON {$table}.pages_id=pages.id " . "WHERE pages.templates_id=:templateID ";
             }
         }
         $query = $database->prepare($sql);
         $query->bindValue(':templateID', $template->id, PDO::PARAM_INT);
     } else {
         if ($options['page']) {
             // count by specific page
             if (is_int($options['page'])) {
                 $pageID = $options['page'];
             } else {
                 $page = $this->wire('pages')->get($options['page']);
                 $pageID = $page->id;
             }
             if (!$pageID) {
                 throw new WireException("Unknown page: {$options['page']}");
             }
             if ($options['countPages']) {
                 // is there any the point to  this?
                 $sql = "SELECT COUNT(DISTINCT pages_id) FROM {$table} WHERE pages_id=:pageID ";
             } else {
                 $sql = "SELECT COUNT(*) FROM {$table} WHERE pages_id=:pageID ";
             }
             $query = $database->prepare($sql);
             $query->bindValue(':pageID', $pageID, PDO::PARAM_INT);
         } else {
             // overall total count
             if ($options['getPageIDs']) {
                 $sql = "SELECT DISTINCT {$table}.pages_id FROM {$table}";
             } else {
                 if ($options['countPages']) {
                     $sql = "SELECT COUNT(DISTINCT pages_id) FROM {$table}";
                 } else {
                     $sql = "SELECT COUNT(*) FROM {$table}";
                 }
             }
             $query = $database->prepare($sql);
         }
     }
     $return = $options['getPageIDs'] ? array() : 0;
     try {
         $query->execute();
         if ($options['getPageIDs']) {
             while ($row = $query->fetch(PDO::FETCH_NUM)) {
                 $return[] = (int) $row['id'];
             }
         } else {
             if ($useRowCount) {
                 $return = (int) $query->rowCount();
             } else {
                 list($return) = $query->fetch(PDO::FETCH_NUM);
                 $return = (int) $return;
             }
         }
     } catch (Exception $e) {
//.........这里部分代码省略.........
开发者ID:Rizsti,项目名称:Processwire_Compatibility,代码行数:101,代码来源:Fields.php


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