Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new X2Leads();
     $users = User::getNames();
     foreach (Groups::model()->findAll() as $group) {
         $users[$group->id] = $group->name;
     }
     unset($users['admin']);
     unset($users['']);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['X2Leads'])) {
         $temp = $model->attributes;
         $model->setX2Fields($_POST['X2Leads']);
         if (isset($_POST['x2ajax'])) {
             $ajaxErrors = $this->quickCreate($model);
         } else {
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     if (isset($_POST['x2ajax'])) {
         $this->renderInlineCreateForm($model, isset($ajaxErrors) ? $ajaxErrors : false);
     } else {
         $this->render('create', array('model' => $model, 'users' => $users));
     }
 }
Exemplo n.º 2
0
 public static function getNames()
 {
     $arr = X2Leads::model()->findAll();
     $names = array(0 => 'None');
     foreach ($arr as $x2Leads) {
         $names[$x2Leads->id] = $x2Leads->name;
     }
     return $names;
 }
Exemplo n.º 3
0
 protected function assertLeadNotCreated()
 {
     $lead = X2Leads::model()->findByAttributes(array('name' => 'test test', 'leadSource' => 'Facebook'));
     $this->assertTrue($lead === null);
     return $lead;
 }
 public function testLeadToOpportunity()
 {
     $lead = $this->x2Leads('1');
     $this->assertConversionCompatibility($lead, 'Opportunity');
     $leadAttrs = $lead->getAttributes();
     AuxLib::debugLogR('$leadAttrs = ');
     AuxLib::debugLogR($leadAttrs);
     $contact = $lead->convert('Opportunity');
     AuxLib::debugLogR('$contact = ');
     AuxLib::debugLogR($contact);
     $targetAttrs = $contact->getAttributes();
     $conversionBehavior = X2Leads::model()->asa('X2ModelConversionBehavior');
     $fieldMap = $conversionBehavior->getFieldMap('Opportunity');
     unset($leadAttrs['id']);
     unset($leadAttrs['nameId']);
     unset($leadAttrs['createDate']);
     $mappedFields = $conversionBehavior->mapFields($leadAttrs, 'Opportunity', true);
     foreach ($mappedFields as $attr => $val) {
         $this->assertEquals($val, $targetAttrs[$attr]);
     }
 }
Exemplo n.º 5
0
 /**
  * Creates a new lead and associates it with the contact
  * @param Contacts $contact
  * @param null|string $leadSource
  */
 private static function generateLead(Contacts $contact, $leadSource = null)
 {
     $lead = new X2Leads('webForm');
     $lead->firstName = $contact->firstName;
     $lead->lastName = $contact->lastName;
     $lead->leadSource = $leadSource;
     // disable validation to prevent saving from failing if leadSource isn't set
     if ($lead->save(false)) {
         Relationships::create('X2Leads', $lead->id, 'Contacts', $contact->id);
     }
 }