Skip to content

Commit

Permalink
Merge pull request #2607 from phili67/phili67-photo-enhancements
Browse files Browse the repository at this point in the history
photo profil deletion and update
  • Loading branch information
phili67 committed Apr 14, 2024
2 parents 4882abc + 1efdb74 commit 4ac9054
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/EcclesiaCRM/dto/Photo.php
Expand Up @@ -110,6 +110,10 @@ private function convertToPNG() {

private function getGDImage($sourceImagePath) {
$sourceImageType = exif_imagetype($sourceImagePath);
if ($sourceImageType == false) {
$sourceImagePath = str_replace("-initials","", $sourceImagePath);
$sourceImageType = exif_imagetype($sourceImagePath);
}
switch ($sourceImageType)
{
case IMAGETYPE_GIF:
Expand Down Expand Up @@ -271,6 +275,7 @@ public function setImageFromBase64($base64) {
file_put_contents( $fileName , $fileData);
}

$this->createThumbnail();
}

public function delete() {
Expand Down
27 changes: 19 additions & 8 deletions src/EcclesiaCRM/model/EcclesiaCRM/Family.php
Expand Up @@ -328,33 +328,41 @@ public function getPhoto()
return $this->photo;
}

// 'initials-image direct-chat-img'
public function getJPGPhotoDatas($width = '50', $heigth = '50', $class = 'user-image initials-image'): string
private function changeJPGPhotoDatas($width = '50', $heigth = '50', $class = 'user-image initials-image') : void
{
if (isset($_SESSION['photos']['families'][$this->getId()])) {
return $_SESSION['photos']['families'][$this->getId()];
}

// usefull for base 64
$photo = $this->getPhoto();
$datas = base64_encode($photo->getThumbnailBytes());

$_SESSION['photos']['families'][$this->getId()] = '<img src="data:image/jpg;base64, ' . $datas . '" class="' . $class . '" width="' . $width . '" height="' . $heigth . '" />';
}

// 'initials-image direct-chat-img'
public function getJPGPhotoDatas($width = '50', $heigth = '50', $class = 'user-image initials-image'): string
{
if (isset($_SESSION['photos']['families'][$this->getId()])) {
return $_SESSION['photos']['families'][$this->getId()];
}

$this->changeJPGPhotoDatas($width, $heigth, $class);

return $_SESSION['photos']['families'][$this->getId()];
}

public function deletePhoto()
{
if (SessionUser::getUser()->isAddRecordsEnabled() || SessionUser::getUser()->getPerson()->getFamily()->getId() == $this->getId() ) {
if ( $this->getPhoto()->delete() )
{
if ( $this->getPhoto()->delete() ) {
$this->photo = null;
$note = new Note();
$note->setText(_("Profile Image Deleted"));
$note->setType("photo");
$note->setEntered(SessionUser::getUser()->getPersonId());
$note->setPerId($this->getId());
$note->save();

$this->changeJPGPhotoDatas('50', '50', 'user-image initials-image');

return true;
}
}
Expand All @@ -369,6 +377,9 @@ public function setImageFromBase64($base64) {
$this->getPhoto()->setImageFromBase64($base64);
$note->setFamId($this->getId());
$note->save();

$this->changeJPGPhotoDatas('50', '50', 'user-image initials-image');

return true;
}
return false;
Expand Down
23 changes: 17 additions & 6 deletions src/EcclesiaCRM/model/EcclesiaCRM/Person.php
Expand Up @@ -565,18 +565,23 @@ public function getLatLng()
);
}

private function changeJPGPhotoDatas($width = '50', $heigth = '50', $class = 'user-image initials-image') : void
{
// usefull for base 64
$photo = $this->getPhoto();
$datas = base64_encode($photo->getThumbnailBytes());

$_SESSION['photos']['persons'][$this->getId()] = '<img src="data:image/jpg;base64, ' . $datas . '" class="' . $class . '" width="' . $width . '" height="' . $heigth . '" />';
}

// 'initials-image direct-chat-img'
public function getJPGPhotoDatas($width = '50', $heigth = '50', $class = 'user-image initials-image'): string
{
if (isset($_SESSION['photos']['persons'][$this->getId()])) {
return $_SESSION['photos']['persons'][$this->getId()];
}

// usefull for base 64
$photo = $this->getPhoto();
$datas = base64_encode($photo->getThumbnailBytes());

$_SESSION['photos']['persons'][$this->getId()] = '<img src="data:image/jpg;base64, ' . $datas . '" class="' . $class . '" width="' . $width . '" height="' . $heigth . '" />';
$this->changeJPGPhotoDatas($width, $heigth, $class);

return $_SESSION['photos']['persons'][$this->getId()];
}
Expand All @@ -585,12 +590,16 @@ public function deletePhoto()
{
if (SessionUser::getUser()->isAddRecordsEnabled() || SessionUser::getUser()->getPersonId() == $this->getId() ) {
if ($this->getPhoto()->delete()) {
$this->photo = null;
$note = new Note();
$note->setText(gettext("Profile Image Deleted"));
$note->setType("photo");
$note->setEntered(SessionUser::getUser()->getPersonId());
$note->setPerId($this->getId());
$note->save();

$this->changeJPGPhotoDatas('50', '50', 'user-image initials-image');

return true;
}
}
Expand All @@ -616,10 +625,12 @@ public function setImageFromBase64($base64)
$this->getPhoto()->setImageFromBase64($base64);
$note->setPerId($this->getId());
$note->save();

$this->changeJPGPhotoDatas('50', '50', 'user-image initials-image');

return true;
}
return false;

}

/**
Expand Down

0 comments on commit 4ac9054

Please sign in to comment.