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     public $invite_id;
32     public $friend_table;
33  
34     function convertTo($target = false)
35     {
36         if(!$target){
37             return false;
38         }
39         
40         $roo = HTML_FlexyFramework::get()->page;
41         $old = clone($this);
42         // this shold not really happen...
43         if($target->get('email', $this->email)){
44             
45             $this->person_id = $target->id;
46             $this->person_table = $target->tableName();
47             $this->update($old);
48             
49             return $target;
50         }
51         
52         $target->setFrom($this->toArray());
53         
54         $target->insert();
55         
56         $this->person_id = $target->id;
57         $this->person_table = $target->tableName();
58         $this->update($old);
59         
60         if(!empty($this->invite_id) && !empty($this->friend_table)){
61             $friend = DB_DataObject::factory($this->friend_table);
62             $friend->setFrom(array(
63                 'person_id' => $this->invite_id,
64                 'friend_id' => $target->id
65             ));
66             
67             $friend->insert();
68         }
69         
70         return $target;
71     }
72     
73     function sendVerification($template, $roo)
74     {
75         
76         $content = array(
77             'template'      => $template,
78             'person'        => $this,
79             'serverName'    => $_SERVER['SERVER_NAME'],
80             'baseURL'       => $roo->baseURL
81         );
82
83         $sent = DB_DataObject::factory('core_email')->send($content);
84         
85         if(!is_object($sent)){
86             return true;
87         }
88         
89         return $sent;
90     }
91     
92     function getEmailFrom()
93     {
94         if (empty($this->name)) {
95             return $this->email;
96         }
97         return '"' . addslashes($this->name) . '" <' . $this->email . '>';
98     }
99 }
100