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


PHP fORMDatabase类代码示例

本文整理汇总了PHP中fORMDatabase的典型用法代码示例。如果您正苦于以下问题:PHP fORMDatabase类的具体用法?PHP fORMDatabase怎么用?PHP fORMDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: sortTermIdsByTermOrder

 /**
  * Helper function to workaround old WP versions
  * @param integer $testId
  * @param array $termIds
  * @return array
  */
 public function sortTermIdsByTermOrder($testId, $termIds)
 {
     if (empty($testId) || empty($termIds)) {
         return $termIds;
     }
     /* @var $db fDatabase */
     $db = fORMDatabase::retrieve(__CLASS__, 'read');
     $records = $db->translatedQuery('
         SELECT
             tt.term_id
         FROM
             ' . WP_DB_PREFIX . 'term_relationships tr
         JOIN
             ' . WP_DB_PREFIX . 'term_taxonomy tt
             ON tt.term_taxonomy_id = tr.term_taxonomy_id
         WHERE tt.term_id IN (' . implode(', ', array_map('intval', $termIds)) . ')
         AND tr.object_id = ' . intval($testId) . '
         ORDER BY tr.term_order
     ');
     $result = array();
     foreach ($records as $record) {
         $result[] = $record['term_id'];
     }
     return $result;
 }
开发者ID:pmanterys,项目名称:wp-mw-newsletter,代码行数:31,代码来源:Taxonomy.php

示例2: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     if (DB_TYPE == 'sqlite') {
         $db->execute(file_get_contents(DB_SETUP_FILE));
         $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
     }
     $db->execute(file_get_contents(DB_POPULATE_FILE));
     $db->execute(file_get_contents(DB_EXTENDED_POPULATE_FILE));
     self::$db = $db;
     self::$schema = new fSchema($db);
     fORMDatabase::attach(self::$db);
     fORMSchema::attach(self::$schema);
     fORMOrdering::configureOrderingColumn('TopAlbum', 'position');
     fORMOrdering::configureOrderingColumn('FavoriteAlbum', 'position');
     fORMOrdering::configureOrderingColumn('YearFavoriteAlbum', 'position');
     if (defined('MAP_TABLES')) {
         fORM::mapClassToTable('User', 'user');
         fORM::mapClassToTable('Group', 'group');
         fORM::mapClassToTable('Artist', 'popular_artists');
         fORM::mapClassToTable('Album', 'records');
     }
 }
开发者ID:nurulimamnotes,项目名称:flourish-old,代码行数:26,代码来源:fORMOrderingTest.php

示例3: importUsers

 public function importUsers()
 {
     try {
         $raw = fRequest::get('content');
         $this->db = fORMDatabase::retrieve();
         $this->db->query('BEGIN');
         foreach (explode("\n", $raw) as $i) {
             $j = preg_split('/\\s+/', $i);
             if (count($j) < 2) {
                 continue;
             }
             $x = $j[0];
             $y = $j[1];
             $user = new Name();
             $user->setRealname($x);
             $user->setStudentNumber($y);
             $user->store();
         }
         $this->db->query('COMMIT');
         $this->ajaxReturn(array('result' => 'success'));
     } catch (fException $e) {
         if (isset($this->db)) {
             $this->db->query('ROLLBACK');
         }
         $this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage()));
     }
 }
开发者ID:daerduoCarey,项目名称:xiaoyou,代码行数:27,代码来源:AdminController.php

示例4: getImage

 public static function getImage($id_entity, $id_section)
 {
     $result = fORMDatabase::retrieve()->unbufferedQuery("SELECT * FROM resource WHERE id_entity='{$id_entity}' AND id_section='{$id_section}' AND resource_type='i' LIMIT 1");
     foreach ($result as $r) {
         return $r['url'];
     }
 }
开发者ID:nevermind89x,项目名称:Mi-morelia,代码行数:7,代码来源:banner.php

示例5: hasAccepted

 public static function hasAccepted($problem)
 {
     if (self::$accepted_cache === NULL) {
         $db = fORMDatabase::retrieve();
         $result = $db->translatedQuery('SELECT DISTINCT problem_id FROM records WHERE owner=%s AND verdict=%i', fAuthorization::getUserToken(), Verdict::AC);
         $result->unescape(array('problem_id' => 'integer'));
         self::$accepted_cache = array();
         foreach ($result as $row) {
             self::$accepted_cache[] = $row['problem_id'];
         }
     }
     return in_array($problem->getId(), self::$accepted_cache);
 }
开发者ID:daerduoCarey,项目名称:oj,代码行数:13,代码来源:User.php

示例6: setUp

 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach(self::$db);
     fORMSchema::attach(self::$schema);
     if (defined('MAP_TABLES')) {
         fORM::mapClassToTable('User', 'user');
         fORM::mapClassToTable('Group', 'group');
         fORM::mapClassToTable('Artist', 'popular_artists');
         fORM::mapClassToTable('Album', 'records');
     }
 }
开发者ID:netcarver,项目名称:flourish,代码行数:14,代码来源:fORMValidationTest.php

示例7: update

 public function update($id)
 {
     try {
         $this->db = fORMDatabase::retrieve();
         $this->db->query('BEGIN');
         $profile = new Profile($id);
         if (UserHelper::getProfileId() != $profile->getId() and !UserHelper::isEditor()) {
             throw new fValidationException('not allowed');
         }
         $profile->setStartYear(fRequest::get('start_year'));
         $profile->setClassNumber(fRequest::get('class_number'));
         $profile->setStudentNumber(trim(fRequest::get('student_number')));
         $profile->setBirthday(trim(fRequest::get('birthday')));
         $profile->setGender(fRequest::get('gender'));
         //$profile->setLocation(trim(fRequest::get('location')));
         $province = trim(fRequest::get('province'));
         $city = trim(fRequest::get('city'));
         $profile->setLocation(self::formatLocation($province, $city));
         $profile->setPostNumber(trim(fRequest::get('post_number')));
         $profile->setPrivacyControl(trim(fRequest::get('privacy', 'int', 0)));
         $profile->setField(trim(fRequest::get('field')));
         $profile->setInstitute(trim(fRequest::get('institute')));
         $profile->setPosition(trim(fRequest::get('position')));
         $profile->setMajor(trim(fRequest::get('major')));
         $profile->setMentor(trim(fRequest::get('mentor')));
         $profile->setSubscription(trim(fRequest::get('subscription')));
         $profile->store();
         foreach ($profile->getContacts() as $contact) {
             $contact->delete();
         }
         foreach ($this->contact_types as $type) {
             if (strlen(trim(fRequest::get($type)))) {
                 $contact = new Contact();
                 $contact->setProfileId($profile->getId());
                 $contact->setType($type);
                 $contact->setContent(trim(fRequest::get($type)));
                 $contact->setCreatedAt(Util::currentTime());
                 $contact->store();
             }
         }
         $this->db->query('COMMIT');
         Activity::fireUpdateProfile();
         $this->ajaxReturn(array('result' => 'success', 'profile_id' => $profile->getId()));
     } catch (fException $e) {
         if (isset($this->db)) {
             $this->db->query('ROLLBACK');
         }
         $this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage()));
     }
 }
开发者ID:daerduoCarey,项目名称:xiaoyou,代码行数:50,代码来源:ProfileController.php

示例8: setUp

 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach(self::$db);
     fORMDatabase::attach(self::$db2, 'db2');
     fORMSchema::attach(self::$schema);
     fORMSchema::attach(self::$schema2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
开发者ID:netcarver,项目名称:flourish,代码行数:14,代码来源:fActiveRecordWithMultipleDatabasesTest.php

示例9: setUp

 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach($this->sharedFixture['db']);
     fORMDatabase::attach($this->sharedFixture['db2'], 'db2');
     fORMSchema::attach($this->sharedFixture['schema']);
     fORMSchema::attach($this->sharedFixture['schema2'], 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
开发者ID:philip,项目名称:flourish,代码行数:14,代码来源:fActiveRecordWithMultipleDatabasesTest.php

示例10: ensureCountCaches

 private static function ensureCountCaches()
 {
     $db = fORMDatabase::retrieve();
     if (self::$accept_count_cache === NULL) {
         $result = $db->translatedQuery('SELECT problem_id, COUNT(1) AS count FROM records WHERE verdict=%i GROUP BY problem_id', Verdict::AC);
         $result->unescape(array('problem_id' => 'integer', 'count' => 'integer'));
         static::populateCountCache(self::$accept_count_cache, $result);
     }
     if (self::$submit_count_cache === NULL) {
         $result = $db->translatedQuery('SELECT problem_id, COUNT(1) AS count FROM records GROUP BY problem_id');
         $result->unescape(array('problem_id' => 'integer', 'count' => 'integer'));
         static::populateCountCache(self::$submit_count_cache, $result);
     }
 }
开发者ID:daerduoCarey,项目名称:oj,代码行数:14,代码来源:Problem.php

示例11: setUp

 protected function setUp()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $db2 = new fDatabase(DB_TYPE, DB_2, DB_2_USERNAME, DB_2_PASSWORD, DB_2_HOST, DB_2_PORT);
     $db2->execute(file_get_contents(DB_2_SETUP_FILE));
     $this->sharedFixture = array($db, $db2);
     fORMDatabase::attach($db);
     fORMDatabase::attach($db2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
开发者ID:philip,项目名称:flourish,代码行数:17,代码来源:fRecordSetWithMultipleDatabasesTest.php

示例12: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $db2 = new fDatabase(DB_TYPE, DB_2, DB_2_USERNAME, DB_2_PASSWORD, DB_2_HOST, DB_2_PORT);
     $db2->execute(file_get_contents(DB_2_SETUP_FILE));
     self::$db = $db;
     self::$db2 = $db2;
     fORMDatabase::attach($db);
     fORMDatabase::attach($db2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
开发者ID:netcarver,项目名称:flourish,代码行数:18,代码来源:fRecordSetWithMultipleDatabasesTest.php

示例13: setUp

 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     $db = $this->sharedFixture['db'];
     $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
     $db->clearCache();
     fORMDatabase::attach($db);
     fORMSchema::attach($this->sharedFixture['schema']);
     fORMOrdering::configureOrderingColumn('TopAlbum', 'position');
     fORMOrdering::configureOrderingColumn('FavoriteAlbum', 'position');
     fORMOrdering::configureOrderingColumn('YearFavoriteAlbum', 'position');
     if (defined('MAP_TABLES')) {
         fORM::mapClassToTable('User', 'user');
         fORM::mapClassToTable('Group', 'group');
         fORM::mapClassToTable('Artist', 'popular_artists');
         fORM::mapClassToTable('Album', 'records');
     }
 }
开发者ID:philip,项目名称:flourish,代码行数:20,代码来源:fORMOrderingTest.php

示例14: store

 /**
  * Stores a record in the database, whether existing or new
  * 
  * This method will start database and filesystem transactions if they have
  * not already been started.
  * 
  * @throws fValidationException  When ::validate() throws an exception
  * 
  * @param  boolean $force_cascade  When storing related records, this will force deleting child records even if they have their own children in a relationship with an RESTRICT or NO ACTION for the ON DELETE clause
  * @return fActiveRecord  The record object, to allow for method chaining
  */
 public function store($force_cascade = FALSE)
 {
     $class = get_class($this);
     if (fORM::getActiveRecordMethod($class, 'store')) {
         return $this->__call('store', array());
     }
     fORM::callHookCallbacks($this, 'pre::store()', $this->values, $this->old_values, $this->related_records, $this->cache);
     $db = fORMDatabase::retrieve($class, 'write');
     $schema = fORMSchema::retrieve($class);
     try {
         $table = fORM::tablize($class);
         // New auto-incrementing records require lots of special stuff, so we'll detect them here
         $new_autoincrementing_record = FALSE;
         if (!$this->exists()) {
             $pk_columns = $schema->getKeys($table, 'primary');
             $pk_column = $pk_columns[0];
             $pk_auto_incrementing = $schema->getColumnInfo($table, $pk_column, 'auto_increment');
             if (sizeof($pk_columns) == 1 && $pk_auto_incrementing && !$this->values[$pk_column]) {
                 $new_autoincrementing_record = TRUE;
             }
         }
         $inside_db_transaction = $db->isInsideTransaction();
         if (!$inside_db_transaction) {
             $db->translatedQuery('BEGIN');
         }
         fORM::callHookCallbacks($this, 'post-begin::store()', $this->values, $this->old_values, $this->related_records, $this->cache);
         $this->validate();
         fORM::callHookCallbacks($this, 'post-validate::store()', $this->values, $this->old_values, $this->related_records, $this->cache);
         // Storing main table
         if (!$this->exists()) {
             $params = $this->constructInsertParams();
         } else {
             $params = $this->constructUpdateParams();
         }
         $result = call_user_func_array($db->translatedQuery, $params);
         // If there is an auto-incrementing primary key, grab the value from the database
         if ($new_autoincrementing_record) {
             $this->set($pk_column, $result->getAutoIncrementedValue());
         }
         // Fix cascade updated columns for in-memory objects to prevent issues when saving
         $one_to_one_relationships = $schema->getRelationships($table, 'one-to-one');
         $one_to_many_relationships = $schema->getRelationships($table, 'one-to-many');
         $relationships = array_merge($one_to_one_relationships, $one_to_many_relationships);
         foreach ($relationships as $relationship) {
             $type = in_array($relationship, $one_to_one_relationships) ? 'one-to-one' : 'one-to-many';
             $route = fORMSchema::getRouteNameFromRelationship($type, $relationship);
             $related_table = $relationship['related_table'];
             $related_class = fORM::classize($related_table);
             $related_class = fORM::getRelatedClass($class, $related_class);
             if ($relationship['on_update'] != 'cascade') {
                 continue;
             }
             $column = $relationship['column'];
             if (!fActiveRecord::changed($this->values, $this->old_values, $column)) {
                 continue;
             }
             if (!isset($this->related_records[$related_table][$route]['record_set'])) {
                 continue;
             }
             $record_set = $this->related_records[$related_table][$route]['record_set'];
             $related_column = $relationship['related_column'];
             $old_value = fActiveRecord::retrieveOld($this->old_values, $column);
             $value = $this->values[$column];
             if ($old_value === NULL) {
                 continue;
             }
             foreach ($record_set as $record) {
                 if (isset($record->old_values[$related_column])) {
                     foreach (array_keys($record->old_values[$related_column]) as $key) {
                         if ($record->old_values[$related_column][$key] === $old_value) {
                             $record->old_values[$related_column][$key] = $value;
                         }
                     }
                 }
                 if ($record->values[$related_column] === $old_value) {
                     $record->values[$related_column] = $value;
                 }
             }
         }
         // Storing *-to-many and one-to-one relationships
         fORMRelated::store($class, $this->values, $this->related_records, $force_cascade);
         fORM::callHookCallbacks($this, 'pre-commit::store()', $this->values, $this->old_values, $this->related_records, $this->cache);
         if (!$inside_db_transaction) {
             $db->translatedQuery('COMMIT');
         }
         fORM::callHookCallbacks($this, 'post-commit::store()', $this->values, $this->old_values, $this->related_records, $this->cache);
     } catch (fException $e) {
         if (!$inside_db_transaction) {
             $db->translatedQuery('ROLLBACK');
//.........这里部分代码省略.........
开发者ID:mrjwc,项目名称:printmaster,代码行数:101,代码来源:fActiveRecord.php

示例15: testPrecountOneToManyMultiColumn

 public function testPrecountOneToManyMultiColumn()
 {
     $set = fRecordSet::build('User');
     $set->precountFavoriteAlbums();
     ob_start();
     fORMDatabase::retrieve()->enableDebugging(TRUE);
     foreach ($set as $user) {
         $count = $user->countFavoriteAlbums();
         switch ($user->getUserId()) {
             case 1:
                 $expected_count = 5;
                 break;
             case 2:
                 $expected_count = 1;
                 break;
             case 3:
                 $expected_count = 0;
                 break;
             case 4:
                 $expected_count = 0;
                 break;
         }
         $this->assertEquals($expected_count, $count);
     }
     fORMDatabase::retrieve()->enableDebugging(FALSE);
     $output = ob_get_clean();
     $this->assertEquals('', $output);
 }
开发者ID:nurulimamnotes,项目名称:flourish-old,代码行数:28,代码来源:fRecordSetTest.php


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