DataObjects/Core_person_signup.php
[Pman.Core] / DataObjects / Core_person_signup.php
1 <?php
2
3 /**
4  * Table Definition for Person
5  */
6 require_once 'DB/DataObject.php';
7
8 class Pman_Core_DataObjects_Core_person_signup extends DB_DataObject 
9 {
10     ###START_AUTOCODE
11     /* the code below is auto generated do not remove the above tag */
12
13     public $__table = 'core_person_signup';                          // table name
14     public $id;                              // int(11)  not_null primary_key auto_increment
15     public $email;                           // string(128)  not_null
16     public $name;                            // string(128)  not_null
17     public $firstname;                            // string(128)  not_null
18     public $lastname;                            // string(128)  not_null
19     public $firstname_alt;                            // string(128)  not_null
20     public $lastname_alt;                            // string(128)  not_null
21     public $honor;                            // string(128)  not_null
22     public $verify_key;                      // int(11)
23     public $verified;
24     public $created_dt;                      // datetime(19)  binary
25     public $company_name;
26     public $person_type;
27     
28     public $person_id;
29     public $person_table;
30
31 //    function verify($key) 
32 //    {
33 //        // if key matches verify_key
34 //        // copy into person or other entity...
35 //        // and delete....
36 //        if ($this->get("verify_key", $key)) {
37 //            $p = DB_DataObject::factory('person');
38 //            $p->setFrom(array(
39 //                'honor' => $this->honor,
40 //                'name' => $this->name,
41 //                'email' => $this->email,
42 //                'firstname' => $this->firstname,
43 //                'lastname' => $this->lastname,
44 //                'firstname_alt' => $this->firstname_alt,
45 //                'lastname_alt' => $this->lastname_alt));
46 //
47 //            if ($p->insert()) {
48 //
49 //                $temp_pwd = $p->generatePassword();
50 //
51 //                $this->delete();
52 //
53 //                //login
54 //                @session_start();
55 //
56 //                $_SESSION['Hydra']['authUser'] = $p ? serialize($p) : false;
57 //
58 //                //mail pwd
59 //                $c = DB_DataObject::factory('core_email');
60 //                if (!$c->get('name', 'CORE_PERSON_SIGNUP_CONGRATULATION')) {
61 //                    $this->jerr("can not find template");
62 //                }
63 //                $ret = $c->send(array(
64 //                    'rcpts' => $this->email,
65 //                    'honor' => $this->honor . ". " . $this->lastname,
66 //                    'password' => $temp_pwd
67 //                        ), true);
68 //
69 //                if (is_object($ret)) {
70 //                    return false;
71 //                }
72 //                return true;
73 //            } else {
74 //                return false;
75 //            }
76 //        }
77 //        return false;
78 //    }
79 //
80 //    function convertTo($table) 
81 //    {
82 //        $t = DB_DataObject::factory($table);
83 //        $ret = $t->get('email', $this->email);
84 //        if ($ret != 0) {
85 //            return false;
86 //        } else {
87 //            $t->setFrom(array(
88 //                'honor' => $this->honor,
89 //                'name' => $this->name,
90 //                'email' => $this->email,
91 //                'firstname' => $this->firstname,
92 //                'lastname' => $this->lastname,
93 //                'firstname_alt' => $this->firstname_alt,
94 //                'lastname_alt' => $this->lastname_alt));
95 //
96 //            $t->insert();
97 //            return true;
98 //        }
99 //    }
100
101     function convertTo($target = false)
102     {
103         if(!$target){
104             return false;
105         }
106         
107         $roo = HTML_FlexyFramework::get()->page;
108         
109         if($target->get('email', $this->email)){
110             return $target;
111         }
112         
113         $target->setFrom($this->toArray());
114         
115         $target->insert();
116         
117         $this->person_id = $target->id;
118         $this->person_table = $target->tableName();
119         $this->update();
120         // ok - deleting might not be a great idea.... - as we can not track already confirmed codes..
121         
122         //$this->delete();
123         
124         return $target;
125     }
126     
127     function sendVerification($template, $roo)
128     {
129         
130         $content = array(
131             'template'      => $template,
132             'person'        => $this,
133             'serverName'    => $_SERVER['SERVER_NAME'],
134             'baseURL'       => $roo->baseURL
135         );
136
137         $sent = DB_DataObject::factory('core_email')->send($content);
138         
139         if(!is_object($sent)){
140             return true;
141         }
142         
143         return $sent;
144     }
145     
146     function getEmailFrom()
147     {
148         if (empty($this->name)) {
149             return $this->email;
150         }
151         return '"' . addslashes($this->name) . '" <' . $this->email . '>';
152     }
153 }
154