/** * @param int $parentId Id сущности, к которой привязаны изображения * @param int $parentType тип сущности, к которой привязаны изображения. Если не задано - определяется по классу объекта $this * @return array[][] Метаданные изображений в виде массива. Первый индекс - изображение, второй ассоциативный - поле изображения */ protected function getPackedImages($parentId, $parentType = 0) { if (empty($parentType)) { switch (true) { case $this instanceof \Maradik\Hinter\Api\SecondQuestionCollection: case $this instanceof \Maradik\Hinter\Api\SecondQuestionDocument: $parentType = FileParentType::SECOND_QUESTION; break; case $this instanceof \Maradik\Hinter\Api\SecondAnswerCollection: case $this instanceof \Maradik\Hinter\Api\SecondAnswerDocument: $parentType = FileParentType::SECOND_ANSWER; break; case $this instanceof \Maradik\Hinter\Api\MainQuestionCollection: case $this instanceof \Maradik\Hinter\Api\MainQuestionDocument: case $this instanceof \Maradik\Hinter\Api\MainQuestionController: $parentType = FileParentType::MAIN_QUESTION; break; case $this instanceof \Maradik\Hinter\Api\MainAnswerCollection: case $this instanceof \Maradik\Hinter\Api\MainAnswerDocument: $parentType = FileParentType::MAIN_ANSWER; break; } } if (empty($parentType)) { return array(); } $images = $this->repositoryFactory->getFileRepository()->query()->addFilterField('parentType', $parentType)->addFilterField('parentId', $parentId)->addFilterField('type', FileData::TYPE_IMAGE)->getEntity(); return array_map(function ($image) { return ImageDocument::packImage($image); }, $images); }
<?php require_once __DIR__ . '/settings.php'; require_once __DIR__ . '/vendor/autoload.php'; use Maradik\User\UserCurrent; use Maradik\User\UserRepository; use Maradik\Hinter\Core\RepositoryFactory; use Maradik\Hinter\Core\Params; $db = new PDO("{$database_s['driver']}:host={$database_s['host']};dbname={$database_s['database']};charset=UTF8", $database_s['username'], $database_s['password']); $user = new UserCurrent(new UserRepository($db, $table_s['user'], $database_s['prefix']), $general_s['enctryptsalt']); $user->init(); $repositoryFactory = new RepositoryFactory($db, $database_s['prefix'], $table_s['category'], $table_s['mainquestion'], $table_s['mainanswer'], $table_s['secondquestion'], $table_s['secondanswer'], $table_s['relationanswers'], $table_s['param'], $table_s['file'], $general_s['upload_dir']); Params::setRepository($repositoryFactory->getParamRepository());