public function createRecord(Vtiger_Request $request)
 {
     $user = Users_Record_Model::getCurrentUserModel();
     $moduleName = $request->get('modulename');
     $name = explode("@", $request->get('email'));
     $element['lastname'] = $name[0];
     $element['email'] = $request->get('email');
     $element['phone'] = $request->get('number');
     $element['assigned_user_id'] = vtws_getWebserviceEntityId('Users', $user->id);
     $moduleInstance = Vtiger_Module_Model::getInstance($moduleName);
     $mandatoryFieldModels = $moduleInstance->getMandatoryFieldModels();
     foreach ($mandatoryFieldModels as $mandatoryField) {
         $fieldName = $mandatoryField->get('name');
         $fieldType = $mandatoryField->getFieldDataType();
         $defaultValue = decode_html($mandatoryField->get('defaultvalue'));
         if (!empty($element[$fieldName])) {
             continue;
         } else {
             $fieldValue = $defaultValue;
             if (empty($fieldValue)) {
                 $fieldValue = Vtiger_Util_Helper::getDefaultMandatoryValue($fieldType);
             }
             $element[$fieldName] = $fieldValue;
         }
     }
     $entity = vtws_create($moduleName, $element, $user);
     $this->updateCustomerInPhoneCalls($entity, $request);
     $response = new Vtiger_Response();
     $response->setResult(true);
     $response->emit();
 }
Example #2
0
 function setDefaultValue($module, $moduleObj)
 {
     $moduleInstance = Vtiger_Module_Model::getInstance($module);
     $fieldInstances = Vtiger_Field_Model::getAllForModule($moduleInstance);
     foreach ($fieldInstances as $blockInstance) {
         foreach ($blockInstance as $fieldInstance) {
             $fieldName = $fieldInstance->getName();
             $defaultValue = $fieldInstance->getDefaultFieldValue();
             if ($defaultValue) {
                 $moduleObj->column_fields[$fieldName] = decode_html($defaultValue);
             }
             if ($fieldInstance->isMandatory() && !$defaultValue) {
                 $moduleObj->column_fields[$fieldName] = Vtiger_Util_Helper::getDefaultMandatoryValue($fieldInstance->getFieldDataType());
             }
         }
     }
 }