Skip to content

Instantly share code, notes, and snippets.

@webber12
webber12 / Helper.php
Last active February 12, 2024 10:16
Helper example
<?php
namespace EvolutionCMS\Main;
//положить файл в папку core/custom/packages/Main/src/
//для использования в любом другом месте добавить use EvolutionCMS\Main\Helper;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
<div class="row">
<div class="col-sm-12 col-md-5">
<div class="dataTables_info">Показано {{ $paginator->firstItem() }} - {{ $paginator->lastItem() }} из {{ $paginator->total() }}</div>
</div>
<div class="col-sm-12 col-md-7">
@if($paginator->hasPages())
<div class="dataTables_paginate paging_simple_numbers" >
<ul class="pagination">
@if(!$paginator->onFirstPage())
@webber12
webber12 / uploadFiles.js
Created November 24, 2022 17:12
Отправка файлов ajax
//<input type="file" data-upload-file>
//<input type="file" multiple data-upload-file>
//ловим в файле ajax.php $_FILES['files'] и $_POST['action'] == "uploadFiles"
$(document).on("change", "[data-upload-file]", function(e){
e.preventDefault();
const formData = new FormData();
formData.append("action", "uploadFiles");
for(let k = 0; k < e.target.files.length; k++) {
formData.append("files[" + k + "]", e.target.files[k]);
@webber12
webber12 / OrderWithProducts.php
Created November 14, 2022 17:48
Список заказов вместе с продуктами
protected function getOrderList()
{
$arr = [];
$currentUser = $this->data['user']['id'] ?? 0;
if(!empty($currentUser)) {
$arr = app('evouser')->do('OrderList', [ 'user' => $currentUser ]);
}
if(!empty($arr['data'])) {
//print_r($arr['data']);
@webber12
webber12 / Users_List_with_latest_item.php
Last active October 17, 2022 21:12
User List with latest item
model User
```
public function latestItem()
{
return $this->hasOne(Item::class)->latestOfMany();
}
```
model Item
```
//<?php
/**
* TagSaver
*
* @category plugin,DocLister
* @version 0.1
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
* @internal @properties &tv=ID TV-параметра;input; &tv_cats=ID категорий TV-параметров;input; &sep=Разделитель тегов;input;
* @internal @events OnDocFormSave
* @internal @modx_category Manager and Admin
<?php
$core = $modx;
if ( ! function_exists('getkey'))
{
/**
* Код MODX гавно, поэтому забываем про TypeHinting
* @param mixed $data
* @param string $key
* @param mixed $default null
* @return mixed