Пример #1
0
 public function actionNew()
 {
     $model = new Contacts();
     $attributeLabels = $model->attributeLabels();
     /*if(isset($_POST['ajax']) && $_POST['ajax']=='quick-contact-form') {
     			echo CActiveForm::validate($model);
     			Yii::app()->end();
     		}*/
     // collect user input data
     if (isset($_POST['Contacts'])) {
         // $this->redirect('http://www.google.com/');
         //$model->attributes = $_POST['Contacts'];
         $model->setX2Fields($_POST['Contacts']);
         //
         // $model->firstName = 'bob';
         // $model->lastName = 'dole';
         // $model->phone = '';
         // $model->email = '';
         $model->visibility = 1;
         // reset to blank if it's the default value
         /*if($model->firstName == $attributeLabels['firstName'])
         			$model->firstName = '';
         		if($model->lastName == $attributeLabels['lastName'])
         			$model->lastName = '';
         		if($model->phone == $attributeLabels['phone'])
         			$model->phone = '';
         		if($model->email == $attributeLabels['email'])
         			$model->email = '';*/
         $model->createDate = time();
         // validate user input and save contact
         if ($model->save()) {
             echo "1";
             $this->redirect(array('/mobile/contacts/view', 'id' => $model->id));
         }
         //else print_r($model->getErrors());
     }
     $this->render('quickContact', array('model' => $model));
 }
Пример #2
0
 /**
  * Test setting default values in new records
  */
 public function testDefaultValues()
 {
     foreach (X2Model::model('Contacts')->getFields() as $field) {
         // Retrieve new values:
         $field->refresh();
     }
     // Setting default values in the constructor
     $contact = new Contacts();
     $this->assertEquals('Gustavo', $contact->firstName);
     $this->assertEquals('Fring', $contact->lastName);
     // Setting default values in setX2Fields
     $contact->firstName = '';
     $contact->lastName = '';
     $input = array();
     $contact->setX2Fields($input);
     $this->assertEquals('Gustavo', $contact->firstName);
     $this->assertEquals('Fring', $contact->lastName);
 }
Пример #3
0
 /**
  * Method of creating a Contact called by the Quick Create widget
  */
 public function actionQuickContact()
 {
     $model = new Contacts();
     // collect user input data
     if (isset($_POST['Contacts'])) {
         // clear values that haven't been changed from the default
         //$temp=$model->attributes;
         $model->setX2Fields($_POST['Contacts']);
         $model->visibility = 1;
         // validate user input and save contact
         // $changes = $this->calculateChanges($temp, $model->attributes, $model);
         // $model = $this->updateChangelog($model, $changes);
         $model->createDate = time();
         //if($model->validate()) {
         if ($model->save()) {
         } else {
             //echo CHtml::errorSummary ($model);
             echo CJSON::encode($model->getErrors());
         }
         return;
         //}
         //echo '';
         //echo CJSON::encode($model->getErrors());
     }
     $this->renderPartial('application.components.views.quickContact', array('model' => $model));
 }
Пример #4
0
 public function actionCreateRecords()
 {
     $contact = new Contacts();
     $account = new Accounts();
     $opportunity = new Opportunity();
     $users = User::getNames();
     if (isset($_POST['Contacts']) && isset($_POST['Accounts']) && isset($_POST['Opportunity'])) {
         $contact->setX2Fields($_POST['Contacts']);
         $account->setX2Fields($_POST['Accounts']);
         $opportunity->setX2Fields($_POST['Opportunity']);
         $validAccount = true;
         if ($account->validate() == false) {
             $validAccount = false;
             // validate other models so that the user gets feedback
             $contact->validate();
             $opportunity->validate();
         }
         if ($validAccount) {
             $allValid = true;
             $a = $this->createAccount($account, $account->attributes, '1');
             // Contact and Opportunity require Account id for lookup field
             $contact->company = Fields::nameId($account->name, $account->id);
             if ($contact->validate() == false) {
                 $allValid = false;
             }
             $c = $this->createContact($contact, $contact->attributes, '1');
             $opportunity->accountName = Fields::nameId($account->name, $account->id);
             $opportunity->contactName = Fields::nameId($contact->name, $contact->id);
             if ($opportunity->validate() == false) {
                 $allValid = false;
             }
             $o = $this->createOpportunity($opportunity, $opportunity->attributes, '1');
             if ($allValid && $c && $a && $o) {
                 // all records created?
                 Relationships::create('Contacts', $contact->id, 'Accounts', $account->id);
                 Relationships::create('Opportunity', $opportunity->id, 'Contacts', $contact->id);
                 Relationships::create('Opportunity', $opportunity->id, 'Accounts', $account->id);
                 if (isset($_GET['ret'])) {
                     if ($_GET['ret'] == 'contacts') {
                         $this->redirect(array("/contacts/contacts/view", 'id' => $contact->id));
                     } else {
                         if ($_GET['ret'] == 'accounts') {
                             $this->redirect(array("/accounts/accounts/view", 'id' => $account->id));
                         } else {
                             if ($_GET['ret'] == 'opportunities') {
                                 $this->redirect(array("/opportunities/opportunities/view", 'id' => $opportunity->id));
                             }
                         }
                     }
                 } else {
                     $this->redirect(array("/contacts/contacts/view", $contact->id));
                 }
             } else {
                 // otherwise clean up
                 $types = array('account' => 'Accounts', 'contact' => 'Contacts', 'opportunity' => 'Opportunity');
                 foreach ($types as $model => $type) {
                     if (${$model} && isset(${$model}->id)) {
                         $modelId = ${$model}->id;
                         ${$model}->delete();
                         // delete all new actions and events from creating/deleting records
                         foreach (array('Actions', 'Events') as $meta) {
                             X2Model::model($meta)->deleteAllByAttributes(array('associationId' => $modelId, 'associationType' => $type));
                         }
                     }
                 }
             }
         }
     }
     $this->render('createRecords', array('contact' => $contact, 'account' => $account, 'opportunity' => $opportunity, 'users' => $users));
 }
Пример #5
0
 public function actionCreate()
 {
     $model = new Contacts();
     $name = 'Contacts';
     $users = User::getNames();
     $accounts = Accounts::getNames();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Contacts'])) {
         $model->setX2Fields($_POST['Contacts']);
         /*// clear values that haven't been changed from the default
         		 foreach($_POST['Contacts'] as $name => &$value) {
         			if($value == $model->getAttributeLabel($name))
         				$value = '';
         		}
         		foreach($_POST as $key=>$arr){
         			$pieces=explode("_",$key);
         			if(isset($pieces[0]) && $pieces[0]=='autoselect'){
         				$newKey=$pieces[1];
         				if(isset($_POST[$newKey."_id"]) && $_POST[$newKey."_id"]!=""){
         					$val=$_POST[$newKey."_id"];
         				}else{
         					$field=Fields::model()->findByAttributes(array('fieldName'=>$newKey));
         					if(isset($field)){
         						$type=ucfirst($field->linkType);
         						if($type!="Contacts"){
         							eval("\$lookupModel=$type::model()->findByAttributes(array('name'=>'$arr'));");
         						}else{
         							$names=explode(" ",$arr);
         							if(count($names)>1) 
         								$lookupModel=Contacts::model()->findByAttributes(array('firstName'=>$names[0],'lastName'=>$names[1]));
         						}
         						if(isset($lookupModel))
         							$val=$lookupModel->id;
         						else
         							$val=$arr;
         					}
         				}
         				$model->$newKey=$val;
         			}
         		}
         		
         		$temp=$model->attributes;
         		foreach(array_keys($model->attributes) as $field){
         			if(isset($_POST['Contacts'][$field])){
         				$model->$field=$_POST['Contacts'][$field];
         				$fieldData=Fields::model()->findByAttributes(array('modelName'=>'Contacts','fieldName'=>$field));
         				if($fieldData->type=='assignment' && $fieldData->linkType=='multiple'){
         					$model->$field=Accounts::parseUsers($model->$field);
         				}elseif($fieldData->type=='date'){
         					$model->$field=strtotime($model->$field);
         				}
         				
         			}
         		}
         		if(!isset($model->visibility))
         			$model->visibility=1; */
         $this->create($model, $model->attributes, '0');
     }
     $this->render('create', array('model' => $model, 'users' => $users, 'accounts' => $accounts));
 }