app.factory('goTo', ['$window', '$interval', '$location', '$anchorScroll', function($window: any, $interval: any, $location: any, $anchorScroll: any) {
return function(id: string, marginTop?: number, step?: number, seconds?: number): void {
marginTop = marginTop || 100;
step = step || 300;
seconds = seconds || 50;
var element: any = $window.document.getElementById(id);
if (null === element) {
return;
}
$location.hash(id);
var position: number = element.getBoundingClientRect().top,
before: number = 0,
current: number = $window.scrollY;
if (current > position) {
position += current;
var go = $interval(function(): void {
$window.scrollTo(0, current);
before = current;
current -= step;
if (position >= current || before === current) {
$anchorScroll();
$window.scrollTo(0, $window.scrollY - marginTop);
$interval.cancel(go);
}
}, seconds);
} else {
var go = $interval(function(): void {
$window.scrollTo(0, current);
before = current;
current += step;
if (position <= current || before === current) {
$anchorScroll();
$window.scrollTo(0, $window.scrollY - marginTop);
$interval.cancel(go);
}
}, seconds);
}
};
}]);
require_once __DIR__ . '/vendor/autoload.php';
function initializeSheets(){
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
$client = new Google_Client();
$client->setApplicationName("Google Sheets API PHP Quickstart");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/spreadsheets']);
return $client;
}
$sheets = new Google_Service_Sheets(initializeSheets());
//создаем саму таблицу
$sfsef = new Google_Service_Sheets_GridProperties();
$sfsef->setRowCount(8);
$sfsef->setColumnCount(5);
$sheet111 = new Google_Service_Sheets_SheetProperties();
$sheet111->setSheetType('GRID');
$sheet111->setSheetId(0);
$sheet111->setTitle('название листа');
$sheet111->setGridProperties($sfsef);
$sheet = new Google_Service_Sheets_Sheet();
$sheet->setProperties($sheet111);
$properties = new Google_Service_Sheets_SpreadsheetProperties();
$properties->setTitle('название документа');
$properties->setLocale('ru_RU');
$spreadsheets1 = new Google_Service_Sheets_Spreadsheet();
$spreadsheets1->setProperties($properties);
$spreadsheets1->setSheets($sheet);
$result = $sheets->spreadsheets->create( $spreadsheets1 ) ;
//даем доступ для редактирование кому угодно
$drive = new Google_Service_Drive(initializeSheets());
$drive1 = new Google_Service_Drive_Permission();
$drive1->setType('anyone');
$drive1->setRole('writer');
$drive1s = $result['spreadsheetId'];
$resultqqq = $drive->permissions->create( $drive1s, $drive1 ) ;
echo '<pre>';
print_r($result);
echo '</pre>';
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`type` enum('AUT','SUB') NOT NULL DEFAULT 'SUB',
PRIMARY KEY (`id`)
);
CREATE TABLE `subscription` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`author_id` int(11) NOT NULL COMMENT 'На кого подписываются',
`subscriber_id` int(11) NOT NULL COMMENT 'Кто подписывается',
`created_at` timestamp NOT NULL COMMENT 'Время подписки',
`expired_at` timestamp NOT NULL COMMENT 'Когда истекает подписка',
PRIMARY KEY (`id`)
);
# Пусть у нас есть один автор и два пользователя:
INSERT INTO `user` (`id`, `name`, `type`)
VALUES
(1, 'Alex Pushkin', 'AUT'),
(2, 'Vasya Pupkin', 'SUB'),
(3, 'Jane Doe', 'SUB');
# Один из них подписался на Автора месяцем ранее, второй недавно
INSERT INTO `subscription` (`author_id`, `subscriber_id`, `created_at`, `expired_at`)
VALUES
(1, 2, '2020-02-15 13:46:12', '2020-03-15 13:46:12'),
(1, 3, '2020-03-15 13:46:12', '2020-04-15 13:46:12');
SELECT *
FROM subscription
WHERE author_id = 1 and expired_at < CURRENT_TIMESTAMP and created_at < CURRENT_TIMESTAMP;
$txt = "Doctor";
$str_replsace = str_replace(" ", "+", $txt);
$content = file_get_contents("https://www.bbc.co.uk/search?q=$str_replsace");
preg_match_all('/<a [^>]+><span aria-hidden="false">([^<]+)<\/span><\/a>/im', $content, $matches);
$titles= array_unique($matches[1]);
//var_dump($titles);
foreach ($titles as $title) {
echo $title . PHP_EOL;
}
SELECT p.*,
case
when exists(SELECT 1 from cart c where c.products_id = p.id)
then 1
else 0
end is_exists_in_cart -- есть товар к корзине? 0 - нет, 1 - есть
FROM table_products p
SELECT p.*, c.*
FROM table_products p
left join cart c on c.products_id = p.id
SELECT с.*, p.*
FROM cart с
LEFT JOIN table_products p ON p.id = c.products_id
LIMIT 10000
SELECT с.*, p.*
переписать, указав конкретные столбцы, иначе будет неопределённость.