Ejemplo n.º 1
0
 public static function update($category, $avatar = null)
 {
     // Find existing Category
     $categoryToUpdate = self::findById($category->id);
     // Copy Attributes
     $categoryToUpdate->copyForUpdateFrom($category, ['avatarId', 'parentId', 'name', 'description', 'type', 'icon', 'featured', 'options']);
     if (isset($avatar)) {
         FileService::saveImage($avatar, ['model' => $categoryToUpdate, 'attribute' => 'avatarId']);
     }
     // Update Category
     $categoryToUpdate->update();
     // Return updated Category
     return $categoryToUpdate;
 }
Ejemplo n.º 2
0
 public static function update($site, $avatar = null, $banner = null)
 {
     $siteToUpdate = self::findById($site->id);
     $siteToUpdate->copyForUpdateFrom($site, ['avatarId', 'name', 'order', 'active']);
     if (isset($avatar)) {
         FileService::saveImage($avatar, ['model' => $siteToUpdate, 'attribute' => 'avatarId']);
     }
     if (isset($banner)) {
         FileService::saveImage($banner, ['model' => $siteToUpdate, 'attribute' => 'bannerId']);
     }
     $siteToUpdate->update();
     return $siteToUpdate;
 }
Ejemplo n.º 3
0
 /**
  * The method update user including avatar.
  * @param User $user
  * @param CmgFile $avatar
  * @return User
  */
 public static function update($user, $avatar = null)
 {
     // Find existing user
     $userToUpdate = User::findById($user->id);
     // Copy Attributes
     $userToUpdate->copyForUpdateFrom($user, ['avatarId', 'genderId', 'email', 'username', 'firstName', 'lastName', 'status', 'phone']);
     if (isset($avatar)) {
         // Save Avatar
         FileService::saveImage($avatar, ['model' => $userToUpdate, 'attribute' => 'avatarId']);
     }
     // Update User
     $userToUpdate->update();
     // Update mailing list
     NewsletterMemberService::update($user->email, $user->getName(), $user->newsletter);
     // Return updated User
     return $userToUpdate;
 }
Ejemplo n.º 4
0
 /**
  * @param ModelContent $content
  * @param CmgFile $banner
  * @return Page
  */
 public static function update($content, $publish = false, $banner = null, $video = null)
 {
     // template
     if (isset($content->templateId) && $content->templateId <= 0) {
         unset($content->templateId);
     }
     $contentToUpdate = self::findById($content->id);
     $contentToUpdate->copyForUpdateFrom($content, ['bannerId', 'templateId', 'summary', 'content', 'seoName', 'seoDescription', 'seoKeywords', 'seoRobot']);
     // publish
     if ($publish && !isset($contentToUpdate->publishedAt)) {
         $date = DateUtil::getDateTime();
         $contentToUpdate->publishedAt = $date;
     }
     // banner, video
     if (isset($banner)) {
         FileService::saveImage($banner, ['model' => $contentToUpdate, 'attribute' => 'bannerId']);
     }
     if (isset($video)) {
         FileService::saveImage($video, ['model' => $contentToUpdate, 'attribute' => 'videoId']);
     }
     // Update Content
     $contentToUpdate->update();
     return $contentToUpdate;
 }
Ejemplo n.º 5
0
 /**
  * The method create user avatar if it does not exist or save existing avatar.
  * @param User $user
  * @param CmgFile $avatar
  * @return User - updated User
  */
 public function updateAvatar($user, $avatar)
 {
     // Find existing user
     $userToUpdate = User::findById($user->id);
     // Save Avatar
     FileService::saveImage($avatar, ['model' => $userToUpdate, 'attribute' => 'avatarId']);
     // Update User
     $userToUpdate->update();
     // Return updated User
     return $userToUpdate;
 }
Ejemplo n.º 6
0
 /**
  * @param Block $block
  * @param CmgFile $banner
  * @param CmgFile $texture
  * @param CmgFile $video
  * @return Block
  */
 public static function update($block, $banner = null, $texture = null, $video = null)
 {
     if (isset($block->templateId) && $block->templateId <= 0) {
         unset($block->templateId);
     }
     $blockToUpdate = self::findById($block->id);
     $blockToUpdate->copyForUpdateFrom($block, ['name', 'description', 'active', 'options', 'title', 'icon', 'content', 'data']);
     if (isset($banner)) {
         FileService::saveImage($banner, ['model' => $blockToUpdate, 'attribute' => 'bannerId']);
     }
     if (isset($texture)) {
         FileService::saveImage($texture, ['model' => $blockToUpdate, 'attribute' => 'textureId']);
     }
     if (isset($video)) {
         FileService::saveImage($video, ['model' => $blockToUpdate, 'attribute' => 'videoId']);
     }
     $blockToUpdate->update();
     return $blockToUpdate;
 }