XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AvatarEditForm.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
13
15{
16 public $mOldAvatarFilename = null;
17 public $mFormFile = null;
18
19 public $mWidth = 0;
20 public $mHeight = 0;
21
22 public function getTokenName()
23 {
24 return 'module.user.AvatarEditForm.TOKEN' . $this->get('uid');
25 }
26
27 public function prepare($width = null, $height = null, $maxfilesize = null)
28 //public function prepare()
29 {
30 // $width = '';
31 // $height = '';
32 // $maxfilesize = '';assert($baz instanceof Baz);
33 //parent::prepare($width, $height, $maxfilesize);
34 $this->mWidth = $width;
35 $this->mHeight = $height;
36
37 //
38 // Set form properties
39 //
40 $this->mFormProperties['uid'] =new XCube_IntProperty('uid');
41 $this->mFormProperties['uploadavatar'] =new XCube_ImageFileProperty('uploadavatar');
42
43 //
44 // Set field properties
45 //
46 $this->mFieldProperties['uploadavatar'] =new XCube_FieldProperty($this);
47 $this->mFieldProperties['uploadavatar']->setDependsByArray(['extension', 'maxfilesize']);
48 $this->mFieldProperties['uploadavatar']->addMessage('extension', _MD_USER_ERROR_AVATAR_EXTENSION);
49 $this->mFieldProperties['uploadavatar']->addVar('extension', 'jpg,gif,png');
50 $this->mFieldProperties['uploadavatar']->addMessage('maxfilesize', _MD_USER_ERROR_AVATAR_MAXFILESIZE);
51 $this->mFieldProperties['uploadavatar']->addVar('maxfilesize', $maxfilesize);
52 }
53
54 public function validateUploadavatar()
55 {
56 if (null != $this->get('uploadavatar')) {
57 /*
58 $formfile = $this->get('uploadavatar');
59 if ($formfile->getWidth() > $this->mWidth) {
60 $this->addErrorMessage(_MD_USER_ERROR_AVATAR_SIZE);
61 }
62 elseif ($formfile->getHeight() > $this->mHeight) {
63 $this->addErrorMessage(_MD_USER_ERROR_AVATAR_SIZE);
64 }
65 */
66 }
67 }
68
69 public function load(&$obj)
70 {
71 $this->set('uid', $obj->get('uid'));
72 $this->mOldAvatarFilename = $obj->get('user_avatar');
73 }
74
75 public function update(&$obj)
76 {
77 $obj->set('uid', $this->get('uid'));
78
79 $this->mFormFile = $this->get('uploadavatar');
80
81 if (null != $this->mFormFile) {
82 $this->mFormFile->setRandomToBodyName('cavt');
83
84 $filename = $this->mFormFile->getFileName();
85 $this->mFormFile->setBodyName(substr($filename, 0, 25));
86
87 $obj->set('user_avatar', $this->mFormFile->getFileName()); //< TODO
88 }
89 }
90
94 public function createAvatar()
95 {
96 $avatar = null;
97 if (null != $this->mFormFile) {
98 $avatarHandler =& xoops_getmodulehandler('avatar', 'user');
99 $avatar =& $avatarHandler->create();
100 $avatar->set('avatar_file', $this->mFormFile->getFileName());
101 $avatar->set('avatar_mimetype', $this->mFormFile->getContentType());
102 $avatar->set('avatar_type', 'C');
103 }
104
105 return $avatar;
106 }
107}
update(&$obj)
[Abstract] Updates an object with properties values.
getTokenName()
Gets the token name of this actionform's token.
load(&$obj)
[Abstract] Initializes properties' values from an object.
prepare()
[Abstract] Set up form properties and field properties.
[Abstract] Used for validating member property values of XCube_ActionForm.
This is extended XCube_FileProperty and limits uploaded files by image files.
Represents int property.