本文整理汇总了PHP中ActiveRecord::baseClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::baseClass方法的具体用法?PHP ActiveRecord::baseClass怎么用?PHP ActiveRecord::baseClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::baseClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doAfterSave
public function doAfterSave($withRelation = true)
{
$pk = $this->tableSchema->primaryKey;
if ($this->isNewRecord) {
if (Setting::get('db.driver') == "mysql") {
$this->{$pk} = $this->dbConnection->getLastInsertID();
## this is hack
## UPDATE AUDIT TRAIL 'CREATE' ID
if (isset(Yii::app()->user) && !Yii::app()->user->isGuest) {
$a = $this->dbConnection->createCommand("\n update p_audit_trail set model_id = :model_id\n WHERE user_id = :user_id and\n model_class = :model_class and\n type = 'create' and\n model_id is null")->execute(['model_class' => ActiveRecord::baseClass($this), 'model_id' => $this->{$pk}, 'user_id' => Yii::app()->user->id]);
}
}
} else {
$this->deleteResetedRelations();
}
## handling untuk file upload
if (method_exists($this, 'getFields')) {
$currentClass = get_class($this);
$attrs = $this->handleFileUpload($currentClass, $this);
if (count($attrs) > 0) {
if ($this->isNewRecord) {
$this->isNewRecord = false;
$this->updateByPk($this->{$pk}, $attrs);
$this->isNewRecord = true;
} else {
$this->saveAttributes($attrs);
}
}
## handle listview
$fb = FormBuilder::load($currentClass);
$listView = $fb->findAllField(['type' => 'ListView']);
foreach ($listView as $k => $lv) {
## if listview is valid
if ($lv['fieldTemplate'] == "datasource" && @$lv['datasource'] != '' && @$lv['templateForm'] != '') {
$ds = $fb->findField(['name' => $lv['datasource']]);
## if datasource is saved via relation and data is posted
if (@$ds['postData'] == 'Yes' && @$ds['relationTo'] != '' && isset($this->__relUpdate[$ds['relationTo']])) {
foreach ($this->__relUpdate[$ds['relationTo']] as $k => $rel) {
$this->handleFileUpload($lv['templateForm'], $this->__relUpdate[$ds['relationTo']][$k]);
}
foreach ($this->__relInsert[$ds['relationTo']] as $k => $rel) {
$this->handleFileUpload($lv['templateForm'], $this->__relInsert[$ds['relationTo']][$k]);
}
}
}
}
}
if ($withRelation) {
$this->saveRelation();
}
return true;
}
示例2: json_encode
?>
";
$scope.pageInfo = <?php
echo json_encode(AuditTrail::getPathInfo());
?>
;
$scope.formClass = "<?php
echo $modelClass;
?>
";
$scope.formClassPath = "<?php
echo $modelClassPath;
?>
";
$scope.modelBaseClass = "<?php
echo ActiveRecord::baseClass($this->model);
?>
";
$scope.lastModified = "<?php
echo Helper::getLastModified($modelClass);
?>
";
$scope.date = date;
$scope.strtotime = strtotime;
$scope.angular = angular;
if (window.plansys) {
window.plansys.rootPath = "<?php
echo Setting::getRootPath();
?>
";
示例3: doAfterSave
public function doAfterSave($withRelation = true)
{
$pk = $this->tableSchema->primaryKey;
if ($this->isNewRecord) {
$this->{$pk} = $this->dbConnection->getLastInsertID();
## this is hack
## UPDATE AUDIT TRAIL 'CREATE' ID
if (!!Yii::app()->user && !Yii::app()->user->isGuest) {
$a = $this->dbConnection->createCommand("\n update p_audit_trail set model_id = :model_id\n WHERE user_id = :user_id and\n model_class = :model_class and\n type = 'create' and\n model_id is null")->execute(['model_class' => ActiveRecord::baseClass($this), 'model_id' => $this->{$pk}, 'user_id' => Yii::app()->user->id]);
}
} else {
$this->deleteResetedRelations();
}
if ($withRelation) {
$this->saveRelation();
}
## handling untuk file upload
if (method_exists($this, 'getFields')) {
$fb = FormBuilder::load(get_class($this));
$uploadFields = $fb->findAllField(['type' => 'UploadFile']);
$attrs = [];
$model = $this;
foreach ($uploadFields as $k => $f) {
if (@$f['name'] == '' || @$f['uploadPath'] == '') {
continue;
}
## create directory
## Jika disini gagal, berarti ada yang salah dengan format uploadPath di FormBuilder-nya
$evalDir = '';
eval('$evalDir = "' . $f['uploadPath'] . '";');
$evalDir = str_replace(["\n", "\r"], "", $evalDir);
$repopath = realpath(Yii::getPathOfAlias("repo"));
$evalDirArr = explode("/", $evalDir);
foreach ($evalDirArr as $i => $j) {
$evalDirArr[$i] = preg_replace('/[\\/\\?\\:\\*\\"\\<\\>\\|\\\\]*/', "", $j);
}
$evalDir = implode("/", $evalDirArr);
$dir = $repopath . "/" . $evalDir . "/";
$dir = str_replace(["\n", "\r"], "", $dir);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
## get oldname
$old = $this->{$f['name']};
$ext = pathinfo($old, PATHINFO_EXTENSION);
$filename = pathinfo($old, PATHINFO_FILENAME);
if (@$f['filePattern']) {
## get newname
## Jika disini gagal, berarti ada yang salah dengan format filePattern di FormBuilder-nya
eval('$newname = "' . $f['filePattern'] . '";');
} else {
$newname = $filename . "." . $ext;
}
$new = $dir . preg_replace('/[\\/\\?\\:\\*\\"\\<\\>\\|\\\\]*/', "", $newname);
$new = str_replace(["\n", "\r"], "", $new);
## delete file if already exist and allowed to overwrite
if (is_file($new) && $f['allowOverwrite'] == 'Yes' && is_file($old)) {
unlink($new);
}
if (!is_file($new) && is_file($old)) {
rename($old, $new);
$this->{$f['name']} = trim($evalDir, "/") . "/" . $newname;
if ($this->hasAttribute($f['name'])) {
$attrs[] = $f['name'];
}
}
}
if (count($attrs) > 0) {
if ($this->isNewRecord) {
$this->isNewRecord = false;
$this->updateByPk($this->id, $this->getAttributes($attrs));
$this->isNewRecord = true;
} else {
$this->update($attrs);
}
}
}
return true;
}
示例4: doAfterSave
public function doAfterSave($withRelation = true)
{
$pk = $this->tableSchema->primaryKey;
if ($this->isNewRecord) {
$this->{$pk} = $this->dbConnection->getLastInsertID();
## this is hack
## UPDATE AUDIT TRAIL 'CREATE' ID
if (!!Yii::app()->user && !Yii::app()->user->isGuest) {
$a = $this->dbConnection->createCommand("\n update p_audit_trail set model_id = :model_id\n WHERE user_id = :user_id and\n model_class = :model_class and\n type = 'create' and\n model_id is null")->execute(['model_class' => ActiveRecord::baseClass($this), 'model_id' => $this->{$pk}, 'user_id' => Yii::app()->user->id]);
}
} else {
$this->deleteResetedRelations();
}
if ($withRelation) {
foreach ($this->__relations as $k => $new) {
if ($k == 'currentModel') {
$rel = new CHasManyRelation('currentModel', get_class($this), 'id');
} else {
$rel = $this->getMetaData()->relations[$k];
}
$relClass = $rel->className;
if (!class_exists($relClass)) {
continue;
}
$relType = get_class($rel);
$relForeignKey = $rel->foreignKey;
$relTableModel = $relClass::model();
$relTable = $relTableModel->tableName();
$relPK = $relTableModel->metadata->tableSchema->primaryKey;
switch ($relType) {
case 'CHasOneRelation':
case 'CBelongsToRelation':
if (!empty($new)) {
$relForeignKey = $rel->foreignKey;
if ($this->{$relForeignKey} == $new[$relPK]) {
$model = $relClass::model()->findByPk($this->{$relForeignKey});
if (is_null($model)) {
$model = new $relClass();
}
if (array_diff($model->attributes, $new)) {
$model->attributes = $new;
if ($relType == 'CHasOneRelation') {
$model->{$relForeignKey} = $this->{$pk};
}
$model->save();
}
} else {
$this->loadRelation($rel->name);
}
}
break;
case 'CManyManyRelation':
case 'CHasManyRelation':
## if relation type is Many to Many, prepare required variable
$relMM = [];
if ($relType == 'CManyManyRelation') {
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative());
$stmts = $parser->parse('<?php ' . $relForeignKey . ';');
if (count($stmts) > 0) {
$relMM = ['tableName' => $stmts[0]->name->parts[0], 'from' => $stmts[0]->args[0]->value->name->parts[0], 'to' => $stmts[0]->args[1]->value->name->parts[0]];
}
}
## Handle Insert
if (isset($this->__relInsert[$k])) {
if ($k != 'currentModel') {
if (is_string($relForeignKey)) {
## without through
if ($relType != 'CManyManyRelation') {
foreach ($this->__relInsert[$k] as $n => $m) {
$this->__relInsert[$k][$n][$relForeignKey] = $this->{$pk};
}
}
} else {
if (is_array($relForeignKey)) {
## with through
foreach ($this->__relInsert[$k] as $n => $m) {
foreach ($relForeignKey as $rk => $fk) {
$this->__relInsert[$k][$n][$fk] = $this->__relations[$rel->through][$rk];
}
}
}
}
}
if (count($this->__relInsert[$k]) > 0) {
if ($relType == "CHasManyRelation") {
ActiveRecord::batchInsert($relClass, $this->__relInsert[$k]);
}
## if current relation is many to many
if ($relType == 'CManyManyRelation' && !empty($relMM)) {
$manyRel = [];
foreach ($this->__relInsert[$k] as $item) {
$manyRel[] = [$relMM['from'] => $this->{$pk}, $relMM['to'] => $item[$relPK]];
}
## if relinsert is already exist, then do not insert it again
foreach ($this->__relInsert[$k] as $insIdx => &$ins) {
if (!!@$ins[$relPK]) {
unset($this->__relInsert[$k]);
}
}
ActiveRecord::batchInsert($relClass, $this->__relInsert[$k]);
//.........这里部分代码省略.........