File size: 4,652 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
<?php
/**
 * AppMessage.php
 * * @package workflow.engine.classes.model
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2011 Colosa Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 */

//require_once 'classes/model/om/BaseAppMessage.php';

/**
 * Skeleton subclass for representing a row from the 'APP_MESSAGE' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements. This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package workflow.engine.classes.model
 */
class AppMessage extends BaseAppMessage
{

    private $data_spool;
    private $status_spool;
    private $error_spool;

    public function getSpoolStatus ()
    {
        return $this->status_spool;
    }

    public function getSpoolError ()
    {
        return $this->error_spool;
    }

    /**
     * AppMessgae quick Save method
     *
     * @param Array(msg_uid, app_uid, del_index, app_msg_type, app_msg_subject, app_msg_from, app_msg_to,
     * app_msg_body, app_msg_cc, app_msg_bcc, app_msg_attach, app_msg_template, app_msg_status )
     *
     * @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmai.com>
     * Date Aug 31th, 2009
     */
    public function quickSave2 ($data_spool)
    {
        $this->data_spool = $data_spool;

        $sUID = G::generateUniqueID();
        $spool = new AppMessage();

        $spool->setAppMsgUid( $sUID );
        $spool->setMsgUid( $data_spool['msg_uid'] );
        $spool->setAppUid( $data_spool['app_uid'] );
        $spool->setDelIndex( $data_spool['del_index'] );
        $spool->setAppMsgType( $data_spool['app_msg_type'] );
        $spool->setAppMsgSubject( $data_spool['app_msg_subject'] );
        $spool->setAppMsgFrom( $data_spool['app_msg_from'] );
        $spool->setAppMsgTo( $data_spool['app_msg_to'] );
        $spool->setAppMsgBody( $data_spool['app_msg_body'] );
        $spool->setAppMsgDate( date( 'Y-m-d H:i:s' ) );
        $spool->setAppMsgCc( $data_spool['app_msg_cc'] );
        $spool->setAppMsgBcc( $data_spool['app_msg_bcc'] );
        $spool->setappMsgAttach( $data_spool['app_msg_attach'] );
        $spool->setAppMsgTemplate( $data_spool['app_msg_template'] );
        $spool->setAppMsgStatus( $data_spool['app_msg_status'] );
        $spool->setAppMsgError( $data_spool['app_msg_error'] );

        if (! $spool->validate()) {
            $this->error_spool = $spool->getValidationFailures();
            $this->status_spool = 'error';

            $error_msg = "AppMessage::quickSave(): Validation error: \n";
            foreach ($errors as $key => $value) {
                $error_msg .= $value->getMessage( $key ) . "\n";
            }
            throw new Exception( $error_msg );
        } else {
            //echo "Saving - validation ok\n";
            $this->error_spool = '';
            $this->status = 'success';
            $spool->save();
        }
        return $sUID;
    }

    public function quickSave ($aData)
    {
        if (isset( $aData['app_msg_uid'] )) {
            $o = EmployeePeer::retrieveByPk( $aData['app_msg_uid'] );
        }
        if (isset( $o ) && is_object( $o ) && get_class( $o ) == 'AppMessage') {
            $o->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
            $o->setAppMsgDate( date( 'Y-m-d H:i:s' ) );
            $o->save();
            return $o->getAppMsgUid();
        } else {
            $this->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
            $this->setAppMsgDate( date( 'Y-m-d H:i:s' ) );
            $this->save();
            return $this->getAppMsgUid();
        }
    }

    public function updateStatus($msgUid, $msgStatus)
    {
        $message = AppMessagePeer::retrieveByPk( $msgUid );
        $message->fromArray( $message, BasePeer::TYPE_FIELDNAME );
        $message->setAppMsgStatus($msgStatus);
        $message->save();
    }
}