本文整理汇总了PHP中R::getCol方法的典型用法代码示例。如果您正苦于以下问题:PHP R::getCol方法的具体用法?PHP R::getCol怎么用?PHP R::getCol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::getCol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserExternalSystemIds
public static function getUserExternalSystemIds()
{
$columnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
RedBeanColumnTypeOptimizer::externalIdColumn(User::getTableName('User'), $columnName);
$sql = 'select ' . $columnName . ' from ' . User::getTableName('User');
return R::getCol($sql);
}
示例2: generateCampaignItems
protected static function generateCampaignItems($campaign, $pageSize)
{
if ($pageSize == null) {
$pageSize = self::DEFAULT_CAMPAIGNITEMS_TO_CREATE_PAGE_SIZE;
}
$contacts = array();
$quote = DatabaseCompatibilityUtil::getQuote();
$marketingListMemberTableName = RedBeanModel::getTableName('MarketingListMember');
$campaignItemTableName = RedBeanModel::getTableName('CampaignItem');
$sql = "select {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote} from {$quote}{$marketingListMemberTableName}{$quote}";
// Not Coding Standard
$sql .= "left join {$quote}{$campaignItemTableName}{$quote} on ";
$sql .= "{$quote}{$campaignItemTableName}{$quote}.{$quote}contact_id{$quote} ";
$sql .= "= {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote}";
$sql .= "AND {$quote}{$campaignItemTableName}{$quote}.{$quote}campaign_id{$quote} = " . $campaign->id . " ";
$sql .= "where {$quote}{$marketingListMemberTableName}{$quote}.{$quote}marketinglist_id{$quote} = " . $campaign->marketingList->id;
$sql .= " and {$quote}{$campaignItemTableName}{$quote}.{$quote}id{$quote} is null limit " . $pageSize;
$ids = R::getCol($sql);
foreach ($ids as $contactId) {
$contacts[] = Contact::getById((int) $contactId);
}
if (!empty($contacts)) {
//todo: if the return value is false, then we might need to catch that since it didn't go well.
CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts);
if (count($ids) < $pageSize) {
return true;
}
} else {
return true;
}
return false;
}
示例3: index
function index()
{
$view = new G2_TwigView('pages/index');
$test_a = R::findOne('audit');
$args = [];
if (!empty($_GET)) {
$wheres = [];
foreach ($_GET as $field => $value) {
if (isset($test_a->{$field}) && trim($value)) {
$wheres[] = "{$field} LIKE :{$field}";
$args[$field] = $value;
}
}
$where = implode(' AND ', $wheres);
} else {
$where = '';
}
$audits = Audit::deserialize(Mvc_Db::paginate_findAll('audit', 10, "{$where} ORDER BY id DESC", $args));
// Sort into entities
$sorted = [];
foreach ($audits as $audit) {
// Limit to 10 entries per entity
if (count($sorted[$audit->entity]) <= 10) {
$sorted[$audit->entity][] = $audit;
}
}
$view->set('sorted', $sorted);
$view->entities = R::getCol('SELECT DISTINCT entity FROM audit');
$view->set_entity = $_GET['entity'];
$view->page_count = Mvc_Db::get_last_total_pages();
$view->current = Mvc_Db::get_current_page();
unset($_GET['p']);
$view->current_url = PACKAGE_URL . '?' . http_build_query($_GET);
$view->render();
}
示例4: getKeys
public static function getKeys(RedBean_OODBBean $bean, $typeName)
{
$fieldName = self::getLinkField($typeName);
$id = (int) $bean->{$fieldName};
$ids = R::getCol("select id from {$typeName} where " . $bean->getMeta("type") . "_id" . " = {$bean->id}");
return $ids;
}
示例5: testFetchTypes
/**
* Tests the various ways to fetch (select queries)
* data using adapter methods in the facade.
* Also tests the new R::getAssocRow() method,
* as requested in issue #324.
*/
public function testFetchTypes()
{
R::nuke();
$page = R::dispense('page');
$page->a = 'a';
$page->b = 'b';
R::store($page);
$page = R::dispense('page');
$page->a = 'c';
$page->b = 'd';
R::store($page);
$expect = '[{"id":"1","a":"a","b":"b"},{"id":"2","a":"c","b":"d"}]';
asrt(json_encode(R::getAll('SELECT * FROM page')), $expect);
$expect = '{"1":"a","2":"c"}';
asrt(json_encode(R::getAssoc('SELECT id, a FROM page')), $expect);
asrt(json_encode(R::getAssoc('SELECT id, a, b FROM page')), $expect);
$expect = '[{"id":"1","a":"a"},{"id":"2","a":"c"}]';
asrt(json_encode(R::getAssocRow('SELECT id, a FROM page')), $expect);
$expect = '[{"id":"1","a":"a","b":"b"},{"id":"2","a":"c","b":"d"}]';
asrt(json_encode(R::getAssocRow('SELECT id, a, b FROM page')), $expect);
$expect = '{"id":"1","a":"a","b":"b"}';
asrt(json_encode(R::getRow('SELECT * FROM page WHERE id = 1')), $expect);
$expect = '"a"';
asrt(json_encode(R::getCell('SELECT a FROM page WHERE id = 1')), $expect);
$expect = '"b"';
asrt(json_encode(R::getCell('SELECT b FROM page WHERE id = 1')), $expect);
$expect = '"c"';
asrt(json_encode(R::getCell('SELECT a FROM page WHERE id = 2')), $expect);
$expect = '["a","c"]';
asrt(json_encode(R::getCol('SELECT a FROM page')), $expect);
$expect = '["b","d"]';
asrt(json_encode(R::getCol('SELECT b FROM page')), $expect);
}
示例6: getKeys
public static function getKeys(RedBean_OODBBean $bean, $typeName, $name = null)
{
$fieldName = self::getLinkField($typeName, $name);
$id = (int) $bean->{$fieldName};
$columnPrefix = self::resolveColumnPrefix($name);
$columnName = $columnPrefix . $bean->getMeta("type") . '_id';
$ids = R::getCol("select id from {$typeName} where " . $columnName . " = {$bean->id}");
return $ids;
}
示例7: getTailDistinctEventsByEventName
public static function getTailDistinctEventsByEventName($eventName, User $user, $count)
{
assert('is_string($eventName)');
assert('is_int($count)');
$sql = "select id\n from ( select id, modelclassname, modelid, datetime from auditevent where _user_id = {$user->id}\n AND eventname = '{$eventName}' order by id desc ) auditevent\n group by concat(modelclassname, modelid) order by datetime desc limit {$count}";
$ids = R::getCol($sql);
$beans = R::batch('auditevent', $ids);
return self::makeModels($beans, __CLASS__);
}
示例8: getAllTableNames
/**
* Returns an array of table names from the database.
*/
public static function getAllTableNames()
{
assert('RedBeanDatabase::isSetup()');
if (RedBeanDatabase::getDatabaseType() == 'sqlite') {
return R::getCol('select name from sqlite_master where type = \'table\' order by name;');
} elseif (RedBeanDatabase::getDatabaseType() == 'pgsql') {
return R::getCol("\n select relname from pg_catalog.pg_class\n left join pg_catalog.pg_namespace n on n.oid = pg_catalog.pg_class.relnamespace\n where pg_catalog.pg_class.relkind in ('r', '') and\n n.nspname <> 'pg_catalog' and\n n.nspname <> 'information_schema' and\n n.nspname !~ '^pg_toast' and\n pg_catalog.pg_table_is_visible(pg_catalog.pg_class.oid)\n order by lower(relname);\n ");
} else {
return R::getCol('show tables;');
}
}
示例9: getByLayoutIdAndUser
public static function getByLayoutIdAndUser($layoutId, $user)
{
assert('is_integer($layoutId) && $layoutId >= 1');
assert('$user instanceof User && $user->id > 0');
$sql = 'select dashboard.id id ' . 'from dashboard, ownedsecurableitem ' . 'where ownedsecurableitem.owner__user_id = ' . $user->id . ' and dashboard.ownedsecurableitem_id = ownedsecurableitem.id ' . ' and layoutid = ' . $layoutId . ' order by layoutId;';
$ids = R::getCol($sql);
assert('count($ids) <= 1');
if (count($ids) == 0) {
if ($layoutId == Dashboard::DEFAULT_USER_LAYOUT_ID) {
return Dashboard::setDefaultDashboardForUser($user);
}
throw new NotFoundException();
}
$bean = R::load(RedBeanModel::getTableName('Dashboard'), $ids[0]);
assert('$bean === false || $bean instanceof RedBean_OODBBean');
if ($bean === false) {
throw new NotFoundException();
}
return self::makeModel($bean);
}
示例10: generateCampaignItems
protected static function generateCampaignItems($campaign, $pageSize)
{
if ($pageSize == null) {
$pageSize = self::DEFAULT_CAMPAIGNITEMS_TO_CREATE_PAGE_SIZE;
}
$contacts = array();
$quote = DatabaseCompatibilityUtil::getQuote();
$sql = "select {$quote}marketinglistmember{$quote}.{$quote}contact_id{$quote} from {$quote}marketinglistmember{$quote}\n left join {$quote}campaignitem{$quote} on {$quote}campaignitem{$quote}.{$quote}contact_id{$quote} " . "= {$quote}marketinglistmember{$quote}.{$quote}contact_id{$quote} " . "AND {$quote}campaignitem{$quote}.{$quote}campaign_id{$quote} = " . $campaign->id . " where {$quote}marketinglistmember{$quote}.{$quote}marketinglist_id{$quote} = " . $campaign->marketingList->id . " and {$quote}campaignitem{$quote}.{$quote}id{$quote} IS NULL limit " . $pageSize;
$ids = R::getCol($sql);
foreach ($ids as $contactId) {
$contacts[] = Contact::getById((int) $contactId);
}
if (!empty($contacts)) {
//todo: if the return value is false, then we might need to catch that since it didn't go well.
CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts);
if (count($ids) < $pageSize) {
return true;
}
} else {
return true;
}
}
示例11: getSubset
/**
* Given a table name, count, and offset get an array of beans.
* @param string $tableName
* @param integer $count
* @param integer $offset
* @return array of RedBean_OODBBean beans.
*/
public static function getSubset($tableName, $where = null, $count = null, $offset = null)
{
assert('is_string($tableName)');
assert('$offset === null || is_integer($offset) && $offset >= 0');
assert('$offset === null || is_integer($count) && $count >= 1');
$sql = 'select id from ' . $tableName;
if ($where != null) {
$sql .= ' where ' . $where;
}
if ($count !== null) {
$sql .= " limit {$count}";
}
if ($offset !== null) {
$sql .= " offset {$offset}";
}
$ids = R::getCol($sql);
return R::batch($tableName, $ids);
}
示例12: getIndexes
/**
* Returns an array containing the index names of all
* indexes on the specified table name.
*
* @param $tableNoQ table name without quotes or backticks
*
* @return array
*/
function getIndexes($tableNoQ)
{
$writer = R::getWriter();
if ($writer instanceof \RedBeanPHP\QueryWriter\MySQL || $writer instanceof \RedBeanPHP\QueryWriter\CUBRID) {
$indexes = array();
$list = R::getAll("SHOW INDEX FROM `{$tableNoQ}`");
foreach ($list as $listItem) {
$indexes[] = $listItem['Key_name'];
}
return $indexes;
}
if ($writer instanceof \RedBeanPHP\QueryWriter\SQLiteT) {
$indexes = array();
$list = R::getAll(" pragma index_list(`{$tableNoQ}`) ");
foreach ($list as $listItem) {
$indexes[] = $listItem['name'];
}
return $indexes;
}
if ($writer instanceof \RedBeanPHP\QueryWriter\PostgreSQL) {
return R::getCol(" SELECT indexname FROM pg_indexes WHERE tablename = '{$tableNoQ}' AND schemaname = 'public' ");
}
return array();
}
示例13: countLines
/**
* Conta as linhas totais do SELECT
* @return int
*/
private function countLines()
{
$sqlCount = "SELECT COUNT(*) AS QNT FROM ({$this->sql}) AS TABLE";
return (int) \R::getCol($sqlCount);
}
示例14: store_in_session
// broadcast_action.php
include "config.php";
$target_usertype = null;
$message = null;
if (isset($_POST["target_usertype"])) {
$target_usertype = $_POST["target_usertype"];
}
if (isset($_POST["message"])) {
$message = $_POST["message"];
}
if ($message == null || $message == "") {
store_in_session("message", "You can't send an empty message");
header("Location: ./broadcast.php");
} else {
$data = R::getCol("select max(thread_id)+1 as new_thread_id from messages");
$thread_id = $data[0];
if (is_null($thread_id)) {
$thread_id = 1;
}
$sql = "insert into messages (from_id, to_id, message_sent_datetime, message_text, thread_id) values(0, ?,?,?,?)";
$param = 1;
$sql1 = "select id from users where 1=?";
if ($target_usertype != -1) {
$sql1 = "select id from users where usertype=?";
$param = $target_usertype;
}
$data = R::getAll($sql1, array($param));
foreach ($data as $value) {
R::exec($sql, array($value["id"], date("Y-m-d h:i:s"), $message, $thread_id++));
}
示例15: getSubsetIds
/**
* Gets a range of model ids from the database of the named model type.
* @param $modelClassName
* @param $joinTablesAdapter null or instance of joinTablesAdapter.
* @param $offset The zero based index of the first model to be returned.
* @param $count The number of models to be returned.
* @param $where
* @param $orderBy - sql string. Example 'a desc' or 'a.b desc'. Currently only supports non-related attributes
* @param $modelClassName Pass only when getting it at runtime gets the wrong name.
* @return An array of models ids
*/
public static function getSubsetIds(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter = null, $offset = null, $count = null, $where = null, $orderBy = null, $modelClassName = null, $selectDistinct = false)
{
assert('$offset === null || is_integer($offset) && $offset >= 0');
assert('$count === null || is_integer($count) && $count >= 1');
assert('$where === null || is_string ($where) && $where != ""');
assert('$orderBy === null || is_string ($orderBy) && $orderBy != ""');
assert('$modelClassName === null || is_string($modelClassName) && $modelClassName != ""');
if ($modelClassName === null) {
$modelClassName = get_called_class();
}
if ($joinTablesAdapter == null) {
$joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
}
$tableName = self::getTableName($modelClassName);
$sql = static::makeSubsetOrCountSqlQuery($tableName, $joinTablesAdapter, $offset, $count, $where, $orderBy, false, $selectDistinct);
$ids = R::getCol($sql);
return $ids;
}