/** * Returns model instance by ID using IdentityMap * @param integer $id * @return Object */ public static function findById($id) { if (!isset(static::$identity_map[$id])) { static::$identity_map[$id] = Yii::$app->cache->get('Object: ' . $id); if (static::$identity_map[$id] === false) { static::$identity_map[$id] = Object::findOne($id); if (is_object(static::$identity_map[$id])) { static::$ids_for_class_name[static::$identity_map[$id]->object_class] = $id; Yii::$app->cache->set('Object: ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]])); } } } return static::$identity_map[$id]; }
public function up() { $objects = \app\models\Object::find()->asArray()->all(); foreach ($objects as $object) { if ($object['name'] == 'Submission') { continue; } else { if ($object['name'] == 'Form') { $submissionObject = \app\models\Object::findOne(['name' => 'Submission']); $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $this->addColumn($submissionObject->eav_table_name, 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all(); foreach ($groups as $group) { $forms = \app\models\ObjectPropertyGroup::find()->select('object_model_id')->where(['property_group_id' => $group['id']])->asArray()->all(); $formIDs = []; foreach ($forms as $formID) { if (!in_array($formID['object_model_id'], $formIDs)) { $formIDs[] = $formID['object_model_id']; } } $submissionIDs = \app\models\Submission::find()->select('id')->where(['form_id' => $formIDs])->asArray()->all(); $subIDs = []; foreach ($submissionIDs as $submission) { $subIDs[] = $submission['id']; } $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all(); foreach ($properties as $property) { $this->update($submissionObject->eav_table_name, ['property_group_id' => $group['id']], ['key' => $property['key']]); } } } else { $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all(); foreach ($groups as $group) { $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all(); foreach ($properties as $property) { $this->update($object['eav_table_name'], ['property_group_id' => $group['id']], ['key' => $property['key']]); } } } } } }
/** * Finds the Object model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Object the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Object::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Invalidate cache for object */ private function invalidateObjectCache() { $className = null; if (!isset(static::$objectClassMap[static::$tableName])) { /** @var Object $object */ if (null !== ($object = Object::findOne(['eav_table_name' => static::$tableName]))) { static::$objectClassMap[static::$tableName] = $object->object_class; $className = static::$objectClassMap[static::$tableName]; } } else { $className = static::$objectClassMap[static::$tableName]; } if (null !== $className) { \yii\caching\TagDependency::invalidate(\Yii::$app->cache, [ActiveRecordHelper::getObjectTag($className, $this->object_model_id)]); } }
/** * Finds the Object model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Monitor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelobject($id) { if (($modelobject = Object::findOne($id)) !== null) { return $modelobject; } else { throw new NotFoundHttpException('Заведение не найдено.'); } }