Properties

$actsAs

$actsAs : array

ビヘイビア

Type

array

$validate

$validate : array

Validation rules

Type

array

$useDbConfig

$useDbConfig : string

Use database config

Type

string

$blockId

$blockId : string

ブロックId Behaviorで関連データ削除する際に使用する

Type

string

$blockKey

$blockKey : string

ブロックKey Behaviorで関連データ削除する際に使用する

Type

string

$contentKey

$contentKey : string

コンテンツKey Behaviorで関連データ削除する際に使用する

Type

string

$uploadBasePath

$uploadBasePath : string

Type

string — UploadFileでアップロードする基準パス

$recursive

$recursive : integer

Type

integer — recursiveはデフォルトアソシエーションなしに

$hasMany

$hasMany : array

hasMany

Type

array

$__changeDbConfig

$__changeDbConfig : string

接続先DB master slave変更用

Type

string

$__oldSlaveDbConfig

$__oldSlaveDbConfig : string

接続先DB 古いslave保存用

Type

string

$__currentDir

$__currentDir : string

アップロードファイルを登録する際、 アップロードディレクトリのパスがWEB_ROOTパス配下になるのでUPLOADS_ROOTにchdirする必要があるため、 処理が終わったら元に戻すように現在のパスを保持しておく用の変数

Type

string — UploadFileでアップロードする基準パス

Methods

__construct()

__construct(boolean|integer|string|array  $id = false, string  $table = null, string  $ds = null) : void

Constructor. DataSourceの選択

接続先DBをランダムに選択します。

Parameters

boolean|integer|string|array $id

Set this ID for this model on startup, can also be an array of options, see above.

string $table

Name of database table to use.

string $ds

DataSource connection name.

setMasterDataSource()

setMasterDataSource() : void

Masterの接続先に変更する。

setSlaveDataSource()

setSlaveDataSource() : void

以前のSlaveの接続先に戻す。なければ、ランダムに選択

getDataSource()

getDataSource() : \DataSource

Gets the DataSource to which this model is bound.

Returns

\DataSource —

A DataSource object

create()

create(boolean|array  $data = array(), boolean  $filterKey = false) : array

NetCommonsで使用する共通の値がセットされた結果を返します。<br> CakePHPのSchemaは、not null指定されたカラムのdefaultがnullになっているため、<br> ''(長さ0の文字列)に書き換えています。<br> https://github.com/NetCommons3/NetCommons3/issues/7

セットされるデータ

'room_id' => Current::read('Room.id'),
'language_id' => Current::read('Language.id'),
'block_id' => Current::read('Block.id'),
'block_key' => Current::read('Block.key'),
'frame_id' => Current::read('Frame.id'),
'frame_key' => Current::read('Frame.key'),
'plugin_key' => Inflector::underscore($this->plugin),

Parameters

boolean|array $data

Optional data array to assign to the model after it is created. If null or false, schema data defaults are not merged.

boolean $filterKey

If true, overwrites any primary key input with an empty value

Returns

array —

The current Model::data; after merging $data and/or defaults from database

createAll()

createAll(boolean|array  $data = array(), boolean  $filterKey = false) : array

Initializes the model for writing a new record, loading the default values for those fields that are not defined in $data, and clearing previous validation errors.

Especially helpful for saving data in loops.

Parameters

boolean|array $data

Optional data array to assign to the model after it is created. If null or false, schema data defaults are not merged.

boolean $filterKey

If true, overwrites any primary key input with an empty value

Returns

array —

The current Model::data; after merging $data and/or defaults from database

begin()

begin() : void

transaction begin

commit()

commit() : void

transaction commit

rollback()

rollback(mixed  $ex = null) : void

transaction rollback

Parameters

mixed $ex

Exception

Throws

\Exception

loadModels()

loadModels(array  $models = array()) : void

Load models

Parameters

array $models

models to load

beforeValidate()

beforeValidate(array  $options = array()) : boolean

beforeValidate

Parameters

array $options

options

Returns

boolean

setOptions()

setOptions(array  $options) : void

ビヘイビア設定

Parameters

array $options

オプション

removeFile()

removeFile(integer  $contentId, integer  $fileId) : void

アップロードファイルとコンテンツとの関連づけ削除

Parameters

integer $contentId

コンテンツID

integer $fileId

アップロードファイルID

Throws

\InternalErrorException

deleteUploadFile()

deleteUploadFile(integer  $fileId) : boolean

Delete uploadFile

Parameters

integer $fileId

UploadFile.id

Returns

boolean

nameCallback()

nameCallback(string  $field, string  $currentName, array  $data, array  $options) : string

nameCallback method

Parameters

string $field

Name of field being modified

string $currentName

current filename

array $data

Array of data being manipulated in the current request

array $options

Array of options for the current rename

Returns

string —

file name

beforeSave()

beforeSave(array  $options = array()) : void

beforeSave

ファイルの保存先を設定 トータルダウンロード数を設定

Parameters

array $options

オプション

afterSave()

afterSave(boolean  $created, array  $options = array()) : void

save()実行後に呼ばれるメソッド

Parameters

boolean $created

新しいレコードが作成された場合はTrue

array $options

Model::save()のオプション

getFile()

getFile(string  $pluginKey, integer  $contentId, string  $fieldName) : array|false

ファイル情報取得

Parameters

string $pluginKey

プラグインキー

integer $contentId

コンテンツID

string $fieldName

フィールド名

Returns

array|false

getFileByContentKey()

getFileByContentKey(string  $pluginKey, string  $contentKey, string  $fieldName) : array|false

ファイル情報取得

アバターなどは、UploadFilesContentを見る必要がないので、ContentKeyでファイル情報を取得できるようにする

Parameters

string $pluginKey

プラグインキー

string $contentKey

コンテンツキー

string $fieldName

フィールド名

Returns

array|false

countUp()

countUp(array  $data) : void

ダウンロードカウントアップ

Parameters

array $data

UploadFileデータ

Throws

\InternalErrorException

registByFile()

registByFile(\File|string  $file, string  $pluginKey, string  $contentKey, string  $fieldName, array  $data = array()) : array

FileインスタンスのファイルをUplodFileに登録する

Parameters

\File|string $file

登録するファイルのFileインスタンス OR ファイルパス

string $pluginKey

プラグインキー

string $contentKey

コンテンツキー

string $fieldName

フィールド名

array $data

データ登録時に上書きしたいデータを渡す

Throws

\InternalErrorException

Returns

array

makeLink()

makeLink(string  $pluginKey, integer  $contentId, integer  $uploadFileId) : void

関連テーブルにコンテンツとUploadFileとの関連データを作成

Parameters

string $pluginKey

プラグインキー

integer $contentId

コンテンツID

integer $uploadFileId

アップロードファイルID

Throws

\InternalErrorException

deleteLink()

deleteLink(string  $pluginKey, integer  $contentId, string  $fieldName = null) : void

関連テーブルデータの削除

Parameters

string $pluginKey

プラグインキー

integer $contentId

コンテンツID

string $fieldName

フィールド名

attach()

attach(string  $pluginKey, string  $contentKey, integer  $contentId, string  $fieldName, \File  $file) : void

添付ファイルをDBに登録する

Parameters

string $pluginKey

登録するプラグイン名

string $contentKey

コンテンツキー

integer $contentId

コンテンツID

string $fieldName

フィールド名

\File $file

登録するファイルのFileインスタンス

getRealFilePath()

getRealFilePath(array  $uploadFileData) : string

UploadFileに登録済みの実ファイルのパスを返す

Parameters

array $uploadFileData

UploadFile

Returns

string —

実ファイルパス

_getDefaultValue()

_getDefaultValue() : array

全カラムのデフォルト値をセットした配列を返す。

Returns

array —

デフォルト値をセットした配列

_doSave()

_doSave(array  $data = null, array  $options = array()) : mixed

cakephpの登録処理をオーバーライド

cakephpのsave時にcreated,modifiedの項目にセットする時間が、date_default_timezone_setに影響してしまうため、 登録直前にUTCに変更し、登録後にdate_default_timezone_setを元に戻すため、オーバライドする

Parameters

array $data

Data to save.

array $options

can have following keys:

  • validate: Set to true/false to enable or disable validation.
  • fieldList: An array of fields you want to allow for saving.
  • callbacks: Set to false to disable callbacks. Using 'before' or 'after' will enable only those callbacks.
  • counterCache: Boolean to control updating of counter caches (if any)

Throws

\PDOException

Returns

mixed —

On success Model::$data if its not empty or true, false on failure

_readDataSource()

_readDataSource(string  $type, array  $query) : array

Findの結果をキャッシュする際、afterFindは実行させたいので、CakeのModelを継承して、カスタマイズする。

Parameters

string $type

Type of find operation (all / first / count / neighbors / list / threaded)

array $query

Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)

Returns

array

_deleteNoRelationUploadFile()

_deleteNoRelationUploadFile(array  $link) : void

関連テーブルデータがひとつもないUploadFileレコードを削除する

Parameters

array $link

UploadFilesContent関連レコードのデータ

Throws

\InternalErrorException

__getRandomlySlave()

__getRandomlySlave() : string

Find the slaves we have

Returns

string —

The name of the DataSource, as defined in app/Config/database.php

__changeDataSource()

__changeDataSource() : void

MasterDBに切り替える処理