Skip to content

Instantly share code, notes, and snippets.

View opotemkin's full-sized avatar
:octocat:
Working...

Oleg Potemkin opotemkin

:octocat:
Working...
View GitHub Profile
@opotemkin
opotemkin / ArrayDataProvider_sort
Created March 2, 2017 17:40
Yii2 new ArrayDataProvider + setSort
// first
$dataProvider = new ArrayDataProvider(['query' => $query]);
$dataProvider->setSort([
'attributes' => [
'time',
'total',
'average-price',
],
'defaultOrder' => ['time' => SORT_ASC]
]);
@opotemkin
opotemkin / str_pad
Created March 10, 2017 15:06
Create 0000001 from 1
$this->id = 1;
$id = str_pad($this->id, 6, '0', STR_PAD_LEFT);
echo $id; // 000001
@opotemkin
opotemkin / few COUNT in the sql
Created June 9, 2017 12:45
Несколько COUNT в одном SQL-запросе
Например, необходимо из таблицы заказов вытащить кол-во доступных текущих заказов, и кол-во заказов, доступных через час.
SELECT "queue".*, COUNT(DISTINCT "order1".id) as count, COUNT(DISTINCT "order2".id) as count_hour
FROM "queue"
LEFT JOIN "order" as "order1" ON "queue".id="order1".queue_id
LEFT JOIN "order" as "order2" ON "queue".id="order2".queue_id
WHERE (
("order1"."updated_at"<=:current_time AND "order1"."updated_at" IS NOT NULL)
OR "order1"."updated_at" IS NULL)
AND (
@opotemkin
opotemkin / create SqlDataProvider in the Yii2
Created June 9, 2017 12:48
create SqlDataProvider in the Yii2
// тек.время по дефолт.таймзоне с временем блокировки
$current_time = (new \DateTime())
->setTimezone(new \DateTimeZone(Timezone::DEFAULT_TIMEZONE))
->getTimestamp();
// Время через час
$current_time_hour = $current_time + 60*60;
$dataProvider = new SqlDataProvider([
'sql' => 'SELECT "queue".*, COUNT(DISTINCT "order1".id) as count, COUNT(DISTINCT "order2".id) as count_hour
// web_check.go
package main
import (
"flag"
"fmt"
"net/http"
"os"
"time"
)
@opotemkin
opotemkin / README.md
Created July 23, 2020 20:26
Update version with composer

composer require yiisoft/yii2 --update-with-all-dependencies