コード例 #1
0
 private function _createAlbum()
 {
     $albumData = [];
     $albumThumbs = [];
     $data = $this->_vkObject->api('photos.getAlbums', 'GET', ['owner_id' => '-' . self::VK_GROUP_ID]);
     if (isset($data, $data['response'], $data['response'][0])) {
         foreach ($data['response'] as $response) {
             $albumThumbs[] = (int) $response['thumb_id'];
             $albumData[] = ['album_id' => $response['aid'], 'title' => $response['title'], 'description' => $response['description'], 'vk_created' => (int) $response['created'], 'vk_updated' => (int) $response['updated'], 'created_at' => time(), 'updated_at' => time()];
         }
         if ($albumData && $albumData[0]) {
             Yii::$app->db->createCommand('TRUNCATE `' . $this->_getClassBaseName(new Photos()) . '`')->execute();
             Yii::$app->db->createCommand('TRUNCATE `' . $this->_getClassBaseName(new Album()) . '`')->execute();
             $this->removeDir(Yii::getAlias('@fullMediaDir/'));
             Yii::$app->db->createCommand()->batchInsert(Album::tableName(), array_keys($albumData[0]), $albumData)->execute();
         }
     }
     return ['albumData' => $albumData, 'albumThumbs' => $albumThumbs];
 }