本文整理汇总了PHP中fORMDatabase::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP fORMDatabase::retrieve方法的具体用法?PHP fORMDatabase::retrieve怎么用?PHP fORMDatabase::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fORMDatabase
的用法示例。
在下文中一共展示了fORMDatabase::retrieve方法的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;
}
示例2: 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'];
}
}
示例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()));
}
}
示例4: 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);
}
示例5: 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);
}
}
示例6: 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()));
}
}
示例7: copy
$fileName[] = $_FILES['files']['name'][$i];
$fileType[] = $_FILES['files']['type'][$i];
copy($dir . $fileName[$i], $dir2 . $fileName[$i]);
$image3 = new fImage($dir2 . $fileName[$i]);
$image3->cropToRatio(1, 1, 'left', 'bottom');
$image3->resize(200, 0);
$image3->saveChanges();
/*
$ftp = new ftp($user,$pass);
$ftp->upload($dir . "/" . $fileName[$i], 'DIR EN REMOTE');
# resize
$ftp->upload($dir2 . "/" . $fileName[$i], 'DIR EN REMOTE');
$image->delete
*/
}
/*
* Add Files to DataBase (Resource)
*/
try {
$statement = fORMDatabase::retrieve()->prepare("INSERT INTO resource (id_entity,id_section,token,url,resource_type,description) VALUES (%i, 1, '', %s, %s, %s)");
for ($i = 0; $i < $uploaded; $i++) {
if ($imageDescrip[$i] == "Si es necesario escribe la descripción del archivo") {
$imageDescrip[$i] = "";
}
fORMDatabase::retrieve()->query($statement, $lastId, $fileName[$i], $banner->getResourceType($fileType[$i]), $imageDescrip[$i]);
}
} catch (fSQLException $e) {
die("No se ha podido ejecutar la consulta");
}
}
exit("1");
示例8: enableSchemaCaching
/**
* Enables caching on the fDatabase, fSQLTranslation and fSchema objects used for the ORM
*
* This method will cache database schema information to the three objects
* that use it during normal ORM operation: fDatabase, fSQLTranslation and
* fSchema. To allow for schema changes without having to manually clear
* the cache, all cached information will be cleared if any
* fUnexpectedException objects are thrown.
*
* This method should be called right after fORMDatabase::attach().
*
* @param fCache $cache The object to cache schema information to
* @param string $database_name The database to enable caching for
* @param string $key_token This is a token that is used in cache keys to prevent conflicts for server-wide caches - when non-NULL the document root is used
* @return void
*/
public static function enableSchemaCaching($cache, $database_name = 'default', $key_token = NULL)
{
if ($key_token === NULL) {
$key_token = $_SERVER['DOCUMENT_ROOT'];
}
$token = 'fORM::' . $database_name . '::' . $key_token . '::';
$db = fORMDatabase::retrieve('name:' . $database_name);
$db->enableCaching($cache, $token);
fException::registerCallback($db->clearCache, 'fUnexpectedException');
$sql_translation = $db->getSQLTranslation();
$sql_translation->enableCaching($cache, $token);
$schema = fORMSchema::retrieve('name:' . $database_name);
$schema->enableCaching($cache, $token);
fException::registerCallback($schema->clearCache, 'fUnexpectedException');
}
示例9: testPrecountOneToMany
public function testPrecountOneToMany()
{
$set = fRecordSet::build('Flourish2Artist');
$set->precountFlourish2Albums();
ob_start();
fORMDatabase::retrieve()->enableDebugging(TRUE);
foreach ($set as $artist) {
$count = $artist->countFlourish2Albums();
switch ($artist->getArtistId()) {
case 1:
$expected_count = 3;
break;
case 2:
$expected_count = 2;
break;
case 3:
$expected_count = 1;
break;
}
$this->assertEquals($expected_count, $count);
}
fORMDatabase::retrieve()->enableDebugging(FALSE);
$output = ob_get_clean();
$this->assertEquals('', $output);
}
示例10: buildScalesWithRange
/**
* Build scales and setup their ranges from test's questions
*
* @return WpTesting_Model_Scale[]
*/
public function buildScalesWithRange()
{
$scales = $this->buildScales();
if (!$scales->count()) {
return $scales;
}
$questionIds = array_filter($this->listWpTesting_Model_Questions());
if (empty($questionIds)) {
return $scales;
}
$lastColumnInRow = $this->isMultipleAnswers() ? 's.answer_id' : 'question_id';
/* @var $db fDatabase */
$db = fORMDatabase::retrieve('WpTesting_Model_Score', 'read');
$scoresTable = fORM::tablize('WpTesting_Model_Score');
$answersTable = fORM::tablize('WpTesting_Model_Answer');
$result = $db->translatedQuery('
SELECT
scale_id,
SUM(minimum_in_row) AS minimum_in_column,
SUM(maximum_in_row) AS maximum_in_column,
SUM(sum_in_row) AS sum_in_column
FROM (
SELECT
scale_id,
MIN(IF(score_value > 0, 0, score_value)) AS minimum_in_row,
MAX(IF(score_value > 0, score_value, 0)) AS maximum_in_row,
SUM(score_value) AS sum_in_row
FROM ' . $scoresTable . ' AS s
JOIN ' . $answersTable . ' AS a ON s.answer_id = a.answer_id
WHERE TRUE
AND question_id IN (' . implode(',', $questionIds) . ')
AND scale_id IN (' . implode(',', $scales->getPrimaryKeys()) . ')
GROUP BY scale_id, question_id, ' . $lastColumnInRow . '
HAVING minimum_in_row < maximum_in_row
) AS groupped
GROUP BY scale_id
');
$resultByPk = array();
foreach ($result->fetchAllRows() as $row) {
$resultByPk[$row['scale_id']] = $row;
}
foreach ($scales as $scale) {
if (isset($resultByPk[$scale->getId()])) {
$values = $resultByPk[$scale->getId()];
$scale->setRange($values['minimum_in_column'], $values['maximum_in_column'], $values['sum_in_column']);
}
}
return $scales;
}
示例11: enableSchemaCaching
/**
* Enables caching on the fDatabase, fSQLTranslation and fSchema objects used for the ORM
*
* This method will cache database schema information to the three objects
* that use it during normal ORM operation: fDatabase, fSQLTranslation and
* fSchema. To allow for schema changes without having to manually clear
* the cache, all cached information will be cleared if any
* fUnexpectedException objects are thrown.
*
* This method should be called right after fORMDatabase::attach().
*
* @param fCache $cache The object to cache schema information to
* @return void
*/
public static function enableSchemaCaching($cache)
{
$db = fORMDatabase::retrieve();
$db->enableCaching($cache);
fException::registerCallback($db->clearCache, 'fUnexpectedException');
$sql_translation = $db->getSQLTranslation();
$sql_translation->enableCaching($cache);
fException::registerCallback($sql_translation->clearCache, 'fUnexpectedException');
$schema = fORMSchema::retrieve();
$schema->enableCaching($cache);
fException::registerCallback($schema->clearCache, 'fUnexpectedException');
}
示例12: header
<?php
fSession::open();
$idUser = fSession::get(SESSION_ID_USER);
//if(empty($idUser) || !fAuthorization::checkACL('banner', 'delete')) {
if (empty($idUser)) {
header('Location: ' . SITE);
exit("No se ha podido acceder a esta secci&oacite;n");
}
$id = fRequest::encode('id', 'string');
if (strstr($id, ",")) {
fORMDatabase::retrieve()->query("DELETE FROM banner WHERE id_banner IN ({$id})");
} else {
$banner = new Banner($id);
$banner->delete();
}
fORMDatabase::retrieve()->query("DELETE FROM resource WHERE id_entity IN ({$id}) AND id_section = 1");
示例13: 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));
}
}
}
示例14: generate
/**
* Generates a new random value for the column
*
* @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 string $method_name The method that was called
* @param array $parameters The parameters passed to the method
* @return string The newly generated random value
*/
public static function generate($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters)
{
list($action, $subject) = fORM::parseMethod($method_name);
$column = fGrammar::underscorize($subject);
$class = get_class($object);
$table = fORM::tablize($class);
$schema = fORMSchema::retrieve($class);
$db = fORMDatabase::retrieve($class, 'read');
$settings = self::$random_columns[$class][$column];
// Check to see if this is a unique column
$unique_keys = $schema->getKeys($table, 'unique');
$is_unique_column = FALSE;
foreach ($unique_keys as $unique_key) {
if ($unique_key == array($column)) {
$is_unique_column = TRUE;
$sql = "SELECT %r FROM %r WHERE %r = %s";
do {
$value = fCryptography::randomString($settings['length'], $settings['type']);
} while ($db->query($sql, $column, $table, $column, $value)->countReturnedRows());
}
}
// If is is not a unique column, just generate a value
if (!$is_unique_column) {
$value = fCryptography::randomString($settings['length'], $settings['type']);
}
fActiveRecord::assign($values, $old_values, $column, $value);
return $value;
}
示例15: getDb
protected function getDb($role = 'write')
{
return fORMDatabase::retrieve(get_class($this), $role);
}