-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessor.php
More file actions
122 lines (112 loc) · 2.88 KB
/
Copy pathProcessor.php
File metadata and controls
122 lines (112 loc) · 2.88 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Inkifi\Consolidation;
use Inkifi\Mediaclip\API\Facade\User as fUser;
use Magento\Sales\Model\Order as O;
// 2019-01-12
final class Processor {
/**
* 2019-01-12
* @used-by \Inkifi\Consolidation\Controller\Adminhtml\Index\Index::execute()
*/
function consolidate() {
$this->f()->consolidate($this->mcid());
$this->updateDb();
}
/**
* 2019-01-12
* @used-by \Inkifi\Consolidation\Controller\Adminhtml\Index\Index::execute()
* @used-by \Inkifi\Consolidation\Plugin\Backend\Block\Widget\Button\Toolbar::beforePushButtons()
* @return bool
*/
function eligible() {
$r = false; /** @var bool $r */
// 2019-01-11
// It could be a string like «f6549c2f-9230-f8e8-f1e4-625c7ac4f2f1»
// or a Magento customer ID like «65963».
if (df_is_guid($mcid = $this->mcid())) { /** @var string $mcid */
if (!in_array($this->pid(), $this->f()->projects())) {
$r = true;
}
else {
// 2018-01-12
// The user has been consolidated manually before the module's installation.
// We need to update his ID in Magento.
$this->updateDb();
}
}
return $r;
}
/**
* 2019-01-12
* @used-by s()
* @param O $o
*/
private function __construct(O $o) {$this->_o = $o;}
/**
* 2019-01-12
* @used-by f()
* @used-by updateDb()
* @return int
*/
private function cid() {return (int)$this->_o->getCustomerId();}
/**
* 2019-01-12
* @used-by consolidate()
* @return fUser
*/
private function f() {return dfc($this, function() {return new fUser(
$this->cid(), $this->_o->getStore()
);});}
/**
* 2019-01-12
* @used-by consolidate()
* @return string
*/
private function mcid() {return dfc($this, function() {return df_fetch_one(
'mediaclip', 'user_id', ['project_id' => $this->pid()]
);});}
/**
* 2019-01-12
* @used-by eligible()
* @used-by mcid()
* @used-by updateDb()
* @return string
*/
private function pid() {return df_first($this->pids());}
/**
* 2019-01-31
* @used-by pid()
* @used-by updateDb()
* @return string[]
*/
private function pids() {return dfc($this, function() {return array_values(array_map(
'ikf_oi_pid', df_oqi_leafs($this->_o)
));});}
/**
* 2019-01-14
* @used-by consolidate()
* @used-by eligible()
*/
private function updateDb() {
$cid = $this->cid(); /** @var string $cid */
foreach ($this->pids() as $pid) { /** @var string $pid */
df_conn()->update('mediaclip', ['user_id' => $cid], ['? = project_id' => $pid]);
}
}
/**
* 2019-01-12
* @used-by pid()
* @var O
*/
private $_o;
/**
* 2019-01-12
* @used-by \Inkifi\Consolidation\Controller\Adminhtml\Index\Index::execute()
* @used-by \Inkifi\Consolidation\Plugin\Backend\Block\Widget\Button\Toolbar::beforePushButtons()
* @param int|null $oid [optional]
* @return self
*/
static function s($oid = null) {return dfcf(function($oid) {return
new self(df_order($oid))
;}, [intval($oid ?: df_request('order_id'))]);}
}