本文整理汇总了PHP中array_column函数的典型用法代码示例。如果您正苦于以下问题:PHP array_column函数的具体用法?PHP array_column怎么用?PHP array_column使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_column函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateSetting
/**
* update settings
*/
public static function updateSetting()
{
$s = [['key' => 'title', 'value' => 'Yii2 Skeleton', 'title' => 'Title', 'description' => 'Homepage title', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2 Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'keywords', 'value' => 'Yii2, Skeleton', 'title' => 'Keywords', 'description' => 'Homepage keywords', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2, Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'description', 'value' => 'Skeleton for Yii Framework', 'title' => 'Description', 'description' => 'Homepage description', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Skeleton for Yii Framework', 'rules' => json_encode(['required' => []])], ['key' => 'language', 'value' => 'en-US', 'title' => 'Language', 'description' => 'Site language', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{LOCALE}', 'default' => 'en-US', 'rules' => json_encode(['required' => []])], ['key' => 'timezone', 'value' => 'Asia/Ho_Chi_Minh', 'title' => 'Timezone', 'description' => 'Server Timezone', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{TIMEZONE}', 'default' => 'Asia/Ho_Chi_Minh', 'rules' => json_encode(['required' => []])], ['key' => 'maxNameChange', 'value' => '1', 'title' => 'Max Name Change', 'description' => 'Max name change allowed', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '1', 'rules' => json_encode(['required' => [], 'number' => ['min' => -1]])], ['key' => 'tokenExpiryTime', 'value' => '3600', 'title' => 'Token Expiry Time', 'description' => 'Expiration time in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '3600', 'rules' => json_encode(['required' => [], 'number' => ['min' => 3600]])], ['key' => 'rememberMeDuration', 'value' => '2592000', 'title' => 'Remember Me Duration', 'description' => 'Customize the duration of the Remember Me in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '2592000', 'rules' => json_encode(['required' => [], 'number' => ['min' => 86400]])], ['key' => 'blogTitle', 'value' => 'My Blog', 'title' => 'Title', 'description' => 'Blog page title', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'My Blog', 'rules' => json_encode(['required' => []])], ['key' => 'blogDesc', 'value' => 'Welcome to my world.', 'title' => 'Description', 'description' => 'Blog page description', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'Welcome to my world.', 'rules' => json_encode(['required' => []])], ['key' => 'blogKeywords', 'value' => 'blog, my blog', 'title' => 'Keywords', 'description' => 'Blog page keywords', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'blog, my blog', 'rules' => json_encode(['required' => []])], ['key' => 'blogThumbnail', 'value' => '', 'title' => 'Thumbnail Image', 'description' => 'Blog page thumbnail', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => '', 'rules' => json_encode(['url' => []])], ['key' => 'outgoingMail', 'value' => 'youremail@domain.com', 'title' => 'Outgoing Mail', 'description' => 'Outgoing email address', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['required' => [], 'email' => []])], ['key' => 'mailProtocol', 'value' => 'php', 'title' => 'Mail Protocol', 'description' => 'Outgoing email protocol', 'group' => 'Mail', 'type' => 'dropDownList', 'data' => json_encode(['php' => 'php', 'smtp' => 'smtp']), 'default' => 'php', 'rules' => json_encode(['required' => []])], ['key' => 'smtpHost', 'value' => '', 'title' => 'SMTP Host', 'description' => 'SMTP host', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpUsername', 'value' => '', 'title' => 'SMTP Username', 'description' => 'SMTP username', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpPassword', 'value' => '', 'title' => 'SMTP Password', 'description' => 'SMTP password', 'group' => 'Mail', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpPort', 'value' => '', 'title' => 'SMTP Port', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '25', 'rules' => json_encode(['safe' => [], 'number' => []])], ['key' => 'smtpEncryption', 'value' => '', 'title' => 'SMTP Encryption', 'description' => 'SMTP Encryption', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => 'ssl', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'fbPageUrl', 'value' => '', 'title' => 'Facebook Page URL', 'description' => 'Facebook Page URL', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'url' => []])], ['key' => 'fbAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'fbAdmins', 'value' => '', 'title' => 'Facebook Admins', 'description' => 'Facebook Admins ID', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'gpPageUrl', 'value' => '', 'title' => 'Google+ Page URL', 'description' => 'Google+ Page URL', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'url' => []])], ['key' => 'twitterSite', 'value' => '', 'title' => 'Twitter Card Site', 'description' => '@username for the website used', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'reCaptchaKey', 'value' => '', 'title' => 'reCaptcha Site Key', 'description' => 'reCaptcha Site Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'reCaptchaSecret', 'value' => '', 'title' => 'reCaptcha Secret', 'description' => 'reCaptcha Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'facebookAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'facebookAppSecret', 'value' => '', 'title' => 'Facebook App Secret', 'description' => 'Facebook App Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleClientId', 'value' => '', 'title' => 'Google Client ID', 'description' => 'Google Client ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleClientSecret', 'value' => '', 'title' => 'Google Client Secret', 'description' => 'Google Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'flickrClientKey', 'value' => '', 'title' => 'Flickr Client Key', 'description' => 'Flickr Client Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'flickrClientSecret', 'value' => '', 'title' => 'Flickr Client Secret', 'description' => 'Flickr Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'androidThemeColor', 'value' => '#3c8dbc', 'title' => 'Android Theme Color', 'description' => 'Android theme color', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'msTileColor', 'value' => '#3c8dbc', 'title' => 'MS Tile Color', 'description' => 'Background color for a live tile', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'safariMaskColor', 'value' => '#3c8dbc', 'title' => 'Safari Mask Color', 'description' => 'Safari pinned tab color', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleCustomSearch', 'value' => '', 'title' => 'Google Custom Search', 'description' => 'CX code: 123456789012345678901:abcdefjh123', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleAnalytics', 'value' => '', 'title' => 'Google Analytics', 'description' => 'Tracking ID: UA-1111111-22', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'disqus', 'value' => '', 'title' => 'Disqus', 'description' => 'Disqus shortname', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'zopim', 'value' => '', 'title' => 'Zopim Chat', 'description' => 'Zopim ID: 5d8f1e3c8f77c45608ada76d51256aad', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'addthis', 'value' => '', 'title' => 'Addthis', 'description' => 'Addthis ID: ra-123a1234567890b1', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'headJs', 'value' => '', 'title' => 'Header JS', 'description' => 'Header Javascript', 'group' => 'Enhancements', 'type' => 'textarea', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'adsense', 'value' => '', 'title' => 'Google Adsense', 'description' => 'Client ID: ca-pub-1234567890123456', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzTracking', 'value' => '', 'title' => 'Amazon Tracking ID', 'description' => 'Tracking ID: yourname-11', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzAds', 'value' => '', 'title' => 'Amazon Native Ads', 'description' => 'Ad Instance ID: 12abc1ab-ab12-1234-a123-1abcd123456a', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzSearchAds', 'value' => '', 'title' => 'Amazon Search Ads', 'description' => 'Link ID: 12abc1ab-ab12-1234-a123-1abcd123456a', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'languageUrlCode', 'value' => '0', 'title' => 'Language URL', 'description' => 'Include language code in URL', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])], ['key' => 'debug', 'value' => '0', 'title' => 'Debug Mode', 'description' => 'Turn debug mode ON/OFF', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])]];
/* delete old settings */
$settings = Setting::find()->all();
foreach ($settings as $setting) {
if (!in_array($setting->key, array_column($s, 'key'))) {
$setting->delete();
}
}
/* sync */
foreach ($s as $i => $setting) {
$conf = Setting::findOne($setting['key']);
if (!$conf) {
$conf = new Setting();
$conf->key = $setting['key'];
$conf->value = $setting['value'];
}
$conf->title = $setting['title'];
$conf->description = $setting['description'];
$conf->group = $setting['group'];
$conf->type = $setting['type'];
$conf->data = $setting['data'];
$conf->default = $setting['default'];
$conf->rules = $setting['rules'];
$conf->key_order = $i;
$conf->save();
}
}
示例2: informNotifications
/**
* Grabs all new notifications and adds them to the sender's inform queue.
*
* This method gets called by dashboard's hooks file to display new
* notifications on every pageload.
*
* @since 2.0.18
* @access public
*
* @param Gdn_Controller $Sender The object calling this method.
*/
public static function informNotifications($Sender)
{
$Session = Gdn::session();
if (!$Session->isValid()) {
return;
}
$ActivityModel = new ActivityModel();
// Get five pending notifications.
$Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
// If we're in the middle of a visit only get very recent notifications.
$Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
$Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray();
$ActivityIDs = array_column($Activities, 'ActivityID');
$ActivityModel->setNotified($ActivityIDs);
$Sender->EventArguments['Activities'] =& $Activities;
$Sender->fireEvent('InformNotifications');
foreach ($Activities as $Activity) {
if ($Activity['Photo']) {
$UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
} else {
$UserPhoto = '';
}
$Excerpt = Gdn_Format::plainText($Activity['Story']);
$ActivityClass = ' Activity-' . $Activity['ActivityType'];
$Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
}
}
示例3: __construct
public function __construct(array $outputs, $confirms = 1)
{
$this->data = $outputs;
$this->minimumConfirms = $confirms;
$this->total = count($outputs);
// do calculation only if at least 1 output
if ($this->total > 0) {
$amounts = array_column($outputs, 'amount');
$this->amountsSum = array_sum($amounts);
$amountPairs = [];
foreach ($amounts as $amount) {
$amount = (string) $amount;
// cast float to string, because array_key_exists can handle only string or integer
// if key exists, then add +1 to value that means that amount already was counted
if (array_key_exists($amount, $amountPairs)) {
$amountPairs[$amount] = $amountPairs[$amount] + 1;
} else {
// new result, just add initial 1
$amountPairs[$amount] = 1;
}
}
$this->amountPairs = $amountPairs;
ksort($this->amountPairs);
// sort incrementing by amount
}
}
示例4: defaultAction
public function defaultAction()
{
$pageSize = 20;
// 获取参数
$page = Pager::get();
$title = Request::getGET('title');
$status = (int) Request::getGET('status');
// 构建where
$where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1));
if (!empty($status) && $status != -1) {
$where[] = array('hidden', '=', $status - 1);
}
if (!empty($title)) {
$where[] = array('title', 'LIKE', "%{$title}%");
}
// 获取数据
$offset = ($page - 1) * $pageSize;
$contestList = OjContestInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
$allCount = 0;
if (!empty($contestList)) {
$allCount = OjContestInterface::getCount($where);
}
$userIds = array_unique(array_column($contestList, 'user_id'));
$userHash = UserCommonInterface::getById(array('id' => $userIds));
// 缓存部分的html
$html = array();
$html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
// 输出
$this->renderFramework(array('contestList' => $contestList, 'userHash' => $userHash, 'html' => $html), 'setup/contest/list.php');
}
示例5: Moodle_GetUserId
function Moodle_GetUserId($usert)
{
/**
* Returns the moodle id of the username $usert
* @author Germán Sánchez (GREC-ESADE), Collage
* @version 24.04.2014
*/
global $debugar;
$moodleUsers = Moodle_GetUsersList();
$moodleUsers = objectToArray($moodleUsers);
// $moodleUsers es un array con 'users, que es otro array:
// [0][1]... con [id] y [username]
//echo '<pre>'.print_r($moodleUsers['users'], TRUE).'</pre>';
$key = array_search($usert, array_column($moodleUsers['users'], 'username'));
if ($debugar) {
echo '<h1>key = ' . $key . '</h1>';
}
if ($key != NULL) {
$userid = $moodleUsers['users'][$key]['id'];
} else {
$userid = NULL;
}
if ($debugar) {
echo '<h1>userid = ' . $userid . '</h1>';
}
if ($debugar) {
echo '<pre>' . print_r($moodleUsers['users'], TRUE) . '</pre>';
}
return $userid;
}
示例6: login
/**
* 登陆
*/
public function login()
{
if (IS_POST) {
//登陆验证
if ($this->model->create() !== false) {
if (($result = $this->model->login(I('post.'))) !== false) {
//是否记住密码
$remember = false;
if (I('post.remember')) {
$remember = true;
}
//保存用户登录
login($result['userinfo'], $remember);
//保存用户权限ids和urls
$permissions = $result['permissions'];
permissionId(array_column($permissions, 'id'));
permissionURL(array_column($permissions, 'url'));
//跳转后台首页
$this->success('登陆成功', U('Index/index'));
return;
}
}
$this->error(show_model_error($this->model), U('login'));
} else {
//登陆表单
$this->display('login');
}
}
示例7: findEventsByType
public function findEventsByType($logTypeID)
{
return $this->cache->load('logEvents-' . $logTypeID, function (&$dependencies) use($logTypeID) {
return array_column($this->em->createQuery('SELECT e.id, e.name FROM ' . EventLog::class . ' e INDEX BY e.id
WHERE e.logType = :typeID')->setParameter('typeID', $logTypeID)->getArrayResult(), 'name', 'id');
});
}
示例8: parse
public function parse(\SplFileInfo $file, string $filename = null, string $title = null) : Dictionary
{
$dictionary = new Dictionary();
if (!$file instanceof \SplFileObject) {
$file = $file->openFile();
} else {
$file->rewind();
}
$file->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
foreach ($file as $line) {
$this->parseLine($dictionary, $line);
}
$this->wholeText .= implode('', array_column(array_column($dictionary->getWords(), 'text'), 0));
if ($this->wholeText === '') {
throw new SyntaxException(_('制御文字や空白文字のみで構成された辞書は変換できません。'));
}
$regard = $this->generateRegard();
if ($regard) {
$metaFields['@regard'] = $this->generateRegard();
}
if (!is_null($title)) {
$metaFields['@title'] = $title;
} elseif (!is_null($filename)) {
$titleFromFilename = $this->getTitleFromFilename($filename);
if ($titleFromFilename) {
$metaFields['@title'] = $titleFromFilename;
}
}
if (isset($metaFields)) {
$dictionary->setMetadata($metaFields);
}
return $dictionary;
}
示例9: get_user_tokens
public function get_user_tokens($user_id)
{
$ar = ['users_id' => $user_id];
$this->db->select('token');
$res = $this->db->get_where($this->table, $ar)->result_array();
return array_column($res, 'token');
}
示例10: draw
public function draw()
{
$temp = "";
$host = $this->parameters["app"]->server["HTTP_HOST"];
$uri = $this->parameters["app"]->server["REQUEST_URI"];
$actualLink = "http://{$host}{$uri}";
$relative = $this->parameters["app"]->server["RELATIVE"];
foreach ($this->tags["menu"] as $i) {
$prePath = "";
if ($i["relative"]) {
$prePath = $relative;
}
$active = $this->isSubString($actualLink, array_merge(array_column($i["submenu"], 'link'), array($i["link"]))) ? "active" : "";
if (is_array($i["submenu"]) && count($i["submenu"]) < 1) {
$temp .= "<li class='{$active}'><a href='{$prePath}{$i['link']}'>{$i['label']}</a></li>";
} else {
$temp .= "<li class='dropdown {$active}'>";
$temp .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">' . $i["label"] . '<span class="caret"></span>' . '</a>' . '<ul class="dropdown-menu">';
foreach ($i["submenu"] as $j) {
$prePath = "";
if ($j["relative"]) {
$prePath = $relative;
}
$temp .= "<li><a href='{$prePath}{$j['link']}'>{$j['label']}</a></li>";
}
$temp .= "</ul></li>";
}
}
return $temp;
}
示例11: toString
public function toString($startCountAt = 0)
{
foreach ($this->myArray[0] as $key => $value) {
$this->array_columns[$key] = array_column($this->myArray, $key);
}
$output = '';
$maxColWidths = $this->calculateMaxWidths($this->array_columns, $startCountAt);
$output .= sprintf("%{$maxColWidths['row_num_col']}s%s", "", $this->rowNumbersColSep);
$headerKeys = array_keys($this->array_columns);
foreach ($headerKeys as $heading) {
$headingFormat = "%-{$maxColWidths[$heading]}s{$this->cellSep}";
$output .= sprintf($headingFormat, $heading);
}
$output .= "\n";
foreach ($maxColWidths as $maxColWidth) {
$output .= sprintf("%{$maxColWidth}s%s", str_repeat($this->headerSep, $maxColWidth), $this->cellSep);
}
$output .= "\n";
for ($row = 0, $maxRows = count(array_values($this->array_columns)[0]); $row < $maxRows; $row++) {
$output .= sprintf("%{$maxColWidths['row_num_col']}d%s", $startCountAt, $this->rowNumbersColSep);
$keysCount = 0;
foreach (array_values($this->array_columns) as $data) {
$maxDataWidth = $maxColWidths[$headerKeys[$keysCount]];
$output .= sprintf("%-{$maxDataWidth}s%s", $data[$row], $this->cellSep);
$keysCount += 1;
}
$startCountAt += 1;
$output .= "\n";
foreach ($maxColWidths as $maxColWidth) {
$output .= sprintf("%{$maxColWidth}s%s", str_repeat($this->headerSep, $maxColWidth), $this->cellSep);
}
$output .= "\n";
}
return $output;
}
示例12: config
/**
* set or get a company config value
* json_decode/encode automatically
* @param string $key
* @param mixed $value
* @return
* get: the config value, false if not found
* set: the insert or update query
*/
function config($key = null, $value = null)
{
$db = $this->load->database('', true);
if (is_null($key)) {
$result = $db->select('id, key, value')->from('company_config')->where('company', $this->id)->get()->result_array();
return array_column($result, 'value', 'key');
}
$row = $db->select('id,value')->from('company_config')->where('company', $this->id)->where('key', $key)->get()->row();
if (is_null($value)) {
if ($row) {
$json_value = json_decode($row->value);
if (is_null($json_value)) {
return $row->value;
} else {
return $json_value;
}
} else {
return;
}
} else {
if (is_array($value)) {
$value = json_encode($value);
}
return $db->upsert('company_config', array('value' => $value, 'id' => $row->id));
}
}
示例13: __construct
public function __construct($data = array())
{
parent::__construct($data);
$this->setPropertiesDefine(array('parent_id' => array('alias' => '上级部门', 'options' => function () {
$data = Department::find()->field('id', 'parent_id', 'name')->all(true);
$tmp = array_combine(array_column($data, 'id'), array_column($data, 'name'));
array_unshift_assoc($tmp, 0, '顶级');
return $tmp;
}, 'form' => function ($val = null, self $instance = null) {
$data = Department::find()->field('id', 'parent_id', 'name')->all(true);
return ViewBase::generateParentTreeSelector($data, $instance);
}), 'manager_id' => array('alias' => '负责人', 'options' => function () {
$data = User::find('state=?', User::STATE_ENABLED)->field('id', 'name')->all(true);
return array_combine(array_column($data, 'id'), array_column($data, 'name'));
}, 'display' => function (self $item) {
$tmp = User::findOneByPk($item->manager_id);
if (!$tmp) {
return '';
}
return $tmp->state == User::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>';
}), 'stage_id' => array('options' => function () {
return WorkStage::$work_stage_list;
}), 'stage_name' => array('getter' => function ($item) {
if ($item->stage_id) {
return WorkStage::$work_stage_list[$item->stage_id];
}
return '';
}, 'alias' => '负责流程')));
}
示例14: __construct
public function __construct()
{
global $CFG_GLPI, $DB;
// construct api url
self::$api_url = trim($CFG_GLPI['url_base_api'], "/");
// Don't display error in result
set_error_handler(array('Toolbox', 'userErrorHandlerNormal'));
ini_set('display_errors', 'Off');
// Avoid keeping messages between api calls
$_SESSION["MESSAGE_AFTER_REDIRECT"] = '';
// check if api is enabled
if (!$CFG_GLPI['enable_api']) {
$this->returnError(__("API disabled"), "", "", false);
exit;
}
// retrieve ip of client
$this->iptxt = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$this->ipnum = strstr($this->iptxt, ':') === false ? ip2long($this->iptxt) : '';
// check ip access
$apiclient = new APIClient();
$where_ip = "";
if ($this->ipnum) {
$where_ip .= " AND (`ipv4_range_start` IS NULL\n OR (`ipv4_range_start` <= '{$this->ipnum}'\n AND `ipv4_range_end` >= '{$this->ipnum}'))";
} else {
$where_ip .= " AND (`ipv6` IS NULL\n OR `ipv6` = '" . $DB->escape($this->iptxt) . "')";
}
$found_clients = $apiclient->find("`is_active` = '1' {$where_ip}");
if (count($found_clients) <= 0) {
$this->returnError(__("There isn't an active api client matching your ip adress in the configuration") . " (" . $this->iptxt . ")", "", "ERROR_NOT_ALLOWED_IP", false);
}
$app_tokens = array_column($found_clients, 'app_token');
$apiclients_id = array_column($found_clients, 'id');
$this->app_tokens = array_combine($apiclients_id, $app_tokens);
}
示例15: edit
/**
* renders the edit form and calls the createProccess
* method located in the main Controller class in order to update
* the database data
*/
public function edit()
{
$id = empty($this->urlParams['q1']) ? 1 : $this->urlParams['q1'];
$cnl = $this->model->get($id);
if (false === $cnl) {
// not found
$this->app->flashNow('errors', $this->classMessages['not_found']);
}
$allCats = $this->model->getCats();
$cnlCats = $this->model->getAssosCats($id);
/* check the checkboxes if the categories belong to our channel */
foreach ($allCats as $key => $value) {
if (false !== array_search($value['title'], array_column($cnlCats, 'title'))) {
$allCats[$key]['checked'] = true;
}
}
$post = $this->app->request->post();
if (isset($post['submit'])) {
$createProccess = $this->createProccess($post, $this->reqFields, 'update', $cnl);
if (true === $createProccess['success']) {
$this->app->flash('success', $createProccess['message']);
$this->redirectInAdmin($this->type);
} else {
$this->app->flashNow('errors', $createProccess['message']);
}
}
$this->app->render($this->getView(), array('cats' => $allCats, 'cnl' => $cnl));
}