use Bitrix\Main\Mail;
/**
* Get from b_event table
* @var integer Existed event id
*/
$displayedEventId = 336020;
/**
* List of site ids, for event theme generation
* must be replaced by current site id in public
* @var array
*/
$arSites = [
's1'
];
try
{
/**
* First, try to find event
*/
$arEvent = Mail\Internal\EventTable::getRow([
'filter' => [
'=ID' => $displayedEventId,
]
]);
if ( !$arEvent )
{
throw new \Exception('Event not found');
}
$arEvent['FIELDS'] = $arEvent['C_FIELDS'];
/**
* Try to find all message templates for
* sites. In event handler we send for one letter
* per site.
*/
$arEventMessageFilter = [
'=ACTIVE' => 'Y',
'=EVENT_NAME' => $arEvent["EVENT_NAME"],
'=EVENT_MESSAGE_SITE.SITE_ID' => $arSites,
];
$messageDb = Mail\Internal\EventMessageTable::getList([
'select' => ['ID'],
'filter' => $arEventMessageFilter,
'group' => ['ID']
]);
foreach ($messageDb as $arMessage)
{
$eventMessage = Mail\Internal\EventMessageTable::getRowById($arMessage['ID']);
$eventMessage['FILES'] = array();
$attachmentDb = Mail\Internal\EventMessageAttachmentTable::getList(array(
'select' => array('FILE_ID'),
'filter' => array('=EVENT_MESSAGE_ID' => $arMessage['ID']),
));
while($arAttachmentDb = $attachmentDb->fetch())
{
$eventMessage['FILE'][] = $arAttachmentDb['FILE_ID'];
}
$arFields = $arEvent['FIELDS'];
// get message object for send mail
$arMessageParams = array(
'EVENT' => $arEvent,
'FIELDS' => $arFields,
'MESSAGE' => $eventMessage,
'SITE' => $arSites,
'CHARSET' => $charset,
);
$message = Mail\EventMessageCompiler::createInstance($arMessageParams);
$message->compile();
echo $message->getMailBody();
}
}
catch( \Exception $e )
{
var_dump($e);
}
$data = [
[
'name' => 'Москва и Московская обл.',
'items' => ['Москва', 'Абрамцево']
],
[
'name' => 'Санкт-Петербург',
'items' => ['Санкт-Петербург', 'Александровская']
]
];
class Location
{
private $data;
/**
* Location constructor.
*
* @param array $data
*/
function __construct($data = [])
{
$this->data = $data;
}
/**
* Get cities by region
*
* @param string $region
*
* @return array
*/
public function getCitiesByRegion($region)
{
$key = array_search($region, array_column($this->data, 'region'));
if ( $key === false ) return false;
return $this->data[$key]['items'];
}
}
$data = [
[
'region' => 'Москва и Московская обл.',
'items' => ['Москва', 'Абрамцево']
],
[
'region' => 'Санкт-Петербург',
'items' => ['Санкт-Петербург', 'Александровская']
]
];
$location = new Location($data);
print_r($location->getCitiesByRegion('Санкт-Петербург'));
php artisan make:model Localization
protected $table = 'localization';
public function lozalizable()
{
return $this->morphTo();
}
public function lozalization(){
return $this->morphOne('App\Localization', 'lozalizable');
}
Schema::create('localization', function (Blueprint $table) {
$table->increments('id');
$table->string('field');
$table->string('language');
$table->string('value');
$table->string('lozalizable_type');
$table->integer('lozalizable_id');
$table->timestamps();
});
$article = Article::create($Atricle);
$localization = new Localization;
$localization->language = 'en';
$localization->field = 'content';
$localization->value = 'Znachenye na english yazike';
$article->localization()->save($localization); //привязываем к свежесозданному объекту Article новую локализацию
public function scopeGetLocalize($language, $field){
return $this->localization()->where(['language' => $language, 'field' => $field])-> firstOrFail()->value;
}
$article->getLocalize('en', 'title')
php artisan cache:clear
chmod -R 777 app/storage
php artisan dump-autoload
Я намереваюсь изучить Ruby on Rails ,но толковых видео-курсов в гугле не нашел(Их вообще нет).