Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
album.php
1<?php
2
4
7
14class Album extends DataConverter
15{
16 const TITLE_LENGHT_MAX = 128;
17 private $result;
18
24 public function __construct($exportId)
25 {
26 if (!isset($exportId) || $exportId == '')
27 throw new ArgumentNullException("EXPORT_ID");
28
29 $this->exportId = $exportId;
30 }
31
32
39 public function convert($data)
40 {
41 $this->result = array();
42 $logger = new Vk\Logger($this->exportId);
43 if ($data["ELEMENT_CNT"] == 0)
44 $logger->addError("ALBUM_EMPTY", $data["ID"]);
45
46 $this->result["SECTION_ID"] = $data["ID"];
47 $this->result["IBLOCK_ID"] = $data["IBLOCK_ID"];
48 $this->result["TITLE"] = $data["TO_ALBUM_ALIAS"] ? $data["TO_ALBUM_ALIAS"] : $data["NAME"];
49 $this->result["TITLE"] = $this->validateTitle($this->result['TITLE'], $logger);
50 $this->result["TITLE"] = self::convertToUtf8($this->result["TITLE"]);
51// add only checked photos
52 $sortedPhotos = Vk\PhotoResizer::sortPhotoArray(
53 array($data["PICTURE"], $data["DETAIL_PICTURE"]),
54 'ALBUM'
55 );
56 $checkedPhotos = Vk\PhotoResizer::checkPhotos($sortedPhotos, 'ALBUM');
57 if ($checkedPhotos)
58 foreach ($checkedPhotos["PHOTOS"] as $photo)
59 {
60 $this->result["PHOTO_BX_ID"] = $photo["PHOTO_BX_ID"];
61 $this->result["PHOTO_URL"] = $photo["PHOTO_URL"];
62 }
63 else
64 $logger->addError("ALBUM_EMPTY_PHOTOS", $data["ID"]);
65
66// add item to log, if image was be resized
67 if ($checkedPhotos['RESIZE'])
68 $logger->addError('ALBUM_PHOTOS_'.$checkedPhotos['RESIZE_TYPE'], $data["ID"]);
69
70 return array($data["ID"] => $this->result);
71 }
72
73
81 private function validateTitle($title, Vk\Logger $logger = NULL)
82 {
83 $newTitle = $title;
84
85 if (mb_strlen($title) > self::TITLE_LENGHT_MAX)
86 {
87 $newTitle = mb_substr($title, 0, self::TITLE_LENGHT_MAX - 1);
88 if ($logger)
89 $logger->addError('ALBUM_LONG_TITLE', $this->result["ID"]);
90 }
91
92 return $newTitle;
93 }
94}