public function upload($attribute) { $class = \yii\helpers\StringHelper::basename(get_class($this->owner)) . 'Cutter'; if ($uploadImage = UploadedFile::getInstance($this->owner, $attribute)) { if (!$this->owner->isNewRecord) { $this->delete($attribute); } $cropping = $_POST[$class][$attribute . '-cropping']; $croppingFileName = md5($uploadImage->name . $this->quality . Json::encode($cropping)); $croppingFileExt = strrchr($uploadImage->name, '.'); $croppingFileDir = substr($croppingFileName, 0, 2); $croppingFileBasePath = Yii::getAlias($this->basePath) . $this->baseDir; if (!is_dir($croppingFileBasePath)) { mkdir($croppingFileBasePath, 0755, true); } $croppingFilePath = Yii::getAlias($this->basePath) . $this->baseDir . DIRECTORY_SEPARATOR . $croppingFileDir; if (!is_dir($croppingFilePath)) { mkdir($croppingFilePath, 0755, true); } $fileSavePath = $croppingFilePath . DIRECTORY_SEPARATOR . $croppingFileName . $croppingFileExt; $point = new Point($cropping['dataX'], $cropping['dataY']); $box = new Box($cropping['dataWidth'], $cropping['dataHeight']); $palette = new \Imagine\Image\Palette\RGB(); $color = $palette->color('fff', 0); Image::frame($uploadImage->tempName, 0, 'fff', 0)->rotate($cropping['dataRotate'], $color)->crop($point, $box)->save($fileSavePath, ['quality' => $this->quality]); $this->owner->{$attribute} = $this->baseDir . DIRECTORY_SEPARATOR . $croppingFileDir . DIRECTORY_SEPARATOR . $croppingFileName . $croppingFileExt; } elseif (isset($_POST[$class][$attribute . '-remove']) && $_POST[$class][$attribute . '-remove']) { $this->delete($attribute); } elseif (!empty($_POST[$class][$attribute])) { $this->owner->{$attribute} = $_POST[$class][$attribute]; } elseif (isset($this->owner->oldAttributes[$attribute])) { $this->owner->{$attribute} = $this->owner->oldAttributes[$attribute]; } }
public static function bOrderAttr() { if (is_null(static::$b_order_attr)) { static::$b_order_attr = Inflector::camel2id(StringHelper::basename(static::bClass()), '_') . '_ord'; } return static::$b_order_attr; }
public function run() { if (is_null($this->imageOptions)) { $this->imageOptions = ['class' => 'img-responsive']; } $this->imageOptions['id'] = Yii::$app->getSecurity()->generateRandomString(10); $inputField = Html::getInputId($this->model, $this->attribute); $class = \yii\helpers\StringHelper::basename(get_class($this->model)) . 'Cutter'; echo Html::beginTag('div', ['class' => 'image-cutter', 'id' => $inputField . '-cutter']); echo Html::activeFileInput($this->model, $this->attribute); echo Html::hiddenInput($class . '[' . $this->attribute . ']', $this->model->{$this->attribute}); $previewImage = Html::beginTag('div', ['class' => 'img-container']); $previewImage .= Html::tag('span', '', ['class' => 'helper']); $previewImage .= Html::tag('span', Yii::t('sadovojav/cutter/cutter', 'Click to upload image'), ['class' => 'message']); $previewImage .= Html::img($this->model->{$this->attribute} ? $this->model->{$this->attribute} : null, ['class' => 'preview-image']); $previewImage .= Html::endTag('div'); echo Html::label($previewImage, Html::getInputId($this->model, $this->attribute), ['class' => 'dropzone']); echo Html::checkbox($class . '[' . $this->attribute . '-remove]', false, ['label' => Yii::t('sadovojav/cutter/cutter', 'Remove')]); Modal::begin(['header' => Html::tag('h4', Yii::t('sadovojav/cutter/cutter', 'Cutter'), ['class' => 'modal-title']), 'closeButton' => false, 'footer' => $this->getModalFooter($inputField), 'size' => Modal::SIZE_LARGE]); echo Html::beginTag('div', ['class' => 'image-container']); echo Html::img(null, $this->imageOptions); echo Html::endTag('div'); echo Html::tag('br'); echo Html::beginTag('div', ['class' => 'row']); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Aspect ratio'), $inputField . '-aspectRatio'); echo Html::textInput($class . '[' . $this->attribute . '-aspectRatio]', isset($this->cropperOptions['aspectRatio']) ? $this->cropperOptions['aspectRatio'] : 0, ['id' => $inputField . '-aspectRatio', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Angle'), $inputField . '-dataRotate'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataRotate]', '', ['id' => $inputField . '-dataRotate', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (x)', $inputField . '-dataX'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataX]', '', ['id' => $inputField . '-dataX', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Position') . ' (y)', $inputField . '-dataY'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataY]', '', ['id' => $inputField . '-dataY', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Width'), $inputField . '-dataWidth'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataWidth]', '', ['id' => $inputField . '-dataWidth', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'col-md-2']); echo Html::label(Yii::t('sadovojav/cutter/cutter', 'Height'), $inputField . '-dataHeight'); echo Html::textInput($class . '[' . $this->attribute . '-cropping][dataHeight]', '', ['id' => $inputField . '-dataHeight', 'class' => 'form-control']); echo Html::endTag('div'); echo Html::endTag('div'); Modal::end(); echo Html::endTag('div'); $options = ['inputField' => $inputField, 'useWindowHeight' => $this->useWindowHeight, 'cropperOptions' => $this->cropperOptions]; $options = Json::encode($options); $this->view->registerJs('jQuery("#' . $inputField . '").cutter(' . $options . ');'); }
/** * Unlinks two or more models by provided primary key or a list of primary keys. * If the relation type is a many_to_many. related row in the junction table will be deleted. * Otherwise related foreign key will be simply set to NULL. * A '204' response should be set to headers if any change has been made. * @param string $IDs should hold the list of IDs related to the models to be unlinken from the relative one. * it must be a string of the primary keys values separated by commas. * @throws BadRequestHttpException if any of the models are not linked. * @throws InvalidCallException if the models cannot be unlinked */ public function run($IDs) { $relModel = $this->getRelativeModel(); $modelClass = $this->modelClass; $pk = $modelClass::primaryKey()[0]; $getter = 'get' . $this->relationName; $ids = preg_split('/\\s*,\\s*/', $IDs, -1, PREG_SPLIT_NO_EMPTY); $to_unlink = []; foreach ($ids as $pk_value) { $linked = $relModel->{$getter}()->where([$pk => $pk_value])->exists(); if ($linked === true) { $to_unlink[] = $this->findModel($pk_value); } else { throw new BadRequestHttpException(StringHelper::basename($modelClass) . " '{$pk_value}' not linked to " . StringHelper::basename($this->relativeClass) . " '{$this->relative_id}'."); } } $relType = $relModel->getRelation($this->relationName); $delete = $relType->multiple === true && $relType->via !== null; foreach ($to_unlink as $model) { if ($this->checkAccess) { call_user_func($this->checkAccess, $this->id, $model); } $relModel->unlink($this->relationName, $model, $delete); } Yii::$app->getResponse()->setStatusCode(204); }
/** * @inheritdoc */ public static function tableName() { $name = Inflector::camel2id(StringHelper::basename(get_called_class()), '_'); $length = mb_strlen($name, \Yii::$app->charset) - 7; // - mb_strlen('_record', Yii::$app->charset); return '{{%' . trim(mb_substr($name, 0, $length, \Yii::$app->charset)) . '}}'; }
/** * @param DOMElement $element * @param mixed $data */ protected function buildXml($element, $data) { if (is_object($data)) { $child = new DOMElement(StringHelper::basename(get_class($data))); $element->appendChild($child); if ($data instanceof Arrayable) { $this->buildXml($child, $data->toArray()); } else { $array = []; foreach ($data as $name => $value) { $array[$name] = $value; } $this->buildXml($child, $array); } } elseif (is_array($data)) { foreach ($data as $name => $value) { if (is_int($name) && is_object($value)) { $this->buildXml($element, $value); } elseif (is_array($value) || is_object($value)) { $child = new DOMElement(is_int($name) ? $this->itemTag : $name); $element->appendChild($child); $this->buildXml($child, $value); } else { $child = new DOMElement(is_int($name) ? $this->itemTag : $name); $element->appendChild($child); $child->appendChild(new DOMText((string) $value)); } } } else { $element->appendChild(new DOMText((string) $data)); } }
public function testBasename() { $this->assertEquals('', StringHelper::basename('')); $this->assertEquals('file', StringHelper::basename('file')); $this->assertEquals('file.test', StringHelper::basename('file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('file.test', '.test')); $this->assertEquals('file', StringHelper::basename('/file')); $this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('/file.test', '.test')); $this->assertEquals('file', StringHelper::basename('/path/to/file')); $this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test')); $this->assertEquals('file', StringHelper::basename('\\file')); $this->assertEquals('file.test', StringHelper::basename('\\file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('\\file.test', '.test')); $this->assertEquals('file', StringHelper::basename('C:\\file')); $this->assertEquals('file.test', StringHelper::basename('C:\\file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('C:\\file.test', '.test')); $this->assertEquals('file', StringHelper::basename('C:\\path\\to\\file')); $this->assertEquals('file.test', StringHelper::basename('C:\\path\\to\\file.test', '.test2')); $this->assertEquals('file', StringHelper::basename('C:\\path\\to\\file.test', '.test')); // mixed paths $this->assertEquals('file.test', StringHelper::basename('/path\\to/file.test')); $this->assertEquals('file.test', StringHelper::basename('/path/to\\file.test')); $this->assertEquals('file.test', StringHelper::basename('\\path/to\\file.test')); // \ and / in suffix $this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st')); $this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\\st')); $this->assertEquals('file', StringHelper::basename('/path/to/filete\\st', 'te\\st')); $this->assertEquals('st', StringHelper::basename('/path/to/filete\\st', 'te/st')); // http://www.php.net/manual/en/function.basename.php#72254 $this->assertEquals('foo', StringHelper::basename('/bar/foo/')); $this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\')); }
public function init() { if (!$this->modelName) { $this->modelName = StringHelper::basename(get_class($this), 'Controller'); } if (!$this->modelClass) { $modelClass = 'app\\models\\' . $this->modelName; if (class_exists($modelClass)) { $this->modelClass = $modelClass; } else { $modelClass = 'app\\models\\readonly\\' . $this->modelName; if (class_exists($modelClass)) { $this->modelClass = $modelClass; } } } if (!$this->filterModelClass) { $filterModelClass = 'app\\models\\search\\' . $this->modelName . 'Search'; if (class_exists($filterModelClass)) { $this->filterModelClass = $filterModelClass; } else { $filterModelClass = 'app\\models\\readonly\\search\\' . $this->modelName . 'Search'; if (class_exists($filterModelClass)) { $this->filterModelClass = $filterModelClass; } } } parent::init(); }
/** * @param \phpDocumentor\Reflection\BaseReflector $reflector * @param Context $context * @param array $config */ public function __construct($reflector = null, $context = null, $config = []) { parent::__construct($config); if ($reflector === null) { return; } // base properties $this->name = ltrim($reflector->getName(), '\\'); $this->startLine = $reflector->getNode()->getAttribute('startLine'); $this->endLine = $reflector->getNode()->getAttribute('endLine'); $docblock = $reflector->getDocBlock(); if ($docblock !== null) { $this->shortDescription = ucfirst($docblock->getShortDescription()); if (empty($this->shortDescription) && !$this instanceof PropertyDoc && $context !== null && $docblock->getTagsByName('inheritdoc') === null) { $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No short description for " . substr(StringHelper::basename(get_class($this)), 0, -3) . " '{$this->name}'"]; } $this->description = $docblock->getLongDescription()->getContents(); $this->phpDocContext = $docblock->getContext(); $this->tags = $docblock->getTags(); foreach ($this->tags as $i => $tag) { if ($tag instanceof SinceTag) { $this->since = $tag->getVersion(); unset($this->tags[$i]); } elseif ($tag instanceof DeprecatedTag) { $this->deprecatedSince = $tag->getVersion(); $this->deprecatedReason = $tag->getDescription(); unset($this->tags[$i]); } } } elseif ($context !== null) { $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No docblock for element '{$this->name}'"]; } }
public function getThumbnailTrue() { if ($this->image) { $name = \yii\helpers\StringHelper::basename($this->image); $dir = \yii\helpers\StringHelper::dirname($this->image); return Yii::getAlias($dir . '/thumb/' . $name); } }
public function run() { $notesDataProvider = new ActiveDataProvider(['query' => $this->model->getNotes(), 'pagination' => ['pageSize' => 3]]); $newModel = new Note(); $newModel->Model_id = $this->model->id; $newModel->Model = StringHelper::basename(get_class($this->model)); echo $this->render('note', ['model' => $newModel, 'dataProvider' => $notesDataProvider, 'accessPriviledge' => $this->accessPriviledge]); }
protected function idAttr() { if (is_null($this->pivotIdAttr)) { $owner = $this->owner; $this->pivotIdAttr = Inflector::camel2id(StringHelper::basename($owner->className()), '_') . '_id'; } return $this->pivotIdAttr; }
/** * @inheritdoc */ public function generate() { $files = []; $modulePath = $this->getModulePath(); $files[] = new CodeFile($modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php', $this->render("module.php")); $files[] = new CodeFile($modulePath . '/controllers/frontend/DefaultController.php', $this->render("controller.php")); $files[] = new CodeFile($modulePath . '/views/frontend/default/index.php', $this->render("view.php")); return $files; }
public function parseExtraFields($modelName) { if (isset($this->extraFieldModels[StringHelper::basename($modelName::className())])) { $var = $this->extraFieldModels[StringHelper::basename($modelName::className())]; $fieldsArr = $this->{$var}; return array_values(ArrayHelper::map($fieldsArr, 0, 0)); } return []; }
public function init() { $this->className = \yii\helpers\StringHelper::basename(get_class($this->model)); $cities = LocationCity::find()->orderBy('title ASC')->all(); foreach ($cities as $city) { $this->district[$city->_id] = ArrayHelper::map(LocationDistrict::find()->where(['region_id' => $city->_id])->orderBy('title ASC')->all(), '_id', 'title'); } $this->registerJs(); }
/** * @inheritdoc */ public function __construct($params = []) { $classname = \yii\helpers\StringHelper::basename(static::className()); if (!isset($params[$classname])) { $params = [$classname => $params]; } $this->_params = $params; return parent::__construct(); }
/** * @inheritdoc */ public function init() { parent::init(); if (!isset($this->counterOwner) || !is_array($this->counterOwner) && !is_object($this->counterOwner)) { throw new InvalidConfigException('counterOwner must be configured as array or object'); } if (!isset($this->counterParam)) { $this->counterParam = Inflector::camel2id(StringHelper::basename(get_class($this->counterOwner))) . '_count'; } }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } Html::addCssClass($this->options, strtolower(StringHelper::basename(get_class($this)))); $assetBundle = $this->assetBundle; $assetBundle::register($this->getView()); }
/** * Initialize attributes * * @throws \yii\base\InvalidConfigException */ public function init() { if (!$this->model) { throw new InvalidConfigException('Model is missing'); } $this->_modelName = $this->model instanceof ActiveRecord ? Inflector::camel2id(StringHelper::basename(get_class($this->model))) : $this->model; if (!$this->storageId) { $this->storageId = $this->_modelName; } }
/** * @inheritdoc */ public function generate() { $files = []; $modulePath = $this->getModulePath(); $files[] = new CodeFile($modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php', $this->render("module.php")); $files[] = new CodeFile($modulePath . '/controllers/.gitkeep', ''); $files[] = new CodeFile($modulePath . '/views/.gitkeep', ''); $files[] = new CodeFile($modulePath . '/models/.gitkeep', ''); return $files; }
/** * @inheritdoc */ public function generate() { $files = []; $modulePath = $this->getModulePath(); $files[] = new CodeFile($modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php', $this->render("module.php")); $files[] = new CodeFile($modulePath . '/controllers/DefaultController.php', $this->render("controller.php")); $files[] = new CodeFile($modulePath . '/views/default/index.php', $this->render("view.php")); $files[] = new CodeFile($modulePath . '/traits/ActiveRecordDbConnectionTrait.php', $this->render("db-connection-trait.php")); return $files; }
public function run() { if (!$this->model->seo) { $seoModel = new Seo(); $seoModel->Model_id = $this->model->id; $seoModel->Model = StringHelper::basename(get_class($this->model)); } else { $seoModel = $this->model->seo; } echo $this->render('seo', ['model' => $seoModel, 'accessPriviledge' => $this->accessPriviledge]); }
/** * Preloads configuration values from php files that stores php array */ public function preloadConfigValues() { if ($this->configValues === null) { $ownerName = StringHelper::basename(get_class($this->owner)); if (isset(Yii::$app->params['kv-' . $ownerName]) === true) { $this->configValues = Yii::$app->params['kv-' . $ownerName]; } else { // config is empty for now $this->configValues = []; } } }
public function imageForm() { ImageFieldAsset::register(\Yii::$app->view); CropperAsset::register(\Yii::$app->view); $content = ''; if ($this->images) { foreach ($this->images as $image) { $content .= \Yii::$app->view->renderFile('@vendor/floor12/yii2-imagefield/views/_form.php', ['image' => $image, 'class' => \yii\helpers\StringHelper::basename(get_class($this->owner))]); } } return \Yii::$app->view->renderFile('@vendor/floor12/yii2-imagefield/views/form.php', ['images' => $content, 'className' => \yii\helpers\StringHelper::basename(get_class($this->owner))]); }
/** * Finds the related model. * @return \yii\db\ActiveRecordInterface. * @throws NotFoundHttpException if not found. */ public function getRelativeModel() { $relativeClass = $this->relativeClass; $relModel = $relativeClass::findOne($this->relative_id); if ($relModel === null) { throw new NotFoundHttpException(StringHelper::basename($relativeClass) . " '{$this->relative_id}' not found."); } if ($this->checkAccess) { call_user_func($this->checkAccess, $this->id, $relModel); } return $relModel; }
/** * @param $model_type * @param $attributes * @return null */ public static function loadObject($model_type, $attributes) { if (!is_null($model_type)) { $object = new $model_type(); if (!is_null($attributes)) { $attributes = [StringHelper::basename(get_class($object)) => (array) json_decode($attributes)]; $object->load($attributes); } return $object; } return null; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $id, $className = null) { $query = Image::find()->where(['itemId' => $id]); if ($className) { $query->andWhere(['modelName' => StringHelper::basename($className)]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['position' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'name' => $this->name]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function init() { $params = (require_once __DIR__ . '/../config/params.php'); $this->_modelName = StringHelper::basename(get_called_class()); $this->_config = $params['api']; $this->_debug = $params['apiDebug']; $authHeader = isset($params['requestAuth']['header']) ? $params['requestAuth']['header'] : false; if ($authHeader) { foreach ($authHeader as $k => $v) { $this->_header[] = "{$k}: {$v}"; } } parent::init(); }
/** * Generates the code based on the current user input and the specified code template files. * This is the main method that child classes should implement. * Please refer to [[\yii\gii\generators\controller\Generator::generate()]] as an example * on how to implement this method. * @return CodeFile[] a list of code files to be created. */ public function generate() { $files = []; $modulePath = $this->getModulePath(); try { $modulesConfigPath = Yii::getAlias('@root/config/modules'); } catch (InvalidParamException $e) { $modulesConfigPath = Yii::$app->getBasePath() . '/config/modules/'; } $files[] = new CodeFile($modulesConfigPath . '/' . $this->moduleID . '.php', $this->render("config.php")); $files[] = new CodeFile($modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php', $this->render("module.php")); $files[] = new CodeFile($modulePath . '/controllers/DefaultController.php', $this->render("controller.php")); $files[] = new CodeFile($modulePath . '/resources/views/default/index.php', $this->render("view.php")); return $files; }
public function run() { if (is_null($this->type)) { throw new Exception("type darf nicht null sein"); } switch ($this->type) { case self::VIEW_NEW: return $this->render('_seen', ['haveSeen' => $this->haveSeen, 'class' => 'btn btn-flat btn-sm btn-info', 'style' => 'float:right;margin-top:-5px;']); case self::VIEW_COUNT_SEEN: return $this->render('_countSeen', ['countSeen' => $this->countSeen, 'modelType' => StringHelper::basename(get_class($this->model))]); case self::VIEW_DEFAULT: return $this->render('default', ['data' => $this->logs, 'behavior' => $this->behavior, 'widgetClass' => $this->className(), 'view' => '_view']); } return null; }