Skip to content

Instantly share code, notes, and snippets.

View KrotovRoman's full-sized avatar

Кротов Роман KrotovRoman

  • Krotov Roman
  • Russia
View GitHub Profile
@KrotovRoman
KrotovRoman / 1
Created December 6, 2018 05:00
проверить является ли строка URL
if (filter_var($data_text, FILTER_VALIDATE_URL) === FALSE) {
echo "no";
}
@KrotovRoman
KrotovRoman / 1
Created December 4, 2018 05:06
поделиться ссылкой в телеграм
$button = [];
$button['text'] = stripcslashes("Рассказать друзьям Telegram");
$button['switch_inline_query'] = $url;
$keyboard[] = array($button);
@KrotovRoman
KrotovRoman / curl
Created November 13, 2018 06:28
examples https://github.com/philsturgeon/codeigniter-curl пример запроса с параметрами в заголовке
$url = "http://test.ru/;
$this->curl->create($url);
$this->curl->option(CURLOPT_HTTPHEADER, ['Content-Type: application/json' , "Authorization: Bearer ".$this->api_eth ]);
$this->curl->get();
$result = $this->curl->execute();
$result = json_decode($result);
if (!$result AND $this->curl->error_code > 0) {
@KrotovRoman
KrotovRoman / checkbox
Created October 31, 2018 05:43
чекбокс checkbox
<div class="form-group">
<label>
<input type="checkbox" name="inp" class="minimal">
Minimal skin checkbox
</label>
</div>
@KrotovRoman
KrotovRoman / form
Created September 28, 2018 06:23
проверка данных по шаблону внутри бота без визуального вывода ошибки
//проверить
$rules['rules'] = 'required|trim|alpha_numeric|min_length[3]';
$rules['field'] = 'alias';
$rules['label'] = 'код мероприятия';
//@dosc https://www.codeigniter.com/userguide3/libraries/form_validation.html
$this->form_validation->set_data(['alias' => $alias]);
$this->form_validation->set_rules([$rules]);
if (!$this->form_validation->run()) {
<?php
class MY_Form_validation extends CI_Form_validation {
function run($module = '', $group = '') {
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
@KrotovRoman
KrotovRoman / 1
Created June 26, 2018 11:11
подсчитать за какой файл больше всего проголосовали
public function get_winner_opros($id_opros) {
$this->db->limit(1);
$this->db->select('id_file, count(*) as count');
$this->db->group_by('id_file');
$this->db->order_by('count', 'desc');
$this->db->where('id_opros', $id_opros);
$files_votes = $this->db->get('files_votes');
if ($files_votes->num_rows() <= 0) {
return FALSE;
}
/*
* Экспортировать выплаты сотрудникам в EXCEL
*/
public function export_pays_xls($pays) {
if ($pays->num_rows() <= 0) {
return FALSE;
}
$this->load->model("Lead_model");
@KrotovRoman
KrotovRoman / dsf
Created March 14, 2018 16:36
Посчитать расстояние между двумя точками в координатах координаты
/*
* Посчитать расстояние между двумя точками в координатах
* @src http://dmitry.im/mysql-dist/
* @example
* $lat1 = 55.130974;
$lon1 = 61.420328;
$lat2 = 55.130682;
$lon2 = 61.421776;
$res = $this->getDistance($lat1, $lon1, $lat2, $lon2);
@KrotovRoman
KrotovRoman / sdsdf
Last active November 29, 2018 03:17
сортировка многомерного массива
//$res - массив который надо отсортировать по полю in_group
//по возрастанию
usort($res, function($a, $b){
return ($a['in_group'] - $b['in_group']);
});
//по убыванию
usort($res, function($a, $b){
return ($b['in_group'] - $a['in_group']);