iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/install/ -> UserDemoData.php (source)

   1  <?php
   2  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   3  /*
   4   * Creates demo data for the user table
   5   *
   6   * SugarCRM is a customer relationship management program developed by
   7   * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
   8   * 
   9   * This program is free software; you can redistribute it and/or modify it under
  10   * the terms of the GNU General Public License version 3 as published by the
  11   * Free Software Foundation with the addition of the following permission added
  12   * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13   * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14   * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15   * 
  16   * This program is distributed in the hope that it will be useful, but WITHOUT
  17   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  19   * details.
  20   * 
  21   * You should have received a copy of the GNU General Public License along with
  22   * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24   * 02110-1301 USA.
  25   * 
  26   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28   * 
  29   * The interactive user interfaces in modified source and object code versions
  30   * of this program must display Appropriate Legal Notices, as required under
  31   * Section 5 of the GNU General Public License version 3.
  32   * 
  33   * In accordance with Section 7(b) of the GNU General Public License version 3,
  34   * these Appropriate Legal Notices must retain the display of the "Powered by
  35   * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  36   * technical reasons, the Appropriate Legal Notices must display the words
  37   * "Powered by SugarCRM".
  38   */
  39  
  40  
  41  
  42  class UserDemoData {
  43      var $_user;
  44      var $_large_scale_test;
  45      var $guids = array(
  46          'jim'    => 'seed_jim_id',
  47          'sarah'    => 'seed_sarah_id',
  48          'sally'    => 'seed_sally_id',
  49          'max'    => 'seed_max_id',
  50          'will'    => 'seed_will_id',
  51          'chris'    => 'seed_chris_id',
  52      /*
  53       * Pending fix of demo data mechanism
  54          'jim'    => 'jim00000-0000-0000-0000-000000000000',
  55          'sarah'    => 'sarah000-0000-0000-0000-000000000000',
  56          'sally'    => 'sally000-0000-0000-0000-000000000000',
  57          'max'    => 'max00000-0000-0000-0000-000000000000',
  58          'will'    => 'will0000-0000-0000-0000-000000000000',
  59          'chris'    => 'chris000-0000-0000-0000-000000000000',
  60      */
  61      );
  62      
  63      /**
  64       * Constructor for creating user demo data
  65       */
  66  	function UserDemoData($seed_user, $large_scale_test = false)
  67      {
  68          // use a seed user so it does not have to be known which file to
  69          // include the User class from
  70          $this->_user = $seed_user;
  71          $this->_large_scale_test = $large_scale_test;
  72      }
  73      
  74      /**
  75       * 
  76       */
  77  	function create_demo_data() 
  78      {
  79          global $current_language;
  80          global $sugar_demodata;
  81          foreach($sugar_demodata['users'] as $v)
  82          {
  83              $this->_create_seed_user($v['id'], $v['last_name'], $v['first_name'], $v['user_name'], $v['title'], $v['is_admin'], $v['reports_to'], $v['reports_to_name'], $v['email']);
  84                  
  85          }
  86          if($this->_large_scale_test) {
  87              $user_list = $this->_seed_data_get_user_list();
  88              foreach($user_list as $user_name)
  89              {
  90                  $this->_quick_create_user($user_name);
  91              }
  92          }
  93      }
  94  
  95  
  96      /**
  97       *  Create a user in the seed data.
  98       */
  99  	function _create_seed_user($id, $last_name, $first_name, $user_name,
 100          $title, $is_admin, $reports_to, $reports_to_name, $email)
 101      {
 102          $u = new User();
 103          
 104          $u->id=$id;
 105          $u->new_with_id = true;
 106          $u->last_name = $last_name;
 107          $u->first_name = $first_name;
 108          $u->user_name = $user_name;
 109          $u->title = $title;
 110          $u->status = 'Active';
 111          $u->employee_status = 'Active';
 112          $u->is_admin = $is_admin;
 113          //$u->user_password = $u->encrypt_password($user_name);
 114          $u->user_hash = strtolower(md5($user_name));
 115          $u->reports_to_id = $reports_to;
 116          $u->reports_to_name = $reports_to_name;
 117          //$u->email1 = $email;
 118          $u->emailAddress->addAddress($email, true);
 119          $u->emailAddress->addAddress("reply.".$email, false, true);
 120          $u->emailAddress->addAddress("alias.".$email);
 121          
 122          // bug 15371 tyoung set a user preference so that Users/DetailView.php can find something without repeatedly querying the db in vain
 123          $u->setPreference('max_tabs','12'); 
 124          UserPreference::savePreferencesToDB($u,true);
 125          
 126          $u->save();
 127      }
 128      
 129      /**
 130       * 
 131       */
 132  	function _seed_data_get_user_list()
 133      {
 134          $users = Array();
 135  //bug 28138 todo
 136          $users[] = "north";
 137          $users[] = "south";
 138          $users[] = "east";
 139          $users[] = "west";
 140          $users[] = "left";
 141          $users[] = "right";
 142          $users[] = "in";
 143          $users[] = "out";
 144          $users[] = "fly";
 145          $users[] = "walk";
 146          $users[] = "crawl";
 147          $users[] = "pivot";
 148          $users[] = "money";
 149          $users[] = "dinero";
 150          $users[] = "shadow";
 151          $users[] = "roof";
 152          $users[] = "sales";
 153          $users[] = "pillow";
 154          $users[] = "feather";
 155  
 156          return $users;
 157      }
 158      
 159      /**
 160       * 
 161       */
 162  	function _quick_create_user($name)
 163      {
 164          global $sugar_demodata;
 165          if (!$this->_user->retrieve($name.'_id'))
 166          {
 167              $this->_create_seed_user("{$name}_id", $name, $name, $name,
 168                  $sugar_demodata['users'][0]['title'], $sugar_demodata['users'][0]['is_admin'], "seed_jim_id", $sugar_demodata['users'][0]['last_name'].", ".$sugar_demodata['users'][0]['first_name'], $sugar_demodata['users'][0]['email']);
 169          }
 170      }
 171      
 172  }
 173  ?>


Generé en: Thu Mar 4 09:44:50 2010 | Cross-referenced par PHPXref 0.7