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