public function post() { if ($this->validate()) { $image = new PhotoActiveRecord(); $image->userId = Yii::$app->user->identity->id; $image->name = $this->name . ''; $image->photo = file_get_contents($this->file->tempName); $image->posted = date('Y-m-d H-i-s'); $imagick = new \Imagick(); $imagick->readImageBlob($image->photo); $size = $imagick->getImageGeometry(); if ($size['width'] > 800) { foreach ($imagick as $frame) { $frame->thumbnailImage(800, 0); } } $image->thumbnail = $imagick->getImagesBlob(); if (!$image->save()) { return false; } $tags = split(',', $this->tags); foreach ($tags as $item) { if ($item != '') { $tag = new TagsActiveRecord(); $tag->photo = $image->id; $tag->tag = trim($item); if (!$tag->save()) { return false; } } } return true; } return false; }
public function register() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->password = $this->password; $user->fio = $this->fio; $user->pol = $this->pol; $user->birthday = $this->birthday; $user->country = $this->country; $user->place = $this->place; $user->email = $this->email; $user->registerDate = date('Y-m-d H:i:s'); Yii::trace($this->birthday); Yii::trace($user->birthday . ' ' . $user->registerDate); if (!$user->save()) { return false; } if (!Yii::$app->user->login(User::findByUsername($this->username), 0)) { return false; } $photo = new PhotoActiveRecord(); $photo->userId = Yii::$app->user->identity->id; $photo->photo = file_get_contents($this->photo->tempName); $imagick = new \Imagick(); $imagick->readImageBlob($photo->photo); foreach ($imagick as $frame) { $frame->thumbnailImage(800, 0); } $photo->thumbnail = $imagick->getImagesBlob(); $photo->posted = date('Y-m-d H:i:s'); $photo->name = $this->fio; if (!$photo->save()) { return false; } $user->photo = $photo->id; $user->save(); return true; } return false; }