File size: 5,995 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
class AppAssignSelfServiceValue extends BaseAppAssignSelfServiceValue
{
    /**
     * Create record
     *
     * @param string $applicationUid Unique id of Case
     * @param int    $delIndex       Delegation index
     * @param array  $arrayData      Data
     *
     * return void
     */
    public function create($applicationUid, $delIndex, array $arrayData, $dataVariable)
    {
        try {
            $cnn = Propel::getConnection(AppAssignSelfServiceValuePeer::DATABASE_NAME);

            try {
                $appAssignSelfServiceValue = new AppAssignSelfServiceValue();

                $appAssignSelfServiceValue->fromArray($arrayData, BasePeer::TYPE_FIELDNAME);

                $appAssignSelfServiceValue->setAppUid($applicationUid);
                $appAssignSelfServiceValue->setDelIndex($delIndex);

                if ($appAssignSelfServiceValue->validate()) {
                    $cnn->begin();
                    $result = $appAssignSelfServiceValue->save();
                    $cnn->commit();

                    //SELECT LAST_INSERT_ID()
                    $stmt = $cnn->createStatement();
                    $rs = $stmt->executeQuery("SELECT LAST_INSERT_ID()", ResultSet::FETCHMODE_ASSOC);
                    $rs->next();
                    $row = $rs->getRow();
                    $appAssignSelfServiceValueId = $row['LAST_INSERT_ID()'];
                    $appAssignSelfServiceValueGroup = new AppAssignSelfServiceValueGroup();
                    $appAssignSelfServiceValueGroup->createRows($appAssignSelfServiceValueId, $dataVariable);
                } else {
                    $msg = "";

                    foreach ($appAssignSelfServiceValue->getValidationFailures() as $validationFailure) {
                        $msg .= (($msg != "")? "\n" : "") . $validationFailure->getMessage();
                    }

                    throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
                }
            } catch (Exception $e) {
                $cnn->rollback();

                throw $e;
            }
        } catch (Exception $e) {
            throw $e;
        }
    }

    /**
     * Remove record
     *
     * @param string $applicationUid Unique id of Case
     * @param int    $delIndex       Delegation index
     *
     * return void
     */
    public function remove($applicationUid, $delIndex = 0)
    {
        try {
            $criteria = new Criteria("workflow");

            $criteria->add(AppAssignSelfServiceValuePeer::APP_UID, $applicationUid, Criteria::EQUAL);

            if ($delIndex != 0) {
                $criteria->add(AppAssignSelfServiceValuePeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
            }

            $result = AppAssignSelfServiceValuePeer::doDelete($criteria);

            // Delete related rows and missing relations, criteria don't execute delete with joins
            $cnn = Propel::getConnection(AppAssignSelfServiceValueGroupPeer::DATABASE_NAME);
            $cnn->begin();
            $stmt = $cnn->createStatement();
            $rs = $stmt->executeQuery("DELETE " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
                                       FROM " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
                                       LEFT JOIN " . AppAssignSelfServiceValuePeer::TABLE_NAME . "
                                       ON (" . AppAssignSelfServiceValueGroupPeer::ID . " = " . AppAssignSelfServiceValuePeer::ID . ")
                                       WHERE " . AppAssignSelfServiceValuePeer::ID . " IS NULL");
            $cnn->commit();
        } catch (Exception $e) {
            throw $e;
        }
    }

    /**
     * Generate data
     *
     * return void
     */
    public function generateData()
    {
        try {
            AppAssignSelfServiceValuePeer::doDeleteAll(); //Delete all records

            //Generate data
            $case = new Cases();

            $criteria = new Criteria("workflow");

            $criteria->addSelectColumn(AppDelegationPeer::APP_UID);
            $criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
            $criteria->addSelectColumn(ApplicationPeer::APP_DATA);
            $criteria->addSelectColumn(AppDelegationPeer::PRO_UID);
            $criteria->addSelectColumn(TaskPeer::TAS_UID);
            $criteria->addSelectColumn(TaskPeer::TAS_GROUP_VARIABLE);
            $criteria->addJoin(AppDelegationPeer::APP_UID, ApplicationPeer::APP_UID, Criteria::LEFT_JOIN);
            $criteria->addJoin(AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
            $criteria->add(TaskPeer::TAS_ASSIGN_TYPE, "SELF_SERVICE", Criteria::EQUAL);
            $criteria->add(TaskPeer::TAS_GROUP_VARIABLE, "", Criteria::NOT_EQUAL);
            $criteria->add(AppDelegationPeer::USR_UID, "", Criteria::EQUAL);
            $criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", Criteria::EQUAL);

            $rsCriteria = AppDelegationPeer::doSelectRS($criteria);
            $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

            while ($rsCriteria->next()) {
                $row = $rsCriteria->getRow();

                $applicationData = $case->unserializeData($row["APP_DATA"]);
                $taskGroupVariable = trim($row["TAS_GROUP_VARIABLE"], " @#");

                if ($taskGroupVariable != "" && isset($applicationData[$taskGroupVariable])) {
                    $dataVariable = $applicationData[$taskGroupVariable];
                    $dataVariable = (is_array($dataVariable))? $dataVariable : trim($dataVariable);

                    if (!empty($dataVariable)) {
                        $this->create($row["APP_UID"], $row["DEL_INDEX"], array("PRO_UID" => $row["PRO_UID"], "TAS_UID" => $row["TAS_UID"], "GRP_UID" => serialize($dataVariable)));
                    }
                }
            }
        } catch (Exception $e) {
            throw $e;
        }
    }
}