Beispiel #1
0
 /**
  * Ассоциативный параметр запроса для подстановки вида id in (...)
  * 
  * @param str $name - название параметра
  * @param array $values - массив значений
  * @param type $limit - размер порции
  * @return array
  */
 public static function assocParamsIn($name, array $values, $limit = self::MAX_IDS_CONCAT)
 {
     $limit = PsCheck::positiveInt($limit);
     $values = array_unique($values);
     sort($values);
     $taken = array();
     $params = array();
     foreach ($values as $value) {
         //$taken[] = PsCheck::int($value);
         $taken[] = $value;
         $count = count($taken);
         if ($count >= $limit) {
             switch ($count) {
                 case 1:
                     $params[] = self::assocParam($name, $taken[0]);
                     break;
                 default:
                     $params[] = self::assocParam($name, '(' . implode(',', array_fill(0, $count, '?')) . ')', false, QueryParamAssoc::OPERATOR_IN, $taken);
                     break;
             }
             $taken = array();
         }
     }
     $count = count($taken);
     switch ($count) {
         case 0:
             break;
         case 1:
             $params[] = self::assocParam($name, $taken[0]);
             break;
         default:
             $params[] = self::assocParam($name, '(' . implode(',', array_fill(0, $count, '?')) . ')', false, QueryParamAssoc::OPERATOR_IN, $taken);
             break;
     }
     return $params;
 }
 public function __construct()
 {
     $this->loggedIn = is_user_logged_in();
     $this->userId = $this->loggedIn ? PsCheck::positiveInt(get_current_user_id()) : null;
     $this->loggedInAsAdmin = $this->loggedIn ? is_super_admin($this->userId) : false;
 }