本文整理汇总了PHP中DataObject::onBeforeWrite方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::onBeforeWrite方法的具体用法?PHP DataObject::onBeforeWrite怎么用?PHP DataObject::onBeforeWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObject
的用法示例。
在下文中一共展示了DataObject::onBeforeWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBeforeWrite
/**
* Automatically set Code
*/
function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->Code) {
$this->Code = md5(rand(0, 10000));
}
}
示例2: onBeforeWrite
public function onBeforeWrite()
{
if (!$this->AuthorID) {
$this->AuthorID = Member::currentUserID();
}
parent::onBeforeWrite();
}
示例3: onBeforeWrite
/**
* Set the owner automatically if needed
*/
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->OwnerID) {
$this->OwnerID = Member::currentUserID();
}
}
示例4: onBeforeWrite
protected function onBeforeWrite()
{
if ($this->isChanged('ParentClass')) {
$this->ParentClass = ClassInfo::baseDataClass($this->ParentClass);
}
parent::onBeforeWrite();
}
示例5: onBeforeWrite
/**
* Ensure a sort value is set
*/
public function onBeforeWrite()
{
if (!$this->Sort) {
$this->Sort = DB::query('SELECT MAX("Sort") + 1 FROM "WorkflowDefinition"')->value();
}
parent::onBeforeWrite();
}
示例6: onBeforeWrite
/**
* Sanitise the identifier and populate the variables list
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();
$slug = singleton('SiteTree')->generateURLSegment($this->Identifier);
$original_slug = $slug;
$i = 0;
while ($t = PermamailTemplate::get()->filter(array("Identifier" => "{$slug}"))->exclude(array("ID" => $this->ID))->first()) {
$i++;
$slug = $original_slug . "-{$i}";
}
$this->Identifier = $slug;
$reflector = EmailReflectionTemplate::create();
$reflector->process($this->Content);
$vars = array();
foreach ($reflector->getTopLevelVars() as $var => $type) {
$vars[$var] = false;
}
foreach ($reflector->getTopLevelBlocks() as $block) {
$vars[$block->getName()] = $block->isLoop();
}
// Remove any variables that are no longer in the template
if ($this->TestVariables()->exists()) {
$this->TestVariables()->exclude(array('Variable' => array_keys($vars)))->removeAll();
}
$currentVars = $this->TestVariables()->column('Variable');
foreach ($vars as $var => $isList) {
if (!in_array($var, $currentVars)) {
$v = PermamailTemplateVariable::create(array('Variable' => $var, 'PermamailTemplateID' => $this->ID, 'List' => $isList));
$v->write();
}
}
}
示例7: onBeforeWrite
function onBeforeWrite()
{
parent::onBeforeWrite();
if (empty($this->EventDate)) {
$this->EventDate = time();
}
}
示例8: onBeforeWrite
public function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->ID && !$this->Title) {
throw new Exception("Invalid title");
}
}
示例9: onBeforeWrite
/**
* Generate the title if needed
*/
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->Title) {
$this->Title = empty($this->Query) ? "Search" : "Search: {$this->Query}";
}
}
示例10: onBeforeWrite
/**
* These actions are performed when write() is called on this object.
*/
public function onBeforeWrite() {
// save submitter if a Member is logged in
$currentMember = Member::currentMember();
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
parent::onBeforeWrite();
}
示例11: onBeforeWrite
function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->UniqueHash) {
$this->UniqueHash = md5(strtotime('now') . '|' . rand());
}
}
示例12: onBeforeWrite
public function onBeforeWrite()
{
if ($this->ISBN != null && $this->Title == null) {
$postURL = "https://www.googleapis.com/books/v1/volumes?q=isbn:" . $this->ISBN . "&key=" . self::$googlebooksapi_key;
$json = json_decode(file_get_contents($postURL), true);
$info = $json["items"][0]["volumeInfo"];
if (array_key_exists('title', $info)) {
$this->Title = $info['title'];
}
if (array_key_exists('subtitle', $info)) {
$this->Subtitle = $info['subtitle'];
}
if (array_key_exists('thumbnail', $info['imageLinks'])) {
$this->Thumbnail = $info['imageLinks']['thumbnail'];
}
if (array_key_exists('authors', $info)) {
$this->Author = $info['authors'][0];
}
if (array_key_exists('pageCount', $info)) {
$this->Pages = $info['pageCount'];
}
if (array_key_exists('publisher', $info)) {
$this->Publisher = $info['publisher'];
}
if (array_key_exists('description', $info)) {
$this->Description = $info['description'];
}
}
parent::onBeforeWrite();
}
示例13: onBeforeWrite
function onBeforeWrite()
{
$media = $this->Device;
switch ($media) {
case 'iphone':
$this->setField('Media', '(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)');
break;
case 'iphone-tall':
$this->setField('Media', '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)');
break;
case 'iphone-retina':
$this->setField('Media', '(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)');
break;
case 'ipad-portrait':
$this->setField('Media', '(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)');
break;
case 'ipad-landscape':
$this->setField('Media', '(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)');
break;
case 'ipad-retina-portrait':
$this->setField('Media', '(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)');
break;
case 'ipad-retina-landscape':
$this->setField('Media', '(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)');
break;
}
parent::onBeforeWrite();
}
示例14: onBeforeWrite
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->Date) {
$this->Date = date('Y-m-d H:i:s');
}
}
示例15: onBeforeWrite
/**
* Hook on before write
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->Title) {
$this->Title = 'New ' . strtolower(self::$singular_name);
}
}