DataObjects/Core_person_signup.php
[Pman.Core] / DataObjects / Core_person_signup.php
index c13b74c..cb996cd 100644 (file)
@@ -1,10 +1,10 @@
- <?php
+<?php
+
 /**
  * Table Definition for Person
  */
 require_once 'DB/DataObject.php';
 
-
 class Pman_Core_DataObjects_Core_person_signup extends DB_DataObject 
 {
     ###START_AUTOCODE
@@ -13,24 +13,88 @@ class Pman_Core_DataObjects_Core_person_signup extends DB_DataObject
     public $__table = 'core_person_signup';                          // table name
     public $id;                              // int(11)  not_null primary_key auto_increment
     public $email;                           // string(128)  not_null
-    
     public $name;                            // string(128)  not_null
     public $firstname;                            // string(128)  not_null
     public $lastname;                            // string(128)  not_null
     public $firstname_alt;                            // string(128)  not_null
     public $lastname_alt;                            // string(128)  not_null
-    
-    
     public $honor;                            // string(128)  not_null
     public $verify_key;                      // int(11)
-
-    
-
+    public $verified;
     public $created_dt;                      // datetime(19)  binary
-
+    public $company_name;
+    public $person_type;
     
+    public $person_id;
+    public $person_table;
     
+    public $invite_id;
+    public $friend_table;
+    function convertTo($target = false)
+    {
+        if(!$target){
+            return false;
+        }
+        
+        $roo = HTML_FlexyFramework::get()->page;
+        $old = clone($this);
+        // this shold not really happen...
+        if($target->get('email', $this->email)){
+            
+            $this->person_id = $target->id;
+            $this->person_table = $target->tableName();
+            $this->update($old);
+            
+            return $target;
+        }
+        
+        $target->setFrom($this->toArray());
+        
+        $target->insert();
+        
+        $this->person_id = $target->id;
+        $this->person_table = $target->tableName();
+        $this->update($old);
+        
+        if(!empty($this->invite_id) && !empty($this->friend_table)){
+            $friend = DB_DataObject::factory($this->friend_table);
+            $friend->setFrom(array(
+                'person_id' => $this->invite_id,
+                'friend_id' => $target->id
+            ));
+            
+            $friend->insert();
+        }
+        
+        return $target;
+    }
+    
+    function sendVerification($template, $roo)
+    {
+        
+        $content = array(
+            'template'      => $template,
+            'person'        => $this,
+            'serverName'    => $_SERVER['SERVER_NAME'],
+            'baseURL'       => $roo->baseURL
+        );
+
+        $sent = DB_DataObject::factory('core_email')->send($content);
+        
+        if(!is_object($sent)){
+            return true;
+        }
+        
+        return $sent;
+    }
     
+    function getEmailFrom()
+    {
+        if (empty($this->name)) {
+            return $this->email;
+        }
+        return '"' . addslashes($this->name) . '" <' . $this->email . '>';
+    }
 }
 
-    
\ No newline at end of file