コード例 #1
0
ファイル: Credentials.php プロジェクト: keyeMyria/CRM
 /**
  * @param CModel $model Model whose attribute is being used to specify a set of credentials
  * @param string $name Attribute storing the ID of the credentials record
  * @param string $type Keyword specifying the "service type" (i.e. "email" encompasess 
  *  credentials 
  *  with modelClass "EmailAccount" and "GMailAccount"
  * @param integer $uid The user ID or system role ID for which the input is being generated
  * @param array $htmlOptions HTML options to pass to {@link CHtml::activeDropDownList()}
  * @param boolean $getNameEmailsArr if true, returned array will include array indexed by 
  *  credId which 
  *  contains associated email and name
  * @return array containing values which can be used to instantiate an activeDropDownList.
  *  This inludes an array of credential names as well an array of the options' selected 
  *  attributes.
  */
 public static function getCredentialOptions($model, $name, $type = 'email', $uid = null, $htmlOptions = array(), $excludeLegacy = false, $imapOnly = false)
 {
     // First get credentials available to the user:
     $defaultUserId = in_array($uid, self::$sysUseId) ? $uid : ($uid !== null ? $uid : Yii::app()->user->id);
     // The "user" (actual user or system role)
     $uid = Yii::app()->user->id;
     // The actual user
     // Users can always use their own credentials, it's assumed
     $criteria = new CDbCriteria(array('params' => array(':uid' => $uid)));
     $staticModel = self::model();
     $staticModel->userId = self::SYS_ID;
     $criteria->addCondition('userId=:uid');
     // Exclude accounts types that do not support IMAP if requested
     if ($imapOnly) {
         $criteria->addInCondition('modelClass', self::$imapModels);
     }
     // Include system-owned credentials
     if (Yii::app()->user->checkAccess('CredentialsSelectSystemwide', array('model' => $staticModel))) {
         $criteria->addCondition('userId=' . self::SYS_ID, 'OR');
     } else {
         // Select the user's own default
         $defaultUserId = $uid;
     }
     $staticModel->private = 0;
     // Include non-private credentials if the user has access to them
     if (Yii::app()->user->checkAccess('CredentialsSelectNonPrivate', array('model' => $staticModel))) {
         $criteria->addCondition('private=0', 'OR');
     }
     /* Cover only credentials for the given type of third-party service for which the selector 
        field is being used: */
     $criteria->addInCondition('modelClass', $staticModel->defaultSubstitutes[$type]);
     $credRecords = $staticModel->findAll($criteria);
     $credentials = array();
     if ($model === null || $model->{$name} == null) {
         // Figure out which one is default since it hasn't been set yet
         $defaultCreds = $staticModel->getDefaultCredentials();
         if ($type == 'email') {
             $selectedCredentials = self::LEGACY_ID;
         }
         if (array_key_exists($defaultUserId, $defaultCreds)) {
             if (array_key_exists($type, $defaultCreds[$defaultUserId])) {
                 $selectedCredentials = $defaultCreds[$defaultUserId][$type];
             }
         }
     } else {
         // Use the one previously set
         $selectedCredentials = $model->{$name};
     }
     // Compose options for the selector
     foreach ($credRecords as $cred) {
         $credentials[$cred->id] = $cred->name;
         if ($type == 'email') {
             $credentials[$cred->id] = Formatter::truncateText($credentials[$cred->id] . ' : "' . $cred->auth->senderName . '" <' . $cred->auth->email . '>', 50);
         }
     }
     if ($type == 'email' && !$excludeLegacy) {
         // Legacy email delivery method(s)
         $credentials[self::LEGACY_ID] = Yii::t('app', 'System default (legacy)');
     }
     $options = array();
     $selectedOption = $selectedCredentials;
     foreach ($credentials as $credId => $label) {
         if ($credId == $selectedCredentials) {
             $options[$credId] = array('selected' => 'selected');
         } else {
             $options[$credId] = array('selected' => false);
         }
     }
     if ($type == 'email') {
         $options[self::LEGACY_ID]['class'] = 'legacy-email';
     }
     $htmlOptions['options'] = $options;
     $retDict = array('credentials' => $credentials, 'htmlOptions' => $htmlOptions, 'selectedOption' => $selectedOption);
     return $retDict;
 }
コード例 #2
0
ファイル: Actions.php プロジェクト: tymiles003/X2CRM
 public function getName()
 {
     if (!empty($this->subject)) {
         return $this->subject;
     } else {
         if ($this->type == 'email') {
             return Formatter::parseEmail($this->actionDescription);
         } else {
             return Formatter::truncateText($this->actionDescription, 40);
         }
     }
 }
コード例 #3
0
ファイル: FileUtilTest.php プロジェクト: tymiles003/X2CRM
 /**
  * Make sure ccopy can properly create subdirectories and follows all
  * expected behavior.
  *
  * Note, per the specification of ccopy, relTarget cannot be enabled when
  * the target path given is relative. When $C, test-FileUtil-subdir should
  * be filled with the contents of the test directory. When not $C, it should
  * contain a copy of the test directory itself.
  *
  * @param bool $SR source path given is relative
  * @param bool $TR target path given is relative
  * @param bool $RT enable $relTarget argument
  * @param bool $C enbale $contents argument
  * @param bool $tss include trailing slash in the source path
  * @param bool $tst include trailing slash in the target path
  */
 public function assertRecursiveCcopy($SR, $TR, $RT, $C, $tss, $tst)
 {
     // A thing to note: the current working directory is protected/tests
     $relSource = implode(DIRECTORY_SEPARATOR, array('data', 'output', 'test-' . $this->testTime));
     $absSource = realpath('.') . DIRECTORY_SEPARATOR . $relSource;
     $relTarget = implode(DIRECTORY_SEPARATOR, array('..', 'test-FileUtil', 'test-FileUtil-subdir'));
     $absTarget = implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, 'test-FileUtil', 'test-FileUtil-subdir'));
     $source = $SR ? $relSource : $absSource;
     $target = $TR ? $relTarget : $absTarget;
     $source .= $tss ? DIRECTORY_SEPARATOR : '';
     $target .= $tst ? DIRECTORY_SEPARATOR : '';
     // Run the copy operation:
     if (self::CCOPY_VERBOSE) {
         echo "copying " . Formatter::truncateText($source) . " to " . Formatter::truncateText($target);
     }
     FileUtil::ccopy($source, $target, $RT, $C);
     $basePath = $target;
     if (!$C) {
         $basePath = rtrim($basePath, DIRECTORY_SEPARATOR);
         $basePath .= DIRECTORY_SEPARATOR . 'test-' . $this->testTime;
     }
     // Check that the base path was copied:
     $this->assertTrue(is_dir($basePath), "Target base path {$basePath} not created.");
     foreach (array_merge($this->files, $this->subDirs) as $path) {
         $this->assertFileExists($basePath . DIRECTORY_SEPARATOR . FileUtil::rpath($path), "File/directory {$path} not copied.");
     }
     // Done.
     FileUtil::rrmdir(implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, 'test-FileUtil')));
 }