Esempio n. 1
0
 /**
  * @inheritdoc
  */
 protected function initUserAttributes()
 {
     $data = [];
     foreach (explode(" ", $this->scope) as $scope) {
         if (in_array($scope, $this->_userinfoscopes)) {
             $api = $this->api($scope, 'GET');
             if (ArrayHelper::getValue($api, 'status') !== "ok") {
                 Yii:
                 trace("Server error: " . print_r($api, true));
                 throw new InvalidResponseException($api, "error", print_r($api, true));
             }
             $apiData = ArrayHelper::getValue($api, 'data', []);
             if ($scope === "profile") {
                 if (ArrayHelper::getValue($apiData, 'blacklisted') !== false || ArrayHelper::getValue($apiData, 'quarantine') !== false || ArrayHelper::getValue($apiData, 'verified') !== true) {
                     Yii::trace("OAuth Failed. Provider V. Data: " . print_r($api, true), 'oauth');
                     throw new UserNotAllowedException("User is blacklisted, quarantined or not verified");
                 }
                 if (ArrayHelper::keyExists('enlid', $apiData)) {
                     if (ArrayHelper::getValue($apiData, 'enlid') === "null") {
                         Yii:
                         trace("enlid is null", 'oauth');
                         throw new UserNotAllowedException("Userprofile incomplete");
                     } else {
                         $data['id'] = ArrayHelper::getValue($data, 'enlid');
                     }
                 }
             }
             $data = array_merge($data, $apiData);
         }
     }
     return $data;
 }
 /**
  * @param $name
  * @return Filter
  */
 public function getFilter($name)
 {
     if (!ArrayHelper::keyExists($name, $this->_filters)) {
         $this->addFilter($name);
     }
     return $this->_filters[$name];
 }
 /**
  * Check whether we have a plugin installed with that name previous firing up the call
  *
  * @param string $name
  *
  * @return mixed|void
  */
 public function __get($name)
 {
     if (ArrayHelper::keyExists($name, $this->getInstalledPlugins())) {
         return $this->getPlugin($name);
     }
     return parent::__get($name);
 }
 /**
  * @param $name
  * @return VisioWidget
  */
 public function getWidget($name)
 {
     if (!ArrayHelper::keyExists($name, $this->_widgets)) {
         $this->addWidget($name);
     }
     return $this->_widgets[$name];
 }
Esempio n. 5
0
 /**
  * Add Original Text
  * @param string $text
  * @param int $yandexSiteID
  * @throws InvalidParamException
  * @return string|bool
  */
 public function addOriginalText($text, $yandexSiteID)
 {
     /** @var Cache $cache */
     $cache = \Yii::$app->get($this->cacheComponent);
     $cacheKey = "Yandex_OT_sent:" . $this->clientID . "_" . $this->clientSecret;
     $sent = $cache->get($cacheKey);
     if ($sent === false) {
         $sent = 0;
     }
     if ($sent >= self::YANDEX_OT_DAILY_LIMIT) {
         throw new InvalidParamException("Daily limit exceeded!");
     }
     $validator = new StringValidator(['min' => self::YANDEX_OT_MIN, 'max' => self::YANDEX_OT_MAX, 'enableClientValidation' => false]);
     if (!$validator->validate($text, $error)) {
         throw new InvalidParamException($error);
     }
     $text = urlencode(htmlspecialchars($text));
     $text = "<original-text><content>{$text}</content></original-text>";
     $response = $this->apiClient->rawApi("hosts/{$yandexSiteID}/original-texts/", "POST", $text);
     $success = ArrayHelper::keyExists('id', $response) && ArrayHelper::keyExists('link', $response);
     if ($success) {
         $sent++;
         $cache->set($cacheKey, $sent, 60 * 60 * 24);
     }
     return $success;
 }
Esempio n. 6
0
 public function getSelect2Type()
 {
     if (ArrayHelper::keyExists('ajax', $this->pluginOptions) and $this->pluginOptions['ajax']) {
         return 'ajax';
     }
     return false;
 }
 public function init()
 {
     parent::init();
     if (!ArrayHelper::keyExists('url', $this->clientOptions)) {
         throw \yii\base\InvalidConfigException('Url key is missing in clientOptions');
     }
 }
Esempio n. 8
0
 /**
  * 设置 summernote 配置默认值
  */
 public function setDefault()
 {
     $ary = ['lang' => SELF::LANG_DEFAULT, 'height' => SELF::HEIGHT_DEFAULT];
     foreach ($ary as $k => $v) {
         $this->clientOptions[$k] = ArrayHelper::keyExists($k, $this->clientOptions) ? $this->clientOptions[$k] : $v;
     }
 }
Esempio n. 9
0
 /**
  * отметить как
  * @param $status
  */
 public function markAs($status)
 {
     if (!ArrayHelper::keyExists($status, self::statusNames())) {
         throw new \BadMethodCallException("{$status} not found in status_array");
     }
     $this->status = $status;
     $this->save();
 }
Esempio n. 10
0
 private function requiredCheck()
 {
     foreach ($this->_requiredOptions as $key) {
         if (!ArrayHelper::keyExists($key, $this->_playerOptions, false)) {
             throw new InvalidConfigException("JWPlayer Widget: player options missing '{$key}'");
         }
     }
 }
Esempio n. 11
0
 public static function getActiveUsers()
 {
     $array_ids = static::find()->select(['user_id'])->where('user_id > 0')->asArray()->all();
     $ids = \yii\helpers\ArrayHelper::getColumn($array_ids, 'user_id');
     $users = UserModels::find()->select(['id', 'username'])->where(['IN', 'id', $ids])->asArray()->all();
     if (!ArrayHelper::keyExists('0', $users, false)) {
         $users = [0 => ['id' => '0', 'username' => 'Ninguno']];
     }
     return $users;
 }
Esempio n. 12
0
 /**
  * Возвращает ответ контроллера
  *
  * @param mixed $data возвращаемые данные
  *                    [
  *                    'status' => boolean
  *                    'data' => данные при положительном срабатывании или сообщение об ошибке
  *                    ]
  *
  * @return \yii\web\Response json
  */
 public function jsonController($data)
 {
     if ($data['status']) {
         if (ArrayHelper::keyExists('data', $data)) {
             return self::jsonSuccess($data['data']);
         } else {
             return self::jsonSuccess();
         }
     } else {
         return self::jsonError($data['data']);
     }
 }
Esempio n. 13
0
 /**
  * Inits sortable behavior
  */
 protected function initSortable()
 {
     $route = ArrayHelper::getValue($this->sortable, 'url', false);
     if ($route) {
         $url = Url::toRoute($route);
         if (ArrayHelper::keyExists('class', $this->itemOptions)) {
             $this->itemOptions['class'] = sprintf('%s %s', $this->itemOptions['class'], self::SORTABLE_ITEM_CLASS);
         } else {
             $this->itemOptions['class'] = self::SORTABLE_ITEM_CLASS;
         }
         $options = json_encode(ArrayHelper::getValue($this->sortable, 'options', []));
         $view = $this->getView();
         $view->registerJs("jQuery('#{$this->id}').SortableListView('{$url}', {$options});");
         $view->registerJs("jQuery('#{$this->id}').on('sortableSuccess', function() {jQuery.pjax.reload(" . json_encode($this->clientOptions) . ")})", \yii\web\View::POS_END);
         ListViewSortableAsset::register($view);
     }
 }
 /**
  * Formats response data in JSON format.
  * @link http://jsonapi.org/format/upcoming/#document-structure
  * @param Response $response
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/vnd.api+json; charset=UTF-8');
     if ($response->data !== null) {
         $options = $this->encodeOptions;
         if ($this->prettyPrint) {
             $options |= JSON_PRETTY_PRINT;
         }
         if ($response->isClientError || $response->isServerError) {
             if (ArrayHelper::isAssociative($response->data)) {
                 $response->data = [$response->data];
             }
             $apiDocument = ['errors' => $response->data];
         } elseif (ArrayHelper::keyExists('data', $response->data)) {
             $apiDocument = $response->data;
         } else {
             $apiDocument = ['meta' => $response->data];
         }
         $response->content = Json::encode($apiDocument, $options);
     }
 }
Esempio n. 15
0
 public function indexDataProvider()
 {
     $params = \Yii::$app->request->queryParams;
     $model = new $this->modelClass();
     $modelAttr = $model->attributes;
     $order = isset($params['order']) ? ArrayHelper::keyExists($params['order'], $this->orderParams, false) ? $params['order'] : 'id' : 'id';
     $sort = isset($params['sort']) && ($params['sort'] = 'asc') ? 'ASC' : 'DESC';
     $search = [];
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             if (!is_scalar($key) or !is_scalar($value)) {
                 throw new BadRequestHttpException('Bad Request');
             }
             if (!in_array(strtolower($key), $this->reservedParams) && ArrayHelper::keyExists($key, $modelAttr, false)) {
                 $search[$key] = $value;
             }
         }
     }
     //return $model->find()->where($search)->orderBy([$order => $sort])->limit(10)->all();
     return $model->find()->where($search)->orderBy($order . ' ' . $sort)->limit(20)->all();
 }
 /**
  * Renders the widget.
  * @return string
  */
 public function run()
 {
     if ($this->type == 'list') {
         $items = [];
         foreach ($this->model->options as $option) {
             $items[] = $option->name;
         }
         return $this->render($this->listView, ['items' => $items, 'model' => $this->model]);
     } else {
         $propertyGroup = Json::decode($this->model->option_generate)['group'];
         $items = [];
         $optionsJson = [];
         foreach ($this->model->options as $option) {
             /**
              * @var $option \app\modules\shop\models\Product|\app\properties\HasProperties
              */
             $optionProperties = $option->getPropertyGroups()[$propertyGroup];
             $itemsJson = [];
             foreach ($optionProperties as $key => $property) {
                 foreach ($property->values as $name => $propValue) {
                     if (ArrayHelper::keyExists('property_id', $propValue) === false) {
                         continue;
                     }
                     if (!isset($items[$key])) {
                         $items[$key] = ['name' => Property::findById($propValue['property_id'])->name];
                     }
                     if (!isset($firstOption)) {
                         $firstOption[$key] = $propValue['psv_id'];
                     }
                     $items[$key]['values'][$propValue['psv_id']] = $propValue['name'];
                     $itemsJson[$key] = $propValue['psv_id'];
                 }
             }
             $optionsJson[] = ['id' => $option->id, 'values' => $itemsJson, 'price' => $option->convertedPrice(), 'old_price' => $option->convertedPrice(null, true)];
         }
         return $this->render($this->formView, ['model' => $this->model, 'items' => $items, 'optionsJson' => $optionsJson]);
     }
 }
Esempio n. 17
0
 public function prepareDataProvider()
 {
     $params = \Yii::$app->request->queryParams;
     //print_r($params);die();
     $model = new $this->modelClass();
     // I'm using yii\base\Model::getAttributes() here
     // In a real app I'd rather properly assign
     // $model->scenario then use $model->safeAttributes() instead
     $modelAttr = $model->attributes;
     // this will hold filtering attrs pairs ( 'name' => 'value' )
     $search = [];
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             // In case if you don't want to allow wired requests
             // holding 'objects', 'arrays' or 'resources'
             if (!is_scalar($key) or !is_scalar($value)) {
                 throw new BadRequestHttpException('Bad Request');
             }
             // if the attr name is not a reserved Keyword like 'q' or 'sort' and
             // is matching one of models attributes then we need it to filter results
             if (!in_array(strtolower($key), $this->reservedParams) && ArrayHelper::keyExists($key, $modelAttr, false)) {
                 $search[$key] = $value;
             }
         }
     }
     //print_r($search);die();
     // you may implement and return your 'ActiveDataProvider' instance here.
     // in my case I prefer using the built in Search Class generated by Gii which is already
     // performing validation and using 'like' whenever the attr is expecting a 'string' value.
     $searchByAttr['ProductSearch'] = $search;
     $lat = isset($params['lat']) ? $params['lat'] : 18.509111;
     $lon = isset($params['lon']) ? $params['lon'] : -69.8468487;
     $model = new Articulos();
     $searchModel = $model->listadoPorUbicacion($lat, $lon);
     //$searchModel = Articulos::findOne($search);//new \common\models\ArticulosBuscador();
     //return $searchModel->search($searchByAttr);
     return $searchModel;
 }
Esempio n. 18
0
 /**
  * @param array $rows
  * @return array
  */
 private function convertTreeToFlat($rows)
 {
     $ret = [];
     foreach ($rows as $item) {
         $ret[$item['id']] = $item['name'];
         if (ArrayHelper::keyExists('nodes', $item)) {
             $rows2 = $this->convertTreeToFlat($item['nodes']);
             foreach ($rows2 as $k => $v) {
                 $ret[$k] = '---' . $v;
             }
         }
     }
     return $ret;
 }
 /**
  * @inheritdoc
  */
 public function __get($name)
 {
     // getters go first
     $getter = 'get' . $name;
     if (method_exists($this, $getter)) {
         return $this->{$getter}();
     }
     return ArrayHelper::keyExists($name, $this->options) ? $this->options[$name] : parent::__get($name);
 }
Esempio n. 20
0
 private function checkAccessRecursive($user, $itemName, $params, $assignments)
 {
     $item = $this->getRole($itemName);
     if (!$item) {
         $item = $this->getPermission($itemName);
     }
     if (!$item) {
         throw new InvalidConfigException('Элемент авторизации (роль или право) не найден.');
     }
     if (!$this->executeRule($user, $item, $params)) {
         return false;
     }
     if (isset($assignments[$itemName])) {
         return true;
     }
     foreach ($this->_dag as $parentName => $children) {
         if (ArrayHelper::keyExists($itemName, $children) && $this->checkAccessRecursive($user, $parentName, $params, $assignments)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 21
0
 /**
  * (non-PHPdoc)
  * @see \yii\web\View::registerLinkTag()
  */
 public function registerLinkTag($options, $key = null)
 {
     if (ArrayHelper::keyExists('href', $options)) {
         $options['href'] = \Yii::getAlias($options['href']);
     }
     parent::registerLinkTag($options, $key);
 }
Esempio n. 22
0
 private function drawDetailView_processField($field)
 {
     if (ArrayHelper::keyExists('widget', $field)) {
         $className = ArrayHelper::getValue($field, 'widget.0', '');
         if ($className != '') {
             if (method_exists($className, 'onDraw')) {
                 return $className::onDraw($field, $this);
             }
         }
     }
     if (isset($field['drawDetailView'])) {
         $method = $field['drawDetailView'];
         return call_user_func($method, $this, $field);
     }
     if (ArrayHelper::keyExists('type', $field)) {
         $options = [];
         if (is_array($field['type'])) {
             $name = $field['type'][0];
             if (isset($field['type'][1])) {
                 $options = $field['type'][1];
             }
         } else {
             $name = $field['type'];
         }
         $fieldName = $field[self::POS_DB_NAME];
         switch ($name) {
             case 'place':
                 return \cs\models\Place::initFromModel($this, $fieldName);
             case 'radioList':
                 $value = $this->{$fieldName};
                 return $options[$value];
             case 'file':
                 return \cs\Widget\FileUpload2\FileUpload::drawDetailView($this, $field);
             case 'checkbox':
                 $value = $this->{$fieldName};
                 if (is_null($value)) {
                     return '';
                 }
                 if ($value == 0) {
                     return 'Нет';
                 }
                 if ($value == 1) {
                     return 'Да';
                 }
         }
     }
     if (isset($field[self::POS_RULE])) {
         if ($field[self::POS_RULE] != '') {
             $dbName = $field[self::POS_DB_NAME];
             switch ($field[self::POS_RULE]) {
                 case 'string':
                     return $this->{$dbName};
                 case 'url':
                     return Html::a($this->{$dbName}, $this->{$dbName});
                 case 'integer':
                     return $this->{$dbName};
                 case 'date':
                     return $this->{$dbName};
             }
         }
     }
 }
Esempio n. 23
0
 protected function isItemActive($item)
 {
     if (ArrayHelper::keyExists('active', $item)) {
         return ArrayHelper::remove($item, 'active', false);
     } else {
         return parent::isItemActive($item);
         // TODO: Change the autogenerated stub
     }
 }
Esempio n. 24
0
 /**
  * Renders the closing tag of the field container.
  * @return string the rendering result.
  */
 public function end()
 {
     return Html::endTag(ArrayHelper::keyExists('tag', $this->options) ? $this->options['tag'] : 'div');
 }
Esempio n. 25
0
 /**
  * Load model.
  *
  * @param string $name Model name
  * @param null|int $pk Primary key
  * @return \yii\db\ActiveRecord
  * @throws NotFoundHttpException
  */
 public function loadModel($name, $pk = null)
 {
     $name = (string) $name;
     if (!ArrayHelper::keyExists($name, $this->models)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     /** @var $model \yii\db\ActiveRecord */
     $model = $this->models[$name];
     if ($pk !== null) {
         if (($model = $model->findOne((int) $pk)) !== null) {
             /** @var $model \yii\db\ActiveRecord */
             return $model;
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $model;
 }
Esempio n. 26
0
 private function getHasObschij()
 {
     /* @var $modelClass ActiveRecord */
     $modelClass = $this->modelClass;
     return ArrayHelper::keyExists('obschij', $modelClass::getTableSchema()->columns);
 }
Esempio n. 27
0
 /**
  * @inheritdoc
  */
 protected function validateValue($value)
 {
     return ArrayHelper::keyExists($value, $this->enum, $this->strict) ? null : [$this->message, []];
 }
Esempio n. 28
0
 /**
  * @return string
  */
 public function getJs()
 {
     $name = $this->getName();
     $width = strpos($this->width, "%") ? $this->width : $this->width . 'px';
     $height = strpos($this->height, "%") ? $this->height : $this->height . 'px';
     $containerId = ArrayHelper::getValue($this->containerOptions, 'id', $name . '-map-canvas');
     $overlaysJs = [];
     $js = [];
     foreach ($this->getOverlays() as $overlay) {
         /** @var ObjectAbstract $overlay */
         if (!ArrayHelper::keyExists("{$name}infoWindow", $this->getClosureScopedVariables()) && method_exists($overlay, 'getIsInfoWindowShared') && $overlay->getIsInfoWindowShared()) {
             $this->setClosureScopedVariable("{$name}infoWindow");
             $this->appendScript("{$name}infoWindow = new google.maps.InfoWindow();");
         }
         $overlay->options['map'] = new JsExpression($this->getName());
         $overlaysJs[] = $overlay->getJs();
     }
     $js[] = "(function(){";
     $js[] = $this->getClosureScopedVariablesScript();
     $js[] = "function initialize(){";
     $js[] = "var mapOptions = {$this->getEncodedOptions()};";
     $js[] = "var container = document.getElementById('{$containerId}');";
     $js[] = "container.style.width = '{$width}';";
     $js[] = "container.style.height = '{$height}';";
     $js[] = "var {$this->getName()} = new google.maps.Map(container, mapOptions);";
     $js = ArrayHelper::merge($js, $overlaysJs);
     foreach ($this->events as $event) {
         /** @var Event $event */
         $js[] = $event->getJs($name);
     }
     foreach ($this->getPlugins()->getInstalledPlugins() as $plugin) {
         /** @var \dosamigos\google\maps\PluginAbstract $plugin */
         $plugin->map = $this->getName();
         $js[] = $plugin->getJs($name);
     }
     $js = ArrayHelper::merge($js, $this->_js);
     $js[] = "};";
     $js[] = "initialize();";
     $js[] = "})();";
     return implode("\n", $js);
 }
Esempio n. 29
0
 public function testKeyExists()
 {
     $array = ['a' => 1, 'B' => 2];
     $this->assertTrue(ArrayHelper::keyExists('a', $array));
     $this->assertFalse(ArrayHelper::keyExists('b', $array));
     $this->assertTrue(ArrayHelper::keyExists('B', $array));
     $this->assertFalse(ArrayHelper::keyExists('c', $array));
     $this->assertTrue(ArrayHelper::keyExists('a', $array, false));
     $this->assertTrue(ArrayHelper::keyExists('b', $array, false));
     $this->assertTrue(ArrayHelper::keyExists('B', $array, false));
     $this->assertFalse(ArrayHelper::keyExists('c', $array, false));
 }
Esempio n. 30
0
 /**
  * Checks if reward rules are set properly
  * @throws \yii\base\Exception
  * @return boolean
  */
 protected function validateRules()
 {
     if ($this->limitRules < array_sum($this->rules)) {
         throw new \yii\base\Exception('Rules overflow.');
     }
     ksort($this->rules);
     for ($i = 1; $i < count($this->rules); $i++) {
         if (!ArrayHelper::keyExists($i, $this->rules)) {
             throw new \yii\base\Exception(sprintf('Rule lvl %s missing.', $i));
         }
     }
     return true;
 }