本文整理汇总了PHP中app\models\Object::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::findById方法的具体用法?PHP Object::findById怎么用?PHP Object::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Object
的用法示例。
在下文中一共展示了Object::findById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
public function getData()
{
$objectClass = Object::findById($this->objectId)->object_class;
$object = new $objectClass();
$this->data = $object->attributeLabels();
return parent::getData();
}
示例2: actionExport
public function actionExport($importModel)
{
/** @var ImportModel $model */
$model = new ImportModel();
$model->unserialize($importModel);
if ($model->validate()) {
/** @var Export $exportStatus */
$exportStatus = Export::find()->where(['user_id' => $model->getUser(), 'object_id' => $model->object])->one();
$exportStatus->status = Export::STATUS_PROCESS;
$exportStatus->save();
try {
$object = Object::findById($model->object);
if ($object === null) {
throw new Exception('Object not found');
}
$filename = $model->getFilename('Export');
$import = \app\modules\data\components\Import::createInstance(['object' => $object, 'filename' => $filename, 'type' => $model->type]);
$import->processExport($model->fields, $model->conditions);
$exportStatus->filename = $filename;
$exportStatus->status = Export::STATUS_COMPLETE;
$exportStatus->save();
} catch (\Exception $e) {
$exportStatus->status = Export::STATUS_FAILED;
$exportStatus->save();
echo $e->getMessage();
throw $e;
}
} else {
echo 'Model is not valid';
throw new Exception('Model is not valid');
}
}
示例3: getLinks
protected function getLinks()
{
if (!is_null($this->frontendLink) || !is_null($this->backendLink)) {
return true;
}
/** @var Image $image */
$image = Image::findById($this->img_id);
if (is_null($image) || is_null($object = Object::findById($image->object_id))) {
return false;
}
/** @var \app\models\Object $object */
switch ($object->object_class) {
case Page::className():
$this->getPageLinks($image->object_model_id);
break;
case Category::className():
$this->getCategoryLinks($image->object_model_id);
break;
case Product::className():
$this->getProductLinks($image->object_model_id);
break;
default:
return false;
}
return true;
}
示例4: unifiedAction
/**
* Unified action for import and export
* @param $id
* @param $importMode
* @return string|\yii\web\Response
* @throws ErrorException
*/
private function unifiedAction($id, $importMode)
{
$object = Object::findById($id);
/* @var $className \app\modules\data\models\Import */
$className = $importMode ? 'app\\modules\\data\\models\\Import' : 'app\\modules\\data\\models\\Export';
if ($object !== null) {
$model = new ImportModel(['object' => $id]);
$fields = \app\modules\data\components\Import::getFields($model->object);
if (\Yii::$app->request->isPost) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$import = $className::find()->where(['user_id' => Yii::$app->user->id, 'object_id' => $id])->one();
if ($import === null) {
$import = new $className(['user_id' => Yii::$app->user->id, 'object_id' => $id]);
}
$import->filename = null;
if ($importMode === true) {
$file = UploadedFile::getInstance($model, 'file');
$model->type = $file->extension;
$filename = $model->getFilename('Import');
$import->filename = $filename;
$fullFilename = Yii::$app->getModule('data')->importDir . '/' . $filename;
if ($file->saveAs($fullFilename) === false) {
throw new ErrorException("Unable to save file");
}
}
$import->status = $className::STATUS_PROCESS;
$task_options = Yii::$app->request->post('Task', []);
if ($import->save()) {
BackgroundTasks::addTask(['name' => $importMode ? 'import' : 'export', 'description' => ($importMode ? 'import' : 'export') . " {$model->object}", 'action' => 'data/file/' . ($importMode ? 'import' : 'export'), 'params' => $model->serialize(), 'init_event' => $importMode ? 'import' : 'export'], ['create_notification' => isset($task_options['create_notification']) && 1 == $task_options['create_notification'] ? true : false]);
\Yii::$app->session->setFlash('info', \Yii::t('app', 'Task is queued. Come back later.'));
} else {
\Yii::$app->session->setFlash('error', \Yii::t('app', 'Import Error'));
}
return $this->redirect(['/data/file']);
}
}
$availablePropertyGroups = [];
/** @var \app\modules\shop\models\Product $exampleModel - product for example */
$exampleModel = new $object->object_class();
if ($exampleModel->hasMethod('getPropertyGroups')) {
$availablePropertyGroups = $exampleModel->getPropertyGroups(false, true);
}
\Yii::$app->session->setFlash('info', \Yii::t('app', 'Specify fields to import and select the file'));
$fields['additionalFields'] = [];
if ($exampleModel instanceof ExportableInterface) {
$fields['additionalFields'] = $exampleModel::exportableAdditionalFields();
}
if ($model->type === null) {
$model->type = Yii::$app->modules['data']->defaultType;
}
return $this->render('import-export', ['model' => $model, 'object' => $object, 'fields' => $fields, 'availablePropertyGroups' => $availablePropertyGroups, 'importMode' => $importMode]);
} else {
\Yii::$app->session->setFlash('error', \Yii::t('app', 'Object not found'));
return $this->redirect(['/data/file']);
}
}
示例5: getForModel
/**
* Get images by objectId and objectModelId
* @param integer $objectId
* @param integer $objectModelId
* @return Image[]
*/
public static function getForModel($objectId, $objectModelId)
{
if (!isset(self::$identityMap[$objectId][$objectModelId])) {
$cacheName = 'Images:' . $objectId . ':' . $objectModelId;
self::$identityMap[$objectId][$objectModelId] = Yii::$app->cache->get($cacheName);
if (!is_array(self::$identityMap[$objectId][$objectModelId])) {
if (!isset(self::$identityMap[$objectId])) {
self::$identityMap[$objectId] = [];
}
self::$identityMap[$objectId][$objectModelId] = static::find()->where(['object_id' => $objectId, 'object_model_id' => $objectModelId])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all();
$object = Object::findById($objectId);
if (is_null($object)) {
return self::$identityMap[$objectId][$objectModelId];
}
Yii::$app->cache->set($cacheName, self::$identityMap[$objectId][$objectModelId], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object->object_class, $objectModelId)]]));
}
}
return self::$identityMap[$objectId][$objectModelId];
}
示例6: getForClass
/**
* @param string $class_name
* @return null|\app\models\Object
*/
public static function getForClass($class_name)
{
if (isset(static::$ids_for_class_name[$class_name])) {
$id = static::$ids_for_class_name[$class_name];
return Object::findById($id);
} else {
$object = Yii::$app->cache->get('ObjectByClassName: ' . $class_name);
if ($object === false) {
$object = Object::find()->where(['object_class' => $class_name])->one();
if ($object !== null) {
Yii::$app->cache->set('ObjectByClassName: ' . $class_name, $object, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object, $object->id)]]));
}
}
if (is_object($object)) {
static::$identity_map[$object->id] = $object;
static::$ids_for_class_name[$class_name] = $object->id;
return static::$identity_map[$object->id];
}
}
return null;
}
示例7: afterDelete
public function afterDelete()
{
$object = Object::findById($this->group->object_id);
$staticValues = PropertyStaticValues::find()->where(['property_id' => $this->id])->all();
foreach ($staticValues as $psv) {
$psv->delete();
}
if (null !== $object) {
if ($this->is_eav) {
Yii::$app->db->createCommand()->delete($object->eav_table_name, ['key' => $this->key, 'property_group_id' => $this->group->id])->execute();
}
if ($this->is_column_type_stored) {
Yii::$app->db->createCommand()->dropColumn($object->column_properties_table_name, $this->key)->execute();
// if ($object->object_class == Form::className()) {
// $submissionObject = Object::getForClass(Submission::className());
// Yii::$app->db->createCommand()
// ->dropColumn($submissionObject->column_properties_table_name, $this->key)
// ->execute();
// }
}
}
FilterSets::deleteAll(['property_id' => $this->id]);
parent::afterDelete();
}
示例8: parseRequest
public function parseRequest($manager, $request)
{
Yii::beginProfile("ObjectRule::parseRequest");
$url = $request->getPathInfo();
if (empty($url)) {
Yii::endProfile("ObjectRule::parseRequest");
return false;
}
$cacheKey = 'ObjectRule:' . $url . ':' . Json::encode($request->getQueryParams());
$result = Yii::$app->cache->get($cacheKey);
if ($result !== false) {
Yii::endProfile("ObjectRule::parseRequest");
$this->defineBlocksTitleAndView($result);
return $result['result'];
}
$prefilteredPage = PrefilteredPages::getActiveByUrl($url);
if ($prefilteredPage !== null) {
$params = ['properties' => Json::decode($prefilteredPage['params'])];
$category = Category::findById($prefilteredPage['last_category_id']);
if ($category === null) {
throw new NotFoundHttpException();
}
$params['category_group_id'] = $category->category_group_id;
$params['last_category_id'] = $category->id;
$data = ['blocks' => []];
if (!empty($prefilteredPage['title'])) {
$data['title'] = $prefilteredPage['title'];
}
if (!empty($prefilteredPage['meta_description'])) {
$data['meta_description'] = $prefilteredPage['meta_description'];
}
$blocks = ['content', 'announce', 'breadcrumbs_label', 'h1'];
foreach ($blocks as $block_name) {
if (!empty($prefilteredPage[$block_name])) {
$data['blocks'][$block_name] = $prefilteredPage[$block_name];
}
}
$data['is_prefiltered_page'] = true;
if ($prefilteredPage['view_id'] > 0) {
$data['viewId'] = $prefilteredPage['view_id'];
}
$data['result'] = ['shop/product/list', $params];
$this->defineBlocksTitleAndView($data);
Yii::$app->cache->set($cacheKey, $data, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(PrefilteredPages::className(), $prefilteredPage['id']), ActiveRecordHelper::getObjectTag(Category::className(), $category->id)]]));
return $data['result'];
}
$routes = ObjectRule::getRoutes();
$cacheTags = [];
foreach ($routes as $model) {
/** @var UrlPart[] $handlers */
$handlers = [];
$object = Object::findById($model->object_id);
foreach ($model->template as $t) {
$handler = Yii::createObject($t);
$handler->object = $object;
$handlers[] = $handler;
}
$url_parts = [];
$parameters = [];
$next_part = $url;
foreach ($handlers as $handler) {
if (empty($next_part)) {
//break;
}
$result = $handler->getNextPart($url, $next_part, $url_parts);
if ($result !== false && is_object($result) === true) {
$parameters = ArrayHelper::merge($parameters, $result->parameters);
$cacheTags = ArrayHelper::merge($cacheTags, $result->cacheTags);
// удалим leading slash
$next_part = ltrim($result->rest_part, '/');
$url_parts[] = $result;
} elseif ($result === false && $handler->optional === false) {
continue;
}
}
if (count($url_parts) == 0) {
continue;
}
// в конце удачного парсинга next_part должен остаться пустым
if (empty($next_part)) {
$resultForCache = ['result' => [$model->route, $parameters]];
if (isset($_POST['properties'], $parameters['properties'])) {
foreach ($_POST['properties'] as $key => $value) {
if (isset($parameters['properties'][$key])) {
$parameters['properties'][$key] = array_unique(ArrayHelper::merge($parameters['properties'][$key], $value));
} else {
$parameters['properties'][$key] = array_unique($value);
}
}
} elseif (isset($_POST['properties'])) {
$parameters['properties'] = $_POST['properties'];
}
Yii::endProfile("ObjectRule::parseRequest");
if (isset($parameters['properties'])) {
foreach ($parameters['properties'] as $key => $values) {
foreach ($parameters['properties'][$key] as $index => $value) {
if ($value === '') {
unset($parameters['properties'][$key][$index]);
}
}
//.........这里部分代码省略.........
示例9: getForModel
/**
* @param int $object_id
* @param int $object_model_id
* @return null|\yii\db\ActiveRecord[]
*/
public static function getForModel($object_id, $object_model_id)
{
$cacheKey = "PropertyGroupBy:{$object_id}:{$object_model_id}";
if (false === ($groups = Yii::$app->cache->get($cacheKey))) {
$group_ids = ObjectPropertyGroup::find()->select('property_group_id')->where(['object_id' => $object_id, 'object_model_id' => $object_model_id])->column();
if (null === $group_ids) {
return null;
}
if (null === ($groups = static::find()->where(['in', 'id', $group_ids])->all())) {
return null;
}
if (null !== ($object = Object::findById($object_id))) {
Yii::$app->cache->set($cacheKey, $groups, 0, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag($object, $object_id), ActiveRecordHelper::getObjectTag($object->object_class, $object_model_id)]]));
}
}
return $groups;
}
示例10: getTargetObject
/**
* @return Object|null
*/
public function getTargetObject()
{
return Object::findById($this->object_id);
}
示例11: getTargetObject
/**
* @return Object|null
*/
public function getTargetObject()
{
if ($this->targetObject === null) {
$this->targetObject = Object::findById($this->object_id);
}
return $this->targetObject;
}
示例12: __construct
/**
* @param array $config
*/
public function __construct($config = [])
{
if (!isset($config['object'])) {
throw new InvalidParamException('Parameters \'object\' is not set');
}
$this->object = $config['object'];
if (is_numeric($this->object)) {
$this->object = Object::findById($this->object);
} elseif (!$this->object instanceof Object) {
throw new InvalidParamException('Parameter "object" not Object or numeric');
}
unset($config['object']);
parent::__construct($config);
}
示例13: function
echo \app\backend\widgets\RemoveAllButton::widget(['url' => Url::toRoute(['remove-all', 'returnUrl' => Yii::$app->request->url]), 'gridSelector' => '.grid-view', 'htmlOptions' => ['class' => 'btn btn-danger']]);
?>
</div>
<div class="clearfix"></div>
<?php
$this->endBlock();
?>
<div class="reviews-index">
<?php
echo DynaGrid::widget(['options' => ['id' => 'reviews-grid'], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => Html::tag('h3', $this->title, ['class' => 'panel-title']), 'after' => $this->blocks['add-button']]], 'columns' => [['class' => \kartik\grid\CheckboxColumn::className(), 'options' => ['width' => '10px']], 'id', 'author_email', ['attribute' => 'submission.form.name', 'label' => Yii::t('app', 'Form name')], ['attribute' => 'object_id', 'filter' => \app\components\Helper::getModelMap(\app\models\Object::className(), 'id', 'name'), 'label' => Yii::t('app', 'Object'), 'value' => function ($data) {
$obj = \app\models\Object::findById($data->object_id);
return is_null($obj) ? Yii::t('yii', '(not set)') : $obj->name;
}], ['class' => yii\grid\DataColumn::className(), 'attribute' => 'object_model_id', 'value' => function ($data) {
/** @var $object \app\models\Object*/
if (null !== ($object = \app\models\Object::findById($data->object_id))) {
$class = $object->object_class;
$resource = $class::findById($data->object_model_id);
if (null !== $resource) {
return $resource->name;
}
return null;
}
}], ['class' => yii\grid\DataColumn::className(), 'attribute' => 'processed_by_user_id', 'value' => function ($data) {
if (isset($data->submission)) {
if (null !== $data->submission->processed_by_user_id) {
/** @var $user \app\modules\user\models\User */
$user = \app\modules\user\models\User::findIdentity($data->submission->processed_by_user_id);
return $user->getDisplayName();
} else {
return Yii::t('app', 'Guest');
示例14: actionAddAddonBinding
public function actionAddAddonBinding($remove = '0')
{
if (Yii::$app->request->isAjax === false) {
throw new BadRequestHttpException();
}
Yii::$app->response->format = Response::FORMAT_JSON;
$addon_id = Yii::$app->request->post('addon_id', null);
$object_id = Yii::$app->request->get('object_id', null);
$object_model_id = Yii::$app->request->get('object_model_id', null);
if ($addon_id === null || $object_id === null || $object_model_id === null) {
throw new BadRequestHttpException();
}
$addon = Addon::findById($addon_id);
$object = Object::findById($object_id);
if ($addon === null || $object === null) {
throw new NotFoundHttpException();
}
$modelClassName = $object->object_class;
$model = $this->loadModel($modelClassName, $object_model_id);
// ok, now all's ok, addon and model exist!
try {
if ($remove === '1') {
$model->unlink('bindedAddons', $addon, true);
} else {
$model->link('bindedAddons', $addon, ['sort_order' => count($model->bindedAddons), 'appliance_object_id' => $object->id]);
}
} catch (\Exception $e) {
if (intval($e->getCode()) == 23000) {
return ['data' => Html::tag('div', Yii::t('app', 'Addon is already added'), ['class' => 'alert alert-info']) . AddonsListWidget::widget(['object_id' => $object->id, 'object_model_id' => $model->id, 'bindedAddons' => $model->bindedAddons]), 'error' => false];
} else {
return ['data' => Html::tag('div', $e->getMessage(), ['class' => 'alert alert-danger']), 'error' => $e->getMessage()];
}
}
TagDependency::invalidate(Yii::$app->cache, [Addon::className()]);
return ['data' => AddonsListWidget::widget(['object_id' => $object->id, 'object_model_id' => $model->id, 'bindedAddons' => $model->bindedAddons]), 'error' => false];
}
示例15: updateValues
public function updateValues($new_values, $object_id, $object_model_id)
{
$column_type_updates = ['object_model_id' => $object_model_id];
$osv_psv_ids = [];
$new_eav_values = [];
$eav_ids_to_delete = [];
foreach ($new_values as $key => $values) {
$property = Property::findById($values->property_id);
if ($property->captcha == 1) {
continue;
}
if (!isset($this->values_by_property_key[$key])) {
// нужно добавить
if ($property->is_column_type_stored) {
$column_type_updates[$key] = (string) $values;
} elseif ($property->has_static_values) {
foreach ($values->values as $val) {
$osv_psv_ids[] = $val['value'];
}
} elseif ($property->is_eav) {
$new_eav_values[$key] = $values;
}
} else {
if ($property->is_column_type_stored) {
$column_type_updates[$key] = (string) $values;
} elseif ($property->has_static_values) {
foreach ($values->values as $val) {
$osv_psv_ids[] = $val['value'];
}
} elseif ($property->is_eav) {
// добавим новые
foreach ($values->values as $val) {
$exist_in_old = false;
foreach ($this->values_by_property_key[$key]->values as $old_val) {
if ($old_val['value'] == $val['value']) {
$exist_in_old = true;
break;
}
}
if ($exist_in_old == false) {
$new_eav_values[] = [$object_model_id, $values->property_group_id, $key, $val['value'], 0];
}
}
// теперь добавим на удаление
foreach ($this->values_by_property_key[$key]->values as $old_val) {
$exist_in_new = false;
foreach ($values->values as $new_val) {
if ($old_val['value'] == $new_val['value']) {
$exist_in_new = true;
break;
}
}
if ($exist_in_new == false) {
// @todo find why sometimes it isn't exist
if (isset($old_val['eav_id'])) {
$eav_ids_to_delete[] = $old_val['eav_id'];
}
}
}
}
}
}
$osv_psv_ids_to_delete = [];
foreach ($this->values_by_property_key as $key => $values) {
$property = Property::findById($values->property_id);
if (in_array($key, array_keys($new_values)) === false) {
// if in incoming array there was no specification for this property - skip it
continue;
}
if ($property->has_static_values) {
foreach ($values->values as $val) {
if (in_array($val['psv_id'], $osv_psv_ids) === false) {
// в новых значениях нет
$osv_psv_ids_to_delete[] = $val['psv_id'];
} else {
// удалим, чтобы заново не добавлять
unset($osv_psv_ids[array_search($val['psv_id'], $osv_psv_ids)]);
}
}
}
}
if (count($osv_psv_ids_to_delete) > 0) {
ObjectStaticValues::deleteAll(['and', '`object_id` = :objectId', ['and', '`object_model_id` = :objectModelId', ['in', '`property_static_value_id`', $osv_psv_ids_to_delete]]], [':objectId' => $object_id, ':objectModelId' => $object_model_id]);
}
if (count($osv_psv_ids) > 0) {
$rows = [];
foreach ($osv_psv_ids as $psv_id) {
// 0 - Not Selected Field. Такие значения в базу не сохраняем
if ($psv_id == 0) {
continue;
}
$rows[] = [$object_id, $object_model_id, $psv_id];
}
if (!empty($rows)) {
Yii::$app->db->createCommand()->batchInsert(ObjectStaticValues::tableName(), ['object_id', 'object_model_id', 'property_static_value_id'], $rows)->execute();
}
}
Yii::$app->cache->delete("PSV:" . $object_id . ":" . $object_model_id);
if (count($column_type_updates) > 1) {
$table_name = Object::findById($object_id)->column_properties_table_name;
//.........这里部分代码省略.........