public function getUrl() { if (!$this->isNewRecord) { $name = HText::translit(mb_strtolower($this->name), "-"); return Yii::app()->createUrl(ShopModule::ROUTE_PRODUCT_BRAND, array('translitName' => $name, 'idBrand' => $this->id_brand)); } return '/'; }
public function getUrl() { if (!$this->isNewRecord) { $name = HText::translit(mb_strtolower($this->name), "-"); return Yii::app()->createUrl(ShopModule::ROUTE_PRODUCT_CATEGORY, array('translitName' => $name, 'idCategory' => $this->id_product_category)); } return '/'; }
public function recover() { $this->_newPassword = HText::getRandomString(8); $this->_userModel->user_password = $this->_newPassword; //$this->_userModel->hashPassword($this->_newPassword); $this->_userModel->save(); if ($this->hasEvent('onRecover')) { $this->onRecover(new CEvent($this)); } }
protected function renderDataCellContent($row, $data) { ob_start(); parent::renderDataCellContent($row, $data); $str = strip_tags(ob_get_clean()); if ($this->maxLength !== false) { $str = HText::crop($str, $this->maxLength); } echo nl2br($str); }
public function onProcessPermissionWhere(PermissionWhereEvent $event) { $idObject = intval(HU::get(self::URL_PARAM_OBJECT)); $idInstance = intval(HU::get(self::URL_PARAM_INSTANCE)); $where = $event->where; if ($idObject && $idInstance) { $where = HText::addCondition($where, 'id_object = :id_object_banner AND id_instance = :id_instance_banner'); $event->params[':id_object_banner'] = $idObject; $event->params[':id_instance_banner'] = $idInstance; } $event->where = $where; }
public function onProcessPermissionWhere(PermissionWhereEvent $event) { $where = $event->where; $idObject = HU::get(PhotogalleryPhoto::URL_PARAM_OBJECT); $idInstance = intval(HU::get(PhotogalleryPhoto::URL_PARAM_INSTANCE)); if ($idObject && $idInstance) { $where = HText::addCondition($where, 'id_photogallery_object = :id_object_gallery'); $where = HText::addCondition($where, 'id_photogallery_instance = :id_instance_gallery'); $event->params[':id_object_gallery'] = $idObject; $event->params[':id_instance_gallery'] = $idInstance; } $event->where = $where; }
public function onProcessPermissionWhere(PermissionWhereEvent $event) { //Формирование условия отбора $pkey = HU::get(ObjectUrlRule::PARAM_OBJECT_PARENT); $where = $event->where; if ($pkey == "") { //$where .= "id_object IS NULL OR id_object IN(SELECT id_object FROM da_object WHERE object_type<>".DA_OBJECT_TYPE_HEIR.")"; $where = HText::addCondition($where, "id_module_parent IS NULL"); } else { //$where .= "id_object IN(SELECT id_object FROM da_object WHERE object_type=".DA_OBJECT_TYPE_HEIR." AND table_name=$pkey)"; $where = HText::addCondition($where, "id_module_parent=" . $pkey); } $event->where = $where; }
public function onPostForm(PostFormEvent $event) { if (!YGIN_DEVELOP && $this->model->isNewRecord) { // для не разработчиков системы генерируем имя строковых ключей автоматически $model = $event->model; $id = rtrim(Yii::app()->backend->prefixPkName, '-_') . '-'; if ($this->parentSourceAttr != null) { $id = $model->{$this->parentSourceAttr} . '-'; } $id .= $this->prefixAttr; foreach ($this->sourceAttr as $attr) { if ($model->{$attr} != null && trim($model->{$attr}) != '-') { $id .= HText::translit(mb_strtolower($model->{$attr}), '-'); break; } } $id = str_replace('_', '-', $id); $this->model->{$this->attributeName} = $id; } }
public function getSearchCriteria() { $criteria = new CDbCriteria(); if (!($objParameter = $this->getSearchObjectParamter())) { return $criteria; } switch ($objParameter->getType()) { case DataType::VARCHAR: case DataType::EDITOR: case DataType::TEXTAREA: $criteria->compare($objParameter->getFieldName(), $this->value, true); break; case DataType::INT: case DataType::PRIMARY_KEY: $criteria->compare($objParameter->getFieldName(), $this->value); break; case DataType::OBJECT: $objS = DaObject::getById($objParameter->getAdditionalParameter()); $primParamS = $objS->getFieldByType(DataType::PRIMARY_KEY); $parametersSearch = $objS->parameters; $whereSearch = null; $i = 0; foreach ($parametersSearch as $param) { $type = $param->getType(); if ($type == DataType::VARCHAR) { $i++; $whereSearch = HText::addCondition($whereSearch, $param->getFieldName() . ' LIKE :search' . $i, 'OR'); $criteria->params[':search' . $i] = '%' . $this->value . '%'; } } if ($whereSearch != null) { $condition = HText::addCondition('', "t." . $objParameter->getFieldName() . " IN (SELECT " . $primParamS . " FROM " . $objS->table_name . " WHERE (" . $whereSearch . ") )"); $criteria->addCondition($condition, $condition); } break; case DataType::TIMESTAMP: if ($this->_tsBeginValue && $this->_tsEndValue) { $criteria->addBetweenCondition($objParameter->getFieldName(), $this->_tsBeginValue, $this->_tsEndValue); } else { $criteria->compare($objParameter->getFieldName(), $this->_tsOperator . $this->_tsBeginValue); } break; } return $criteria; }
public function checkObjectInstance($authItem, $userId, $idObject, $idInstance, $checkEventWhere = true) { if (!$this->checkObject($authItem, $userId, $idObject, $params = array('idInstance' => $idInstance))) { return false; } if ($checkEventWhere) { $criteria = new CDbCriteria(); $event = new PermissionWhereEvent(Yii::app()->controller, $idObject, null); $event->criteria = $criteria; Yii::app()->controller->raiseEvent(DefaultController::EVENT_ON_PROCESS_PERMISSION_WHERE, $event); $where = $event->where; if ($where != null || $criteria->condition != null) { $object = DaObject::getById($idObject); $field = $object->getFieldByType(DataType::PRIMARY_KEY); $where = HText::addCondition($where, $field . '=:id'); $criteria->addCondition($where); $criteria->params = array_merge($criteria->params, $event->params); $criteria->params[':id'] = $idInstance; return $object->getModel()->exists($criteria); } } return true; }
protected function beforeSave() { if ($this->isNewRecord) { $site = $this->link; $site = str_replace(array("http://", "www."), "", $site); $site = str_replace("/", "_", $site); $site = HText::translit($site) . "_" . rand(10, 1000); $site = str_replace("__", "_", $site); $this->unique_name = $site; } return parent::beforeSave(); }
<?php $this->registerCssFile("emarket_list_table.css"); ?> <table class="b-emarket_list_table table table-striped"> <?php foreach ($products as $product) { $url = $product->getUrl(); $desc = HText::smartCrop($product->description, 470, '...', 100); $price = $product->getPriceWithMarkup(); $preview = $product->getImagePreview('_list'); $previewUrl = $preview == null ? 'http://dummyimage.com/100x90/cccccc/000000&text=%D0%BD%D0%B5%D1%82+%D1%84%D0%BE%D1%82%D0%BE' : $preview->getUrlPath(); ?> <tr> <td class="preview_picture"><a href="<?php echo $url; ?> "><img src="<?php echo $previewUrl; ?> " alt="<?php echo CHtml::encode($product->name); ?> " title="<?php echo CHtml::encode($product->name); ?> "></a></td> <td class="elem"> <a href="<?php echo $url; ?>
private static function processValue($data) { // Обработка данных. Вырезаем все тэги. $value = trim($data); // Если данных нет, то запись не добавляем. if (is_null($value) || $value == "") { return ''; } $value = strip_tags($value); $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); $value = HText::cutDoubleChars($value, " "); $value = HText::cutDoubleChars($value, "\r"); $value = HText::cutDoubleChars($value, "\n"); $value = HText::cutDoubleChars($value, "\r\n"); $value = HText::cutDoubleChars($value, "\n\r"); $value = HText::cutDoubleChars($value, "\t"); $value = str_replace(array("«", "»", "\\", "\"", "\\'", "-", "+", ">", "<", "*"), array(" ", " ", " ", " ", " ", " ", " ", " ", " ", " "), $value); return $value; }
protected function beforeSave() { $this->alias = HText::translit($this->alias, '_', false); return parent::beforeSave(); }
?> " title="Photo"><img src="<?php echo $smallImage->getUrlPath(); ?> " alt=""></a></li> </ul> <?php } else { ?> <a href="<?php echo $link; ?> " title="Photo"><img class="photo<?php echo $photoNum; ?> stackphotos" src="<?php echo $smallImage->getUrlPath(); ?> " ></a> <?php } } // выводим имя галереи и кол-во фоток echo '<div class="info">' . HText::smartCrop($gallery->name, 85) . " (" . $gallery->countPhoto . ')</div>'; ?> </div> <?php } ?> </div>
protected function handleUpload() { $this->beforeUpload(); $formModel = $this->getFormModel(); if (!$formModel instanceof FileUploadForm) { throw new ErrorException('Модель формы должна расширять класс FileUploadForm.'); } $formModel->attributes = Yii::app()->request->getPost(get_class($formModel), array()); $formModel->{$this->fileAttribute} = CUploadedFile::getInstance($formModel, $this->fileAttribute); $uploadedFile = $formModel->{$this->fileAttribute}; if ($this->beforeUploadValidate()) { if ($formModel->validate()) { if ($this->fileName === null) { if ($this->filenameRule != null) { $this->fileName = $this->evaluateExpression($this->filenameRule, array('file' => $uploadedFile)); } if ($this->fileName === null) { $this->fileName = $uploadedFile->getName(); } if ($this->getTranslitFileName()) { $this->fileName = HText::translit($this->fileName, '-'); } } $oldFile = $this->getOldFile(); if (!$this->checkAccess($oldFile)) { throw new CHttpException(403, 'Вы не можете выполнить данную операцию.'); } $newFile = null; //Если существует старый файл, то его надо либо заменить, либо создать файл с новым именем if ($oldFile !== null) { if ($this->rewriteIfFileExist) { if (file_exists($oldFile->getFilePath(true))) { unlink($oldFile->getFilePath(true)); } $oldFile->deleteChildFile(); $newFile = $oldFile; } else { $this->fileName = $this->getCopyFileName($oldFile->getFilePath(true)); $newFile = new File(); } } else { $newFile = new File(); } $destDir = ''; if ($formModel->instanceId) { $model = $formModel->getInstanceModel(); if ($model == null) { throw new CHttpException(404, 'Экземпляр модели id_object = ' . $formModel->objectId . ', с id_instance = ' . $formModel->instanceId . ' не найден.'); } $destDir = $model->getDir(false, true); } else { $destDir = Yii::getPathOfAlias('temp') . '/' . $formModel->tmpId; } $destDir = $this->createDir($destDir); $normalazedPath = rtrim($destDir, '/') . '/'; $path = $normalazedPath . $this->fileName; //возможно такой файл уже существует //тогда надо сгенерить новое имя if (file_exists($path)) { $this->fileName = $this->getCopyFileName($path); $path = $normalazedPath . $this->fileName; } if (!$uploadedFile->saveAs($path)) { throw new CHttpException(500, 'Не удалось сохранить файл "' . $path . '".'); } else { chmod($path, 0777); } $newFile->create_date = time(); $newFile->id_object = $formModel->objectId; $newFile->id_instance = $formModel->instanceId; $newFile->id_parameter = $formModel->parameterId; $newFile->id_tmp = $formModel->tmpId; $newFile->file_path = $this->getRelativePath($path); if (!$newFile->save()) { throw new CHttpException(500, 'Не удалось сохранить модель File: ' . "\n" . $this->getModelErrors($newFile)); } $this->savedFile = $newFile; //если модель существующая и тип поля - Файл, то сразу обновим поле if ($formModel->instanceId) { $objectParameter = $formModel->getObjectParameter(); if ($objectParameter == null) { throw new CHttpException(404, 'Параметр объекта id_object = ' . $formModel->objectId . ', id_parameter = ' . $formModel->parameterId . ' не найден.'); } if ($objectParameter->id_parameter_type == DataType::FILE) { $model = $formModel->getInstanceModel(); $model->{$objectParameter->field_name} = $newFile->id_file; $model->save(false, array($objectParameter->field_name)); } } $this->afterUpload(); } else { if (isset($formModel->errors['file'])) { throw new DaHttpException(400, $this->getModelErrors($formModel)); // без логирования } else { throw new CHttpException(400, $this->getModelErrors($formModel)); } } } }
protected function beforeValidate() { // генерим другой алиас если текущий дублируется $existAlias = $this->find('alias = :ALIAS', array(':ALIAS' => $this->alias)); if ($existAlias) { $this->alias .= '_' . HText::getRandomString(1); } return true; }