• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP fORMDatabase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: storeManyToMany

 /**
  * Associates a set of many-to-many related records with the current record
  *
  * @internal
  *
  * @param  string $class         The class the relationship is being stored for
  * @param  array  &$values       The current values for the main record being stored
  * @param  array  $relationship  The information about the relationship between this object and the records in the record set
  * @param  array  $related_info  An array containing the keys `'record_set'`, `'count'`, `'primary_keys'` and `'associate'`
  * @return void
  */
 public static function storeManyToMany($class, &$values, $relationship, $related_info)
 {
     $db = fORMDatabase::retrieve($class, 'write');
     $schema = fORMSchema::retrieve($class);
     $column_value = $values[$relationship['column']];
     // First, we remove all existing relationships between the two tables
     $join_table = $relationship['join_table'];
     $join_column = $relationship['join_column'];
     $params = array("DELETE FROM %r WHERE " . fORMDatabase::makeCondition($schema, $join_table, $join_column, '=', $column_value), $join_table, $join_column, $column_value);
     call_user_func_array($db->translatedQuery, $params);
     // Then we add back the ones in the record set
     $join_related_column = $relationship['join_related_column'];
     $related_pk_columns = $schema->getKeys($relationship['related_table'], 'primary');
     $related_column_values = array();
     // If the related column is the primary key, we can just use the primary keys if we have them
     if ($related_pk_columns[0] == $relationship['related_column'] && $related_info['primary_keys']) {
         $related_column_values = $related_info['primary_keys'];
         // Otherwise we need to pull the related values out of the record set
     } else {
         // If there is no record set, build it from the primary keys
         if (!$related_info['record_set']) {
             $related_class = fORM::classize($relationship['related_table']);
             $related_class = fORM::getRelatedClass($class, $related_class);
             $related_info['record_set'] = fRecordSet::build($related_class, array($related_pk_columns[0] . '=' => $related_info['primary_keys']));
         }
         $get_related_method_name = 'get' . fGrammar::camelize($relationship['related_column'], TRUE);
         foreach ($related_info['record_set'] as $record) {
             $related_column_values[] = $record->{$get_related_method_name}();
         }
     }
     // Ensure we aren't storing duplicates
     $related_column_values = array_unique($related_column_values);
     $join_column_placeholder = $schema->getColumnInfo($join_table, $join_column, 'placeholder');
     $related_column_placeholder = $schema->getColumnInfo($join_table, $join_related_column, 'placeholder');
     foreach ($related_column_values as $related_column_value) {
         $params = array("INSERT INTO %r (%r, %r) VALUES (" . $join_column_placeholder . ", " . $related_column_placeholder . ")", $join_table, $join_column, $join_related_column, $column_value, $related_column_value);
         call_user_func_array($db->translatedQuery, $params);
     }
 }
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:50,代码来源:fORMRelated.php


示例17: precount

 /** 
  * Counts the related records for all records in this set in one DB query
  *  
  * @param  string $related_class  This should be the name of a related class
  * @param  string $route          This should be a column name or a join table name and is only required when there are multiple routes to a related table. If there are multiple routes and this is not specified, an fProgrammerException will be thrown.
  * @return fRecordSet  The record set object, to allow for method chaining
  */
 private function precount($related_class, $route = NULL)
 {
     if (!$this->records) {
         return $this;
     }
     $this->validateSingleClass('precount');
     // If there are no primary keys we can just exit
     if (!array_merge($this->getPrimaryKeys())) {
         return $this;
     }
     fActiveRecord::validateClass($related_class);
     fActiveRecord::forceConfigure($related_class);
     $db = fORMDatabase::retrieve($this->class, 'read');
     $schema = fORMSchema::retrieve($this->class);
     $related_table = fORM::tablize($related_class);
     $table = fORM::tablize($this->class);
     $route = fORMSchema::getRouteName($schema, $table, $related_table, $route, '*-to-many');
     $relationship = fORMSchema::getRoute($schema, $table, $related_table, $route, '*-to-many');
     // Build the query out
     $table_and_column = $table . '.' . $relationship['column'];
     if (isset($relationship['join_table'])) {
         $table_to_join = $relationship['join_table'];
         $column_to_join = $relationship['join_table'] . '.' . $relationship['join_column'];
     } else {
         $table_to_join = $related_table;
         $column_to_join = $related_table . '.' . $relationship['related_column'];
     }
     $params = array($db->escape("SELECT count(*) AS flourish__count, %r AS flourish__column FROM %r INNER JOIN %r ON %r = %r WHERE ", $table_and_column, $table, $table_to_join, $table_and_column, $column_to_join));
     $params = $this->addWhereParams($db, $schema, $params);
     $params[0] .= $db->escape(' GROUP BY %r', $table_and_column);
     // Run the query and inject the results into the records
     $result = call_user_func_array($db->translatedQuery, $params);
     $counts = array();
     foreach ($result as $row) {
         $counts[$row['flourish__column']] = (int) $row['flourish__count'];
     }
     unset($result);
     $total_records = sizeof($this->records);
     $get_method = 'get' . fGrammar::camelize($relationship['column'], TRUE);
     $tally_method = 'tally' . fGrammar::pluralize($related_class);
     for ($i = 0; $i < $total_records; $i++) {
         $record = $this->records[$i];
         $count = isset($counts[$record->{$get_method}()]) ? $counts[$record->{$get_method}()] : 0;
         $record->{$tally_method}($count, $route);
     }
     return $this;
 }
开发者ID:JhunCabas,项目名称:material-management,代码行数:54,代码来源:fRecordSet.php


示例18: setUp

 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach($this->sharedFixture['db']);
     fORMSchema::attach($this->sharedFixture['schema']);
     fORM::mapClassToTable('Flourish2User', fix_schema('flourish2.users'));
     fORM::mapClassToTable('Flourish2Group', fix_schema('flourish2.groups'));
     fORM::mapClassToTable('Flourish2Artist', fix_schema('flourish2.artists'));
     fORM::mapClassToTable('Flourish2Album', fix_schema('flourish2.albums'));
 }
开发者ID:philip,项目名称:flourish,代码行数:12,代码来源:fActiveRecordWithMultipleSchemasTest.php


示例19: checkUniqueConstraints

 /**
  * Validates values against unique constraints
  *
  * @param  fSchema        $schema       The schema object for the object
  * @param  fActiveRecord  $object       The instance of the class to check
  * @param  array          &$values      The values to check
  * @param  array          &$old_values  The old values for the record
  * @return array  An aray of error messages for the unique constraints
  */
 private static function checkUniqueConstraints($schema, $object, &$values, &$old_values)
 {
     $class = get_class($object);
     $table = fORM::tablize($class);
     $db = fORMDatabase::retrieve($class, 'read');
     $key_info = $schema->getKeys($table);
     $pk_columns = $key_info['primary'];
     $unique_keys = $key_info['unique'];
     $messages = array();
     foreach ($unique_keys as $unique_columns) {
         settype($unique_columns, 'array');
         // NULL values are unique
         $found_not_null = FALSE;
         foreach ($unique_columns as $unique_column) {
             if ($values[$unique_column] !== NULL) {
                 $found_not_null = TRUE;
             }
         }
         if (!$found_not_null) {
             continue;
         }
         $params = array("SELECT %r FROM %r WHERE ", $key_info['primary'], $table);
         $column_info = $schema->getColumnInfo($table);
         $conditions = array();
         foreach ($unique_columns as $unique_column) {
             $value = $values[$unique_column];
             // This makes sure the query performs the way an insert will
             if ($value === NULL && $column_info[$unique_column]['not_null'] && $column_info[$unique_column]['default'] !== NULL) {
                 $value = $column_info[$unique_column]['default'];
             }
             if (self::isCaseInsensitive($class, $unique_column) && self::stringlike($value)) {
                 $condition = fORMDatabase::makeCondition($schema, $table, $unique_column, '=', $value);
                 $conditions[] = str_replace('%r', 'LOWER(%r)', $condition);
                 $params[] = $table . '.' . $unique_column;
                 $params[] = fUTF8::lower($value);
             } else {
                 $conditions[] = fORMDatabase::makeCondition($schema, $table, $unique_column, '=', $value);
                 $params[] = $table . '.' . $unique_column;
                 $params[] = $value;
             }
         }
         $params[0] .= join(' AND ', $conditions);
         if ($object->exists()) {
             foreach ($pk_columns as $pk_column) {
                 $value = fActiveRecord::retrieveOld($old_values, $pk_column, $values[$pk_column]);
                 $params[0] .= ' AND ' . fORMDatabase::makeCondition($schema, $table, $pk_column, '<>', $value);
                 $params[] = $table . '.' . $pk_column;
                 $params[] = $value;
             }
         }
         try {
             $result = call_user_func_array($db->translatedQuery, $params);
             $result->tossIfNoRows();
             // If an exception was not throw, we have existing values
             $column_names = array();
             foreach ($unique_columns as $unique_column) {
                 $column_names[] = fORM::getColumnName($class, $unique_column);
             }
             if (sizeof($column_names) == 1) {
                 $messages[join('', $unique_columns)] = self::compose('%sThe value specified must be unique, however it already exists', fValidationException::formatField(join('', $column_names)));
             } else {
                 $messages[join(',', $unique_columns)] = self::compose('%sThe values specified must be a unique combination, however the specified combination already exists', fValidationException::formatField(join(', ', $column_names)));
             }
         } catch (fNoRowsException $e) {
         }
     }
     return $messages;
 }
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:77,代码来源:fORMValidation.php


示例20: validate

 /**
  * Makes sure the ordering value is sane, removes error messages about missing values
  *
  * @internal
  *
  * @param  fActiveRecord $object                The fActiveRecord instance
  * @param  array         &$values               The current values
  * @param  array         &$old_values           The old values
  * @param  array         &$related_records      Any records related to this record
  * @param  array         &$cache                The cache array for the record
  * @param  array         &$validation_messages  An array of ordered validation messages
  * @return void
  */
 public static function validate($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $class = get_class($object);
     $table = fORM::tablize($class);
     $db = fORMDatabase::retrieve($class, 'read');
     $schema = fORMSchema::retrieve($class);
     foreach (self::$ordering_columns[$class] as $column => $other_columns) {
         $current_value = $values[$column];
         $old_value = fActiveRecord::retrieveOld($old_values, $column);
         $params = array("SELECT MAX(%r) FROM %r", $column, $table);
         if ($other_columns) {
             $params[0] .= " WHERE ";
             $params = self::addOtherFieldsWhereParams($schema, $params, $table, $other_columns, $values);
         }
         $current_max_value = (int) call_user_func_array($db->translatedQuery, $params)->fetchScalar();
         $new_max_value = $current_max_value;
         if ($new_set = self::isInNewSet($column, $other_columns, $values, $old_values)) {
             $new_max_value = $current_max_value + 1;
             $new_set_new_value = fActiveRecord::changed($values, $old_values, $column);
         }
         $column_name = fORM::getColumnName($class, $column);
         // Remove any previous validation warnings
         $filtered_messages = array();
         foreach ($validation_messages as $validation_column => $validation_message) {
             if (!preg_match('#(^|,)' . preg_quote($column, '#') . '(,|$)#D', $validation_column)) {
                 $filtered_messages[$validation_column] = $validation_message;
             }
         }
         $validation_messages = $filtered_messages;
         // If we have a completely empty value, we don't need to validate since a valid value will be generated
         if ($current_value === '' || $current_value === NULL) {
             continue;
         }
         if (!is_numeric($current_value) || strlen((int) $current_value) != strlen($current_value)) {
             $validation_messages[$column] = self::compose('%sPlease enter an integer', fValidationException::formatField($column_name));
         } elseif ($current_value < 1) {
             $validation_messages[$column] = self::compose('%sThe value can not be less than 1', fValidationException::formatField($column_name));
         }
     }
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:53,代码来源:fORMOrdering.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP fORMSchema类代码示例发布时间:2022-05-23
下一篇:
PHP fORM类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap