示例#1
0
 public static function generateCode()
 {
     if (!self::$_codes) {
         self::$_codes = ArrayHelper::getColumn(self::find()->select('code')->all(), 'code');
     }
     $chars = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
     $code = '';
     $generated = false;
     while (!$generated) {
         for ($j = 0; $j < 4; $j++) {
             $r = rand(0, count($chars) - 1);
             $code .= $chars[$r];
         }
         if (!in_array($code, self::$_codes)) {
             $generated = true;
         } else {
             $code = '';
         }
     }
     return $code;
 }
示例#2
0
 private static function _loadVoted()
 {
     self::$_voted = array_map(function ($a) {
         return $a['snippet_id'];
     }, Vote::find()->select('snippet_id')->where(['ip' => ip2long(Yii::$app->request->userIP), 'fingerprint' => md5(Yii::$app->request->userAgent)])->asArray()->all());
 }