本文整理汇总了PHP中BaseElementModel类的典型用法代码示例。如果您正苦于以下问题:PHP BaseElementModel类的具体用法?PHP BaseElementModel怎么用?PHP BaseElementModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseElementModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTableAttributeHtml
/**
* Returns the table view HTML for a given attribute.
*
* @param BaseElementModel $element
* @param string $attribute
* @return string
*/
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
switch ($attribute) {
case 'mode':
return ucwords($element->mode);
case 'planAmount':
if ($element->planType == 'recurring') {
return $element->formatPlanName();
} else {
return $element->formatPlanAmount();
}
case 'customerName':
return $element->customerName . ' <a href="mailto:' . $element->customerEmail . '">' . $element->customerEmail . '</a>';
case 'cardLast4':
return '<span class="cardType type' . $element->cardType . '"></span> ' . $element->formatCard();
case 'planType':
if ($element->planType == 'recurring') {
return ucwords($element->planType);
} else {
return 'One-time';
}
case 'timestamp':
if ($element->timestamp) {
return $element->timestamp->localeDate();
} else {
return '';
}
}
}
示例2: prepElementContentForSave
/**
* Prepares an element's content for being saved to the database.
*
* @param BaseElementModel $element
* @param FieldLayoutModel $fieldLayout
* @param bool $validate
* @return ContentModel
*/
public function prepElementContentForSave(BaseElementModel $element, FieldLayoutModel $fieldLayout, $validate = true)
{
$elementTypeClass = $element->getElementType();
$elementType = craft()->elements->getElementType($elementTypeClass);
$content = $element->getContent();
if ($validate) {
// Set the required fields from the layout
$requiredFields = array();
if ($elementType->hasTitles()) {
$requiredFields[] = 'title';
}
foreach ($fieldLayout->getFields() as $field) {
if ($field->required) {
$requiredFields[] = $field->fieldId;
}
}
if ($requiredFields) {
$content->setRequiredFields($requiredFields);
}
}
// Give the fieldtypes a chance to clean up the post data
foreach (craft()->fields->getAllFields() as $field) {
$fieldType = craft()->fields->populateFieldType($field);
if ($fieldType) {
$fieldType->element = $element;
$handle = $field->handle;
$content->{$handle} = $fieldType->prepValueFromPost($content->{$handle});
}
}
return $content;
}
示例3: getElementOptionsHtml
public function getElementOptionsHtml(BaseElementModel $element)
{
$isNew = $element->id === null;
$locales = array_keys($element->getLocales());
$settings = craft()->plugins->getPlugin('localeSync')->getSettings();
if ($isNew || count($locales) < 2) {
return;
}
return craft()->templates->render('localesync/_cp/entriesEditRightPane', ['settings' => $settings, 'localeId' => $element->locale]);
}
示例4: getTableAttributeHtml
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
switch ($attribute) {
case 'data':
$data = $element->_normalizeDataForElementsTable();
return $element->data;
break;
default:
return parent::getTableAttributeHtml($element, $attribute);
break;
}
}
示例5: getTableAttributeHtml
/**
* Get Tablet Attribute HTML
*
*/
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
switch ($attribute) {
case 'submission':
$data = $element->viewEntryLinkOnElementsTable();
return $element->submission;
break;
case 'files':
$files = $element->normalizeFilesForElementsTable();
return $element->files;
break;
default:
return parent::getTableAttributeHtml($element, $attribute);
break;
}
}
示例6: getTableAttributeHtml
/**
* Return table attribute html.
*
* @param BaseElementModel $element
* @param string $attribute
*
* @return string
*/
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
// First give plugins a chance to set this
$pluginAttributeHtml = craft()->plugins->callFirst('getAuditLogTableAttributeHtml', array($element, $attribute), true);
// Check if that had a valid result
if ($pluginAttributeHtml) {
return $pluginAttributeHtml;
}
// Modify custom attributes
switch ($attribute) {
// Format dates
case 'dateCreated':
case 'dateUpdated':
return craft()->dateFormatter->formatDateTime($element->{$attribute});
// Return clickable user link
// Return clickable user link
case 'user':
$user = $element->getUser();
return $user ? '<a href="' . $user->getCpEditUrl() . '">' . $user . '</a>' : Craft::t('Guest');
// Return clickable event origin
// Return clickable event origin
case 'origin':
return '<a href="' . preg_replace('/' . craft()->config->get('cpTrigger') . '\\//', '', UrlHelper::getUrl($element->origin), 1) . '">' . $element->origin . '</a>';
// Return view changes button
// Return view changes button
case 'changes':
return '<a class="btn" href="' . UrlHelper::getCpUrl('auditlog/' . $element->id) . '">' . Craft::t('View') . '</a>';
// Default behavior
// Default behavior
default:
return $element->{$attribute};
}
}
示例7: indexElementAttributes
/**
* Indexes the attributes of a given element defined by its element type.
*
* @param BaseElementModel $element
* @param string|null $localeId
* @return bool Whether the indexing was a success.
*/
public function indexElementAttributes(BaseElementModel $element, $localeId = null)
{
// Get the element type
$elementTypeClass = $element->getElementType();
$elementType = craft()->elements->getElementType($elementTypeClass);
// Does it have any searchable attributes?
$searchableAttributes = $elementType->defineSearchableAttributes();
if ($elementType->hasTitles()) {
$searchableAttributes[] = 'title';
}
foreach ($searchableAttributes as $attribute) {
$value = $element->{$attribute};
$value = StringHelper::arrayToString($value);
$this->_indexElementKeywords($element->id, $attribute, '0', $localeId, $value);
}
return true;
}
示例8: process
/**
* Upload and process the result.
*
* @param BaseElementModel $element
* @param AssetFileModel $asset
* @param string $handle
*
* @return bool
*/
public function process(BaseElementModel $element, AssetFileModel $asset, $handle)
{
// Check if we have this asset already or upload to YouTube
if (!($youTubeId = $this->exists($asset))) {
try {
$youTubeId = $this->assemble($asset);
} catch (Exception $e) {
return $e->getMessage();
}
}
// Get current video's
$content = $element->getContent()->getAttribute($handle);
// Make sure content's an array
$content = is_array($content) ? $content : array();
// Remove this asset's id from the content
unset($content[array_search($asset->id, $content)]);
// Add video to (existing) content
$element->getContent()->{$handle} = array_merge($content, array($youTubeId));
// Save the content without validation
craft()->content->saveContent($element, false);
// All went well
return true;
}
示例9: prepForElementModel
/**
* Prepare reserved ElementModel values.
*
* @param array &$fields
* @param BaseElementModel $element
*
* @return BaseElementModel
*/
public function prepForElementModel(array &$fields, BaseElementModel $element)
{
// Set slug
$slug = Import_ElementModel::HandleSlug;
if (isset($fields[$slug])) {
$element->{$slug} = ElementHelper::createSlug($fields[$slug]);
unset($fields[$slug]);
}
// Set title
$title = Import_ElementModel::HandleTitle;
if (isset($fields[$title])) {
$element->getContent()->{$title} = $fields[$title];
unset($fields[$title]);
}
// Return element
return $element;
}
示例10: onAfterMoveElementInStructure
/**
* @inheritDoc IElementType::onAfterMoveElementInStructure()
*
* @param BaseElementModel $element
* @param int $structureId
*
* @return null|void
*/
public function onAfterMoveElementInStructure(BaseElementModel $element, $structureId)
{
// Was the entry moved within its section's structure?
$section = $element->getSection();
if ($section->type == SectionType::Structure && $section->structureId == $structureId) {
craft()->elements->updateElementSlugAndUri($element, true, true, true);
}
}
示例11: getEditorHtml
/**
* @inheritDoc IElementType::getEditorHtml()
*
* @param BaseElementModel $element
*
* @return string
*/
public function getEditorHtml(BaseElementModel $element)
{
return sprintf('<div class="pane"><a class="btn submit" href="%s" target="_blank">%s</a></div>', $element->getCpEditUrl(), Craft::t('Edit form'));
}
示例12: defineAttributes
/**
* @access protected
* @return array
*/
protected function defineAttributes()
{
// Craft email settings
$settings = craft()->email->getSettings();
$systemEmail = !empty($settings['emailAddress']) ? $settings['emailAddress'] : '';
$systemName = !empty($settings['senderName']) ? $settings['senderName'] : '';
return array_merge(parent::defineAttributes(), array('id' => AttributeType::Number, 'fieldLayoutId' => AttributeType::Number, 'redirectEntryId' => AttributeType::Number, 'name' => AttributeType::String, 'handle' => AttributeType::String, 'titleFormat' => array(AttributeType::String, 'default' => "{dateCreated|date('D, d M Y H:i:s')}"), 'submitAction' => AttributeType::String, 'submitButton' => AttributeType::String, 'afterSubmitText' => AttributeType::Mixed, 'submissionEnabled' => array(AttributeType::Bool, 'default' => true), 'sendCopy' => array(AttributeType::Bool, 'default' => false), 'sendCopyTo' => AttributeType::String, 'notificationEnabled' => array(AttributeType::Bool, 'default' => true), 'notificationFilesEnabled' => array(AttributeType::Bool, 'default' => false), 'notificationRecipients' => array(AttributeType::String, 'default' => $systemEmail), 'notificationSubject' => array(AttributeType::String, 'default' => Craft::t('{formName} form was submitted')), 'notificationSenderName' => array(AttributeType::String, 'default' => $systemName), 'notificationSenderEmail' => array(AttributeType::String, 'default' => $systemEmail), 'notificationReplyToEmail' => array(AttributeType::String, 'default' => $systemEmail), 'formTemplate' => AttributeType::String, 'tabTemplate' => AttributeType::String, 'fieldTemplate' => AttributeType::String, 'notificationTemplate' => AttributeType::String));
}
示例13: isFresh
/**
* Returns whether this is the first time the element's content has been edited.
*
* @return bool
*/
protected function isFresh()
{
// If this is for a Matrix block, we're more interested in its owner
if (isset($this->element) && $this->element->getElementType() == ElementType::MatrixBlock) {
$element = $this->element->getOwner();
} else {
$element = $this->element;
}
return !$element || empty($element->getContent()->id) && !$element->hasErrors();
}
示例14: isFresh
/**
* Returns whether this is the first time the element's content has been edited.
*
* @return bool
*/
protected function isFresh()
{
if (!isset($this->_isFresh)) {
if (isset($this->element)) {
$this->_isFresh = $this->element->getHasFreshContent();
} else {
$this->_isFresh = true;
}
}
return $this->_isFresh;
}
示例15: getStatus
/**
* Returns the element's status.
*
* @return string|null
*/
public function getStatus()
{
$status = parent::getStatus();
if ($status == static::ENABLED && $this->postDate) {
$currentTime = DateTimeHelper::currentTimeStamp();
$postDate = $this->postDate->getTimestamp();
$expiryDate = $this->expiryDate ? $this->expiryDate->getTimestamp() : null;
if ($postDate <= $currentTime && (!$expiryDate || $expiryDate > $currentTime)) {
return static::LIVE;
} else {
if ($postDate > $currentTime) {
return static::PENDING;
} else {
return static::EXPIRED;
}
}
}
return $status;
}