XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AvatarAdminEditForm.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
8
10{
11 public $mOldFileName = null;
12 public $_mIsNew = false;
13 public $mFormFile = null;
14
15 public function getTokenName()
16 {
17 return 'module.user.AvatarAdminEditForm.TOKEN' . $this->get('avatar_id');
18 }
19
20 public function prepare()
21 {
22 //
23 // Set form properties
24 //
25 $this->mFormProperties['avatar_id'] =new XCube_IntProperty('avatar_id');
26 $this->mFormProperties['avatar_file'] =new XCube_FileProperty('avatar_file');
27 $this->mFormProperties['avatar_name'] =new XCube_StringProperty('avatar_name');
28 $this->mFormProperties['avatar_display'] =new XCube_BoolProperty('avatar_display');
29 $this->mFormProperties['avatar_weight'] =new XCube_IntProperty('avatar_weight');
30
31 //
32 // Set field properties
33 //
34 $this->mFieldProperties['avatar_id'] =new XCube_FieldProperty($this);
35 $this->mFieldProperties['avatar_id']->setDependsByArray(['required']);
36 $this->mFieldProperties['avatar_id']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_AVATAR_ID);
37
38 $this->mFieldProperties['avatar_file'] =new XCube_FieldProperty($this);
39 $this->mFieldProperties['avatar_file']->setDependsByArray(['extension']);
40 $this->mFieldProperties['avatar_file']->addMessage('extension', _MD_USER_ERROR_AVATAR_EXTENSION, _AD_USER_LANG_AVATAR_FILE);
41 $this->mFieldProperties['avatar_file']->addVar('extension', 'gif,png,jpg');
42
43 $this->mFieldProperties['avatar_name'] =new XCube_FieldProperty($this);
44 $this->mFieldProperties['avatar_name']->setDependsByArray(['required', 'maxlength']);
45 $this->mFieldProperties['avatar_name']->addMessage('required', _MD_USER_ERROR_REQUIRED, _AD_USER_LANG_AVATAR_NAME, '100');
46 $this->mFieldProperties['avatar_name']->addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _AD_USER_LANG_AVATAR_NAME, '100');
47 $this->mFieldProperties['avatar_name']->addVar('maxlength', 100);
48
49 $this->mFieldProperties['avatar_weight'] =new XCube_FieldProperty($this);
50 $this->mFieldProperties['avatar_weight']->setDependsByArray(['required']);
51 $this->mFieldProperties['avatar_weight']->addMessage('required', _MD_USER_ERROR_REQUIRED, _AD_USER_LANG_AVATAR_WEIGHT);
52 }
53
54 public function validateAvatar_file()
55 {
56 if ($this->_mIsNew && null == $this->get('avatar_file')) {
57 $this->addErrorMessage(_AD_USER_ERROR_IMAGE_REQUIRED);
58 }
59 }
60
61 public function load(&$obj)
62 {
63 $this->set('avatar_id', $obj->get('avatar_id'));
64 $this->set('avatar_name', $obj->get('avatar_name'));
65 $this->set('avatar_display', $obj->get('avatar_display'));
66 $this->set('avatar_weight', $obj->get('avatar_weight'));
67
68 $this->_mIsNew = $obj->isNew();
69 $this->mOldFileName = $obj->get('avatar_file');
70 }
71
72 public function update(&$obj)
73 {
74 $obj->set('avatar_id', $this->get('avatar_id'));
75 $obj->set('avatar_name', $this->get('avatar_name'));
76 $obj->set('avatar_display', $this->get('avatar_display'));
77 $obj->set('avatar_weight', $this->get('avatar_weight'));
78
79 $this->mFormFile = $this->get('avatar_file');
80 if (null != $this->mFormFile) {
81 $this->mFormFile->setRandomToBodyName('savt');
82 $filename = $this->mFormFile->getBodyName();
83 $this->mFormFile->setBodyName(substr($filename, 0, 24));
84
85 $obj->setVar('avatar_file', $this->mFormFile->getFileName());
86 $obj->setVar('avatar_mimetype', $this->mFormFile->getContentType());
87 }
88 }
89}
update(&$obj)
[Abstract] Updates an object with properties values.
getTokenName()
Gets the token name of this actionform's token.
prepare()
[Abstract] Set up form properties and field properties.
load(&$obj)
[Abstract] Initializes properties' values from an object.
addErrorMessage( $message)
Adds a message to the form's error message buffer.
Represents bool property.
[Abstract] Used for validating member property values of XCube_ActionForm.
Represents the special property which handles uploaded file.
Represents int property.
Represents string property.