Proyectos de Subversion LeadersLinked - Services

Rev

Rev 111 | Rev 333 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 111 Rev 283
Línea 58... Línea 58...
58
use LeadersLinked\Model\UserAptitude;
58
use LeadersLinked\Model\UserAptitude;
59
use LeadersLinked\Form\UserProfile\HobbyAndInterestForm;
59
use LeadersLinked\Form\UserProfile\HobbyAndInterestForm;
60
use LeadersLinked\Mapper\HobbyAndInterestMapper;
60
use LeadersLinked\Mapper\HobbyAndInterestMapper;
61
use LeadersLinked\Mapper\UserHobbyAndInterestMapper;
61
use LeadersLinked\Mapper\UserHobbyAndInterestMapper;
62
use LeadersLinked\Model\UserHobbyAndInterest;
62
use LeadersLinked\Model\UserHobbyAndInterest;
-
 
63
use LeadersLinked\Library\Storage;
Línea 63... Línea 64...
63
 
64
 
64
 
65
 
65
class MyProfilesController extends AbstractActionController
66
class MyProfilesController extends AbstractActionController
Línea 135... Línea 136...
135
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
136
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
136
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
137
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
137
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
138
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
138
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
139
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
Línea -... Línea 140...
-
 
140
 
-
 
141
                
Línea 139... Línea 142...
139
 
142
                $storage = Storage::getInstance($this->config);
140
 
143
 
Línea 146... Línea 149...
146
                foreach ($records as $record) {
149
                foreach ($records as $record) {
Línea 147... Línea 150...
147
 
150
 
148
                    $item = [
151
                    $item = [
149
                        'id' => $record->id,
152
                        'id' => $record->id,
150
                        'name' => $record->name,
153
                        'name' => $record->name,
151
                        'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $record->image],['force_canonical' => true]),
154
                        'image' => $storage->getUserImage($currentUser),
152
                        'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid])  : '',
155
                        'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid])  : '',
153
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid])  : '',
156
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid])  : '',
154
                        'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' => $record->uuid]) : '',
157
                        'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' => $record->uuid]) : '',
Línea 499... Línea 502...
499
 
502
 
500
 
503
 
Línea 501... Línea -...
501
            $image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
-
 
-
 
504
            $image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
Línea 502... Línea 505...
502
            $image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
505
            $image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
503
 
506
 
504
 
507
            $storage = Storage::getInstance($this->config);
505
 
508
 
506
                $data = [
509
                $data = [
507
                    'following'         => $following,
510
                    'following'         => $following,
508
                    'follower'          => $follower,
511
                    'follower'          => $follower,
509
                    'user_id'           => $user->id,
512
                    'user_id'           => $user->id,
510
                    'user_uuid'         => $user->uuid,
513
                    'user_uuid'         => $user->uuid,
511
                    'full_name'         => trim($user->first_name . ' ' . $user->last_name),
514
                    'full_name'         => trim($user->first_name . ' ' . $user->last_name),
512
                    'user_profile_id'   => $userProfile->id,
515
                    'user_profile_id'   => $userProfile->id,
513
                    'user_profile_uuid' => $userProfile->uuid,
516
                    'user_profile_uuid' => $userProfile->uuid,
514
                    'image'             => $this->url()->fromRoute('storage', ['type' => 'user-profile', 'code' => $currentUser->uuid, 'filename' => $userProfile->image],['force_canonical' => true]),
517
                    'image'             => $storage->getUserImage($currentUser),
515
                    'cover'             => $this->url()->fromRoute('storage', ['type' => 'user-cover', 'code' => $currentUser->uuid, 'filename' => $userProfile->cover],['force_canonical' => true]),
518
                    'cover'             => $storage->getUserProfileCover($currentUser, $userProfile),
516
                    'overview'          => $userProfile->description,
519
                    'overview'          => $userProfile->description,
Línea 1599... Línea 1602...
1599
 
1602
 
1600
 
1603
 
-
 
1604
 
1601
 
1605
        $request = $this->getRequest();
-
 
1606
        if ($request->isPost()) {
1602
        $request = $this->getRequest();
1607
            $image = Image::getInstance($this->config);
1603
        if ($request->isPost()) {
1608
            $target_path = $image->getStorage()->getPathUser();
Línea 1604... Línea 1609...
1604
            $target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
1609
            
1605
            if ($operation == 'delete') {
1610
            if ($operation == 'delete') {
1606
                $this->logger->info('Se borro el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1611
                $this->logger->info('Se borro el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1607
 
1612
 
1608
                if ($userProfile->image) {
1613
                if ($userProfile->image) {
1609
                    if (!Image::delete($target_path, $userProfile->image)) {
1614
                    if (!$image->getStorage()->deleteFile($target_path, $currentUser->uuid, $userProfile->image)) {
1610
                        return new JsonModel([
1615
                        return new JsonModel([
Línea 1637... Línea 1642...
1637
                            'data'   =>  'ERROR_UPLOAD_FILE'
1642
                            'data'   =>  'ERROR_UPLOAD_FILE'
1638
                        ]);
1643
                        ]);
1639
                    }
1644
                    }
Línea 1640... Línea 1645...
1640
 
1645
 
1641
                    if ($userProfile->image) {
1646
                    if ($userProfile->image) {
1642
                        if (!Image::delete($target_path, $userProfile->image)) {
1647
                        if (!$image->getStorage()->deleteFile($target_path, $currentUser->uuid, $userProfile->image)) {
1643
                            return new JsonModel([
1648
                            return new JsonModel([
1644
                                'success'   => false,
1649
                                'success'   => false,
1645
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1650
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1646
                            ]);
1651
                            ]);
Línea 1649... Línea 1654...
1649
 
1654
 
1650
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1655
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1651
                    $source             = $files['image']['tmp_name'];
1656
                    $source             = $files['image']['tmp_name'];
1652
                    $target_filename    = 'user-profile-' . uniqid() . '.png';
1657
                    $target_filename    = 'user-profile-' . uniqid() . '.png';
-
 
1658
                    $crop_to_dimensions = true;
Línea 1653... Línea 1659...
1653
                    $crop_to_dimensions = true;
1659
                    $unlink_source = false;
1654
 
1660
 
1655
                    if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1661
                    if (!$image->uploadImageChangeSize($source, $target_path, $currentUser->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
1656
                        return new JsonModel([
1662
                        return new JsonModel([
1657
                            'success'   => false,
1663
                            'success'   => false,
1658
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1664
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
Línea 1666... Línea 1672...
1666
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1672
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1667
                        ]);
1673
                        ]);
1668
                    }
1674
                    }
Línea 1669... Línea 1675...
1669
 
1675
 
-
 
1676
                    if ($userProfile->public == UserProfile::PUBLIC_YES) {
-
 
1677
                        
-
 
1678
                        $target_filename    = 'user-' . uniqid() . '.png';
-
 
1679
                        $unlink_source = true;
-
 
1680
                        
-
 
1681
                        if (!$image->uploadImageChangeSize($source, $target_path, $currentUser->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
1682
                            return new JsonModel([
-
 
1683
                                'success'   => false,
-
 
1684
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
1685
                            ]);
Línea 1670... Línea 1686...
1670
                    if ($userProfile->public == UserProfile::PUBLIC_YES) {
1686
                        }
Línea 1671... Línea 1687...
1671
 
1687
 
1672
                        $currentUser->image = $target_filename;
1688
                        $currentUser->image = $target_filename;
Línea 1687... Línea 1703...
1687
                        'success'   => false,
1703
                        'success'   => false,
1688
                        'data'   => $messages
1704
                        'data'   => $messages
1689
                    ]);
1705
                    ]);
1690
                }
1706
                }
1691
            }
1707
            }
-
 
1708
            
-
 
1709
            $storage = Storage::getInstance($this->config);
-
 
1710
            
1692
            return new JsonModel([
1711
            return new JsonModel([
1693
                'success'   => true,
1712
                'success'   => true,
1694
                'data' => [
1713
                'data' => [
1695
                    'user' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $currentUser->image],['force_canonical' => true]),
1714
                    'user' => $storage->getUserImage($currentUser),
1696
                    'profile' => $this->url()->fromRoute('storage', ['type' => 'user-profile', 'code' => $currentUser->uuid, 'filename' => $userProfile->image],['force_canonical' => true]),
1715
                    'profile' => $storage->getUserProfileImage($currentUser, $userProfile),
1697
                    'update_navbar' =>  $userProfile->public == UserProfile::PUBLIC_YES ? 1 : 0,
1716
                    'update_navbar' =>  $userProfile->public == UserProfile::PUBLIC_YES ? 1 : 0,
Línea 1698... Línea 1717...
1698
 
1717
 
1699
                ]
1718
                ]
1700
            ]);
1719
            ]);
Línea 1747... Línea 1766...
1747
 
1766
 
1748
 
1767
 
-
 
1768
 
1749
 
1769
        $request = $this->getRequest();
1750
        $request = $this->getRequest();
1770
        if ($request->isPost()) {
1751
        if ($request->isPost()) {
1771
            $image = Image::getInstance($this->config);
1752
            $target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
1772
            $target_path = $image->getStorage()->getPathUser();
1753
 
1773
  
1754
            if ($operation == 'delete') {
1774
            if ($operation == 'delete') {
1755
                if ($userProfile->cover) {
1775
                if ($userProfile->cover) {
1756
                    if (!Image::delete($target_path, $userProfile->cover)) {
1776
                    if (!$image->getStorage()->deleteFile($target_path, $currentUser->uuid, $userProfile->cover)) {
1757
                        return new JsonModel([
1777
                        return new JsonModel([
1758
                            'success'   => false,
1778
                            'success'   => false,
Línea 1782... Línea 1802...
1782
                        ]);
1802
                        ]);
1783
                    }
1803
                    }
Línea 1784... Línea 1804...
1784
 
1804
 
1785
 
1805
 
1786
                    if ($userProfile->cover) {
1806
                    if ($userProfile->cover) {
1787
                        if (!Image::delete($target_path, $userProfile->cover)) {
1807
                        if (!$image->getStorage()->deleteFile($target_path, $currentUser->uuid, $userProfile->cover)) {
1788
                            return new JsonModel([
1808
                            return new JsonModel([
1789
                                'success'   => false,
1809
                                'success'   => false,
1790
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1810
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
Línea 1797... Línea 1817...
1797
 
1817
 
1798
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_cover_size']);
1818
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_cover_size']);
1799
                    $target_filename = 'user-cover-' . uniqid() . '.png';
1819
                    $target_filename = 'user-cover-' . uniqid() . '.png';
1800
                    $source = $files['cover']['tmp_name'];
1820
                    $source = $files['cover']['tmp_name'];
-
 
1821
                    $crop_to_dimensions = false;
Línea 1801... Línea 1822...
1801
                    $crop_to_dimensions = false;
1822
                    $unlink_source = true;
1802
 
1823
 
1803
                    if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1824
                    if (!$image->uploadImageChangeSize($source, $target_path, $currentUser->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
1804
                        return new JsonModel([
1825
                        return new JsonModel([
1805
                            'success'   => false,
1826
                            'success'   => false,
1806
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1827
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
Línea 1830... Línea 1851...
1830
                        'success'   => false,
1851
                        'success'   => false,
1831
                        'data'   => $messages
1852
                        'data'   => $messages
1832
                    ]);
1853
                    ]);
1833
                }
1854
                }
1834
            }
1855
            }
-
 
1856
            
-
 
1857
            $storage = Storage::getInstance($this->config);
-
 
1858
            
1835
            return new JsonModel([
1859
            return new JsonModel([
1836
                'success'   => true,
1860
                'success'   => true,
1837
                'data' => $this->url()->fromRoute('storage', ['type' => 'user-cover', 'code' => $currentUser->uuid, 'filename' => $userProfile->cover],['force_canonical' => true])
1861
                'data' => $storage->getUserProfileCover($currentUser, $userProfile)
Línea 1838... Línea 1862...
1838
 
1862
 
1839
            ]);
1863
            ]);