/** * Automatically set Code */ function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Code) { $this->Code = md5(rand(0, 10000)); } }
public function onBeforeWrite() { if (!$this->AuthorID) { $this->AuthorID = Member::currentUserID(); } parent::onBeforeWrite(); }
/** * Set the owner automatically if needed */ protected function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->OwnerID) { $this->OwnerID = Member::currentUserID(); } }
protected function onBeforeWrite() { if ($this->isChanged('ParentClass')) { $this->ParentClass = ClassInfo::baseDataClass($this->ParentClass); } parent::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(); }
/** * 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(); } } }
function onBeforeWrite() { parent::onBeforeWrite(); if (empty($this->EventDate)) { $this->EventDate = time(); } }
public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->ID && !$this->Title) { throw new Exception("Invalid title"); } }
/** * Generate the title if needed */ protected function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Title) { $this->Title = empty($this->Query) ? "Search" : "Search: {$this->Query}"; } }
/** * 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(); }
function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->UniqueHash) { $this->UniqueHash = md5(strtotime('now') . '|' . rand()); } }
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(); }
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(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Date) { $this->Date = date('Y-m-d H:i:s'); } }
/** * Hook on before write */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Title) { $this->Title = 'New ' . strtolower(self::$singular_name); } }
protected function onBeforeWrite() { if (!$this->SortOrder) { $this->SortOrder = $this::get()->max("SortOrder") + 1; } return parent::onBeforeWrite(); }
protected function onBeforeWrite() { parent::onBeforeWrite(); if ($this->CreatedBy()->inGroup(Survey::SurveyTestersGroupSlug)) { $this->IsTest = true; } }
public function onBeforeWrite() { parent::onBeforeWrite(); $shopConfig = ShopConfig::current_shop_config(); $this->BaseCurrency = $shopConfig->BaseCurrency; $this->BaseCurrencySymbol = $shopConfig->BaseCurrencySymbol; }
public function onBeforeWrite() { // If there is no URLSegment set, generate one from Title if ((!$this->URLSegment || $this->URLSegment == 'new-product') && $this->Title != 'New Product') { $siteTree = DataList::create('SiteTree')->first(); $this->URLSegment = $siteTree->generateURLSegment($this->Title); } else { if ($this->isChanged('URLSegment')) { // Make sure the URLSegment is valid for use in a URL $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->URLSegment); $segment = preg_replace('/-+/', '-', $segment); // If after sanitising there is no URLSegment, give it a reasonable default if (!$segment) { $segment = "product-{$this->ID}"; } $this->URLSegment = $segment; } } // Ensure that this object has a non-conflicting URLSegment value. $count = 2; while ($this->LookForExistingURLSegment($this->URLSegment)) { $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count; $count++; } parent::onBeforeWrite(); }
public function onBeforeWrite() { if (!$this->Date) { $this->Date = date('Y-m-d'); } parent::onBeforeWrite(); }
/** * Ensure we populate these fields before a save. */ public function onBeforeWrite() { // Run other beforewrites first. parent::onBeforeWrite(); if (!$this->isBrowser()) { return false; } // If this is the first save... if (!$this->ID) { // Ensure the session exists before querying it. if (!Session::request_contains_session_id()) { Session::start(); } // Store the sesion and has information in the database. $this->SessionID = SecurityToken::getSecurityID(); if (is_null($this->SessionID)) { return false; } $gen = new RandomGenerator(); $uniqueurl = substr($gen->randomToken(), 0, 32); while (ShortList::get()->filter('URL', $uniqueurl)->count() > 0) { $uniqueurl = substr($gen->randomToken(), 0, 32); } $this->URL = $uniqueurl; $this->UserAgent = Controller::curr()->getRequest()->getHeader('User-Agent'); } }
public function onBeforeWrite() { parent::onBeforeWrite(); if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $this->Code, $match)) { $this->Code = $match[1]; } }
protected function onBeforeWrite() { if (!class_exists('Payment')) { $this->Type = 'Free'; } parent::onBeforeWrite(); }
protected function onBeforeWrite() { parent::onBeforeWrite(); if (empty($this->Reference)) { $this->Reference = uniqid(); } }
function onBeforeWrite() { parent::onBeforeWrite(); // If there is no URLSegment set, generate one from Title if ((!$this->URLSegment || $this->URLSegment == 'new-presentation') && $this->Title != 'New Presentation') { $this->URLSegment = $this->generateURLSegment($this->Title); } else { if ($this->isChanged('URLSegment')) { // Make sure the URLSegment is valid for use in a URL $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->URLSegment); $segment = preg_replace('/-+/', '-', $segment); // If after sanitising there is no URLSegment, give it a reasonable default if (!$segment) { $segment = "presentation-" . $this->ID; } $this->URLSegment = $segment; } } // Ensure that this object has a non-conflicting URLSegment value by appending number if needed $count = 2; while ($this->LookForExistingURLSegment($this->URLSegment)) { $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count; $count++; } }
/** * Save selected attributes - somewhat of a hack. */ public function onBeforeWrite() { parent::onBeforeWrite(); if (isset($_POST['ProductAttributes']) && is_array($_POST['ProductAttributes'])) { $this->AttributeValues()->setByIDList(array_values($_POST['ProductAttributes'])); } }
function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->KeepClean) { $this->IsDirty = true; } }
protected function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Sort) { $this->Sort = MemberProfileField::get()->max('Sort') + 1; } }
function onBeforeWrite() { parent::onBeforeWrite(); if ($this->ParentID) { self::update_ratings($this->ParentID); } }
protected function onBeforeWrite() { if ($this->LinkID) { $this->NewsletterID = $this->Link()->NewsletterID; } parent::onBeforeWrite(); }