-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.item.php
More file actions
71 lines (59 loc) · 1.92 KB
/
Copy pathcode.item.php
File metadata and controls
71 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @class codeItem
* @author SMaker (dowon2308@paran.com)
* @brief code 객체
**/
class codeItem {
var $code = ''; ///<< 쿠폰 코드
var $length = 17; ///< 쿠폰 코드 길이
var $split_length = 5; ///< 쿠폰 코드를 나눌 길이
var $alpha = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); ///< 알파벳 목록
function codeItem($length, $split_length) {
$this->length = $length;
$this->split_length = $split_length;
}
function setCode($code) {
$this->code = $code;
}
function setLength($length) {
$this->length = $length;
}
function setSplitLength($length) {
$this->split_length = $length;
}
function getLength() {
return $this->length;
}
function getSplitLength() {
return $this->split_length;
}
function getCode() {
return $this->code;
}
function generate() {
/**
* @TODO: 자유로운 코드 생성을 위한 개선 필요
*/
$length = $this->getLength();
$split_length = $this->getSplitLength() + 1;
$alpha = $this->alpha;
for($i=0; $i<$length; $i++) {
if(($i+1) % $split_length === 0) {
$code[] = '-';
} else {
$type = rand(1,6);
switch($type % 3) {
case 0:
$code[] = rand(0, 9);
break;
default:
$code[] = $alpha[rand(0, 25)];
break;
}
}
}
$this->setCode(join('',$code));
}
}
?>