/**
  * do conversions (transformations, charset, replacements ...)
  *
  * @param array $_data
  * @return array
  *
  * TODO think about moving this to import definition
  * TODO simplify crm/lead config handling for leadstate/source/type
  */
 protected function _doConversions($_data)
 {
     $data = parent::_doConversions($_data);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($data, true));
     }
     // adjust lead_name/leadstate/source/types if missing
     $configSettings = Crm_Controller::getInstance()->getConfigSettings()->toArray();
     $requiredFields = array('leadstate_id' => 'leadstates', 'leadtype_id' => 'leadtypes', 'leadsource_id' => 'leadsources');
     foreach ($requiredFields as $requiredField => $configKey) {
         if (!empty($data[$requiredField])) {
             continue;
         }
         switch ($requiredField) {
             default:
                 // get default leadstate/source/type OR try to find it by name if given
                 if (!isset($configSettings[$configKey])) {
                     continue;
                 }
                 $settingField = preg_replace('/s$/', '', $configKey);
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' config settings' . print_r($configSettings[$configKey], true));
                 }
                 // init with default
                 $data[$requiredField] = isset($configSettings[$configKey][0]['id']) ? $configSettings[$configKey][0]['id'] : 1;
                 foreach ($configSettings[$configKey] as $setting) {
                     if (isset($setting[$settingField]) && isset($_data[$settingField]) && strtolower($setting[$settingField]) === strtolower($_data[$settingField])) {
                         $data[$requiredField] = $setting['id'];
                     }
                 }
         }
     }
     return $data;
 }
 /**
  * do conversions
  *
  * @param array $_data
  * @return array
  */
 protected function _doConversions($_data)
 {
     $result = parent::_doConversions($_data);
     if ((isset($result['warranty']) || array_key_exists('warranty', $result)) && empty($_data['warranty'])) {
         unset($result['warranty']);
     }
     if ((isset($result['invoice_date']) || array_key_exists('invoice_date', $result)) && empty($_data['invoice_date'])) {
         unset($result['invoice_date']);
     }
     if ((isset($result["name"]) || array_key_exists("name", $result)) && $result['name'] == "") {
         $result['name'] = "!Not defined!";
     }
     if ((isset($result["inventory_id"]) || array_key_exists("inventory_id", $result)) && $result['inventory_id'] == "") {
         $result['inventory_id'] = Tinebase_Record_Abstract::generateUID(40);
     }
     if (isset($result["costcentre"]) || array_key_exists("costcentre", $result)) {
         $result["costcentre"] = $c = Sales_Controller_CostCenter::getInstance()->search(new Sales_Model_CostCenterFilter(array(array('field' => 'number', 'operator' => 'equals', 'value' => $result["costcentre"]))))->getFirstRecord();
     }
     if (isset($result["status"]) || array_key_exists("status", $result)) {
         $statusRecord = Inventory_Config::getInstance()->get(Inventory_Config::INVENTORY_STATUS)->getKeyfieldRecordByValue($result["status"]);
         if (empty($statusRecord)) {
             $statusRecord = Inventory_Config::getInstance()->get(Inventory_Config::INVENTORY_STATUS)->getKeyfieldDefault();
         }
         $result["status"] = $statusRecord['id'];
     }
     return $result;
 }
 /**
  * do conversions
  * -> sanitize account_id
  *
  * @param array $_data
  * @return array
  */
 protected function _doConversions($_data)
 {
     $result = parent::_doConversions($_data);
     // unset account id
     if (isset($result['account_id']) && empty($result['account_id'])) {
         unset($result['account_id']);
     }
     if (empty($result['n_family']) && empty($result['org_name'])) {
         if (isset($result['n_fn'])) {
             $result['n_family'] = $result['n_fn'];
         } else {
             $result['n_family'] = 'imported';
         }
     }
     return $result;
 }
 /**
  * do conversions (transformations, charset, replacements ...)
  *
  * @param array $_data
  * @return array
  *
  * TODO think about moving this to import definition
  */
 protected function _doConversions($_data)
 {
     $data = parent::_doConversions($_data);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($data, true));
     }
     // adjust lead_name/leadstate/source/types if missing
     $keyFields = array(Crm_Config::LEAD_STATES => 'leadstate_id', Crm_Config::LEAD_TYPES => 'leadtype_id', Crm_Config::LEAD_SOURCES => 'leadsource_id');
     foreach ($keyFields as $keyFieldName => $fieldName) {
         $keyField = Crm_Config::getInstance()->get($keyFieldName);
         if (isset($data[$fieldName])) {
             $data[$fieldName] = $keyField->getIdByTranslatedValue($data[$fieldName]);
         } else {
             $data[$fieldName] = $keyField->getKeyfieldDefault()->getId();
         }
     }
     return $data;
 }
 /**
  * import single record (create password if in data)
  *
  * @param Tinebase_Record_Abstract $_record
  * @param string $_resolveStrategy
  * @param array $_recordData
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_Record_Validation
  */
 protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array())
 {
     $admCfg = Tinebase_Core::getConfig()->get('Admin');
     $excludeGroups = array();
     $be = new Tinebase_Group_Sql();
     $members = explode(' ', $_record->members);
     $_record->members = null;
     unset($_record->members);
     $this->_setController();
     try {
         $group = $be->getGroupByName($_record->name);
     } catch (Tinebase_Exception_Record_NotDefined $e) {
         $group = NULL;
         parent::_importRecord($_record, $_resolveStrategy, $_recordData);
     }
     if ($group) {
         $this->_handleGroupMemberShip($group, $members);
     } else {
         $group = Admin_Controller_Group::getInstance()->get($_record->getId());
         $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
         $group->list_id = $list->getId();
         $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED;
         $be->updateGroupInSqlBackend($group);
         $memberUids = array();
         if (!empty($members)) {
             $users = $this->_resolveUsers($members);
             foreach ($users as $userId) {
                 try {
                     $be->addGroupMember($_record->getId(), $userId);
                 } catch (Exception $e) {
                 }
             }
         }
     }
     return $group;
 }
 protected function _doMapping($_data)
 {
     $result = parent::_doMapping($_data);
     $result['smtpUser'] = array('emailForwardOnly' => isset($_recordData['emailForwardOnly']) ? $_recordData['emailForwardOnly'] : true, 'emailForwards' => isset($result['emailForwards']) && !empty($result['emailForwards']) ? explode(' ', trim($result['emailForwards'])) : array(), 'emailAliases' => isset($result['emailAliases']) ? explode(' ', trim($result['emailAliases'])) : array());
     $result['groups'] = !empty($result['groups']) ? array_map('trim', explode(",", $result['groups'])) : array();
     $result['samba'] = array('homePath' => isset($result['homePath']) ? stripslashes($result['homePath']) : '', 'homeDrive' => isset($result['homeDrive']) ? stripslashes($result['homeDrive']) : '', 'logonScript' => isset($result['logonScript']) ? $result['logonScript'] : '', 'profilePath' => isset($result['profilePath']) ? stripslashes($result['profilePath']) : '', 'pwdCanChange' => isset($result['pwdCanChange']) ? new Tinebase_DateTime($result['pwdCanChange']) : '', 'pwdMustChange' => isset($result['pwdMustChange']) ? new Tinebase_DateTime($result['pwdMustChange']) : '');
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * do conversions
  * -> sanitize account_id
  *
  * @param array $_data
  * @return array
  */
 protected function _doConversions($_data)
 {
     $result = parent::_doConversions($_data);
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * add some more values (primary group)
  *
  * @return array
  */
 protected function _addData()
 {
     if ($this->_options['model'] == 'Tinebase_Model_FullUser') {
         if (!empty($this->_options['group_id'])) {
             $groupId = $this->_options['group_id'];
         } else {
             // add default user group
             $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup();
             $groupId = $defaultUserGroup->getId();
         }
         $result = array('accountPrimaryGroup' => $groupId);
     } else {
         $result = parent::_addData();
     }
     return $result;
 }