本文整理汇总了PHP中modResource::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP modResource::toArray方法的具体用法?PHP modResource::toArray怎么用?PHP modResource::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modResource
的用法示例。
在下文中一共展示了modResource::toArray方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Process this page, load the resource, and present its values
* @return void
*/
public function process()
{
$useRichtext = $this->modx->getOption('handyman.useRichtext', null, true);
if ($useRichtext && $this->resource->get('richtext')) {
$this->allowRichtext = true;
if (intval($this->config['gpc']['nort'])) {
$this->setPlaceholder('richtextStatus', 2);
} else {
$this->setPlaceholder('richtextStatus', 1);
}
} else {
$this->setPlaceholder('richtextStatus', 0);
}
$this->setPlaceholders($this->resource->toArray());
$this->modx->loadClass('hmInputRenderer', $this->hm->config['classesPath'], true, true);
$this->renderer = new hmInputRenderer($this->hm, $this->resource->toArray());
$clearCache = array('type' => 'boolean', 'name' => 'clearCache', 'title' => $this->modx->lexicon('clear_cache_on_save'), 'value' => true);
$clearCache = $this->renderer->render('boolean', $clearCache);
$this->setPlaceholder('clearCache', $clearCache);
$content = array('type' => 'richtext', 'name' => 'content', 'title' => $this->modx->lexicon('resource_content'), 'value' => $this->resource->get('content'));
$content = $this->renderer->render('richtext', $content);
$this->setPlaceholder('content', $content);
$this->getResourceFields();
$this->getResourceSettings();
$this->getTemplateVariables();
}
示例2: process
public function process()
{
$resourceArray = $this->resource->toArray('', true, true);
$resourceArray = $this->getChanges($resourceArray);
/* template */
if (empty($resourceArray['template_name'])) {
$resourceArray['template_name'] = $this->modx->lexicon('empty_template');
}
/* source */
$resourceArray['buffer'] = $this->getCacheSource();
return $this->success('', $resourceArray);
}
示例3: process
/**
* Process this page, load the resource, and present its values
* @return void
*/
public function process()
{
$this->setPlaceholders($this->resource->toArray());
$this->template = $this->resource->getOne('Template');
if ($this->template) {
$this->setPlaceholder('template', $this->template->get('templatename'));
}
$contentType = $this->resource->getOne('ContentType');
if ($contentType) {
$this->setPlaceholder('content_type', $contentType->get('name'));
}
$this->getContent();
$this->getResourceFields();
$this->getResourceSettings();
if ($this->template) {
$this->getTemplateVariables();
}
}
示例4: process
public function process(array $scriptProperties = array())
{
$placeholders = array();
$reloadData = $this->getReloadData();
$loaded = $this->getResource();
if ($loaded !== true) {
return $this->failure($loaded);
}
if (is_array($reloadData) && !empty($reloadData)) {
$this->resource->fromArray($reloadData);
}
/* get context */
$this->setContext();
/* check for locked status */
$this->checkForLocks();
/* set template overrides */
if (isset($scriptProperties['template'])) {
$this->resource->set('template', $scriptProperties['template']);
}
$this->setParent();
/* invoke OnDocFormRender event */
$this->fireOnRenderEvent();
/* check permissions */
$this->setPermissions();
/* register FC rules */
$this->resourceArray = $this->resource->toArray();
$overridden = $this->checkFormCustomizationRules($this->resource);
$this->resourceArray = array_merge($this->resourceArray, $overridden);
$this->resourceArray['published'] = intval($this->resourceArray['published']) == 1 ? true : false;
$this->resourceArray['hidemenu'] = intval($this->resourceArray['hidemenu']) == 1 ? true : false;
$this->resourceArray['isfolder'] = intval($this->resourceArray['isfolder']) == 1 ? true : false;
$this->resourceArray['richtext'] = intval($this->resourceArray['richtext']) == 1 ? true : false;
$this->resourceArray['searchable'] = intval($this->resourceArray['searchable']) == 1 ? true : false;
$this->resourceArray['cacheable'] = intval($this->resourceArray['cacheable']) == 1 ? true : false;
$this->resourceArray['deleted'] = intval($this->resourceArray['deleted']) == 1 ? true : false;
$this->resourceArray['uri_override'] = intval($this->resourceArray['uri_override']) == 1 ? true : false;
if (!empty($this->resourceArray['parent'])) {
if ($this->parent->get('id') == $this->resourceArray['parent']) {
$this->resourceArray['parent_pagetitle'] = $this->parent->get('pagetitle');
} else {
$overriddenParent = $this->modx->getObject('modResource', $this->resourceArray['parent']);
if ($overriddenParent) {
$this->resourceArray['parent_pagetitle'] = $overriddenParent->get('pagetitle');
}
}
}
/* get TVs */
$this->resource->set('template', $this->resourceArray['template']);
$this->prepareResource();
$this->loadTVs($reloadData);
$this->getPreviewUrl();
/* single-use token for reloading resource */
$this->setResourceToken();
$this->setPlaceholder('resource', $this->resource);
return $placeholders;
}
示例5: saveMarkdown
private function saveMarkdown()
{
$resourceArray = $this->resource->toArray();
$mode = $this->sp['mode'];
$deleteUnused = (int) $this->md->getOption('upload.delete_unused', null, 1);
$underResource = (int) $this->md->getOption('upload.under_resource', null, 1);
if ($mode == \modSystemEvent::MODE_UPD) {
if ($deleteUnused && $underResource) {
$this->uploadedFiles();
}
}
foreach ($resourceArray as $field => $value) {
if (!strpos($field, '_markdown')) {
continue;
}
$fieldName = str_replace('_markdown', '', $field);
$markdown = $this->modx->fromJSON($this->resource->getProperty('markdown', 'markdowneditor', '[]'));
if ($mode == \modSystemEvent::MODE_NEW) {
if ($underResource) {
$this->moveFilesUnderCorrectResource($value, $fieldName);
}
}
if ($mode == \modSystemEvent::MODE_UPD) {
if ($deleteUnused && $underResource) {
$this->unsetUnusedFiles($value);
}
}
$markdown[$fieldName] = $value;
$this->resource->setProperty('markdown', $this->modx->toJSON($markdown), 'markdowneditor');
$this->resource->save();
$this->resource->{$field} = '';
}
if ($mode == \modSystemEvent::MODE_UPD) {
if ($deleteUnused && $underResource) {
$this->deleteUnusedFiles();
}
}
}
示例6: synchronize
/**
* Synchronize Resource and its TVs to the translations of the defined languages
* @param modResource $resource
* @return boolean
*/
public function synchronize(modResource $resource)
{
$resourceArray = $resource->toArray();
$this->modx->resource = $resource;
$languages = $this->getLanguages(true, true, false);
if ($languages) {
$langCodes = array();
foreach ($languages as $language) {
$langCodes[] = $language['lang_code'];
}
// first, delete unused translation
$c = $this->modx->newQuery('linguaSiteContent');
$c->innerJoin('linguaLangs', 'Lang');
$c->where(array('linguaSiteContent.resource_id:=' => $resourceArray['id'], 'Lang.lang_code:NOT IN' => $langCodes));
$unusedContents = $this->modx->getCollection('linguaSiteContent', $c);
if ($unusedContents) {
foreach ($unusedContents as $item) {
$item->remove();
}
}
foreach ($languages as $language) {
$this->setContentTranslation($resourceArray['id'], $language['lang_code'], $resourceArray, false);
}
$tvs = $resource->getTemplateVars();
$translatedTvs = $this->modx->getCollection('linguaSiteTmplvars');
if ($translatedTvs && $tvs) {
$translatedTvsArray = array();
foreach ($translatedTvs as $translatedTv) {
$translatedTvsArray[] = $translatedTv->get('tmplvarid');
}
foreach ($tvs as $tv) {
// first, delete unused translation
$c = $this->modx->newQuery('linguaSiteTmplvarContentvalues');
$c->innerJoin('linguaLangs', 'Lang');
$c->where(array('linguaSiteTmplvarContentvalues.contentid:=' => $resourceArray['id'], 'linguaSiteTmplvarContentvalues.tmplvarid:=' => $tv->get('id'), 'Lang.lang_code:NOT IN' => $langCodes));
$unusedContents = $this->modx->getCollection('linguaSiteTmplvarContentvalues', $c);
if ($unusedContents) {
foreach ($unusedContents as $item) {
$item->remove();
}
}
if (!in_array($tv->get('id'), $translatedTvsArray)) {
continue;
}
$this->setTVTranslation($resourceArray['id'], $language['lang_code'], $tv->get('id'), $tv->get('value'), false);
}
}
}
return true;
}
示例7: toArray
/**
* @param string $keyPrefix
* @param bool $rawValues
* @param bool $excludeLazy
* @param bool $includeRelated
*
* @return array
*/
public function toArray($keyPrefix = '', $rawValues = false, $excludeLazy = false, $includeRelated = false)
{
$array = array_merge(parent::toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated), $this->getVirtualFields());
return $array;
}
示例8: toArray
/**
* {@inheritdoc}
*/
public function toArray($keyPrefix = '', $rawValues = false, $excludeLazy = false, $includeRelated = false)
{
$array = parent::toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated);
if ($this->data === null) {
$this->loadData();
}
if ($this->vendor === null) {
$this->loadVendor();
}
$this->loadOptions();
return array_merge($array, $this->data->toArray(), $this->vendor->toArray('vendor.'), $this->options);
}
示例9: duplicateResource
/**
* Creates a duplicate of the specified resource in the specified context.
*
* @param modResource $resource
* @param string $contextKey
*/
public function duplicateResource(&$resource, $contextKey)
{
/* determine parent id of new resource */
$newParentId = null;
$parentId = $resource->get('parent');
if ($parentId != null) {
$linkedParentResources = $this->getLinkedResources($parentId);
if (isset($linkedParentResources[$contextKey])) {
$newParentId = $linkedParentResources[$contextKey];
}
}
/* create new resource */
$newResource = $this->modx->newObject($resource->get('class_key'));
$newResource->fromArray($resource->toArray('', true), '', false, true);
$newResource->set('id', 0);
$newResource->set('pagetitle', $resource->get('pagetitle') . ' ' . $this->modx->lexicon('babel.translation_pending'));
$newResource->set('parent', intval($newParentId));
$newResource->set('createdby', $this->modx->user->get('id'));
$newResource->set('createdon', time());
$newResource->set('editedby', 0);
$newResource->set('editedon', 0);
$newResource->set('deleted', false);
$newResource->set('deletedon', 0);
$newResource->set('deletedby', 0);
$newResource->set('published', false);
$newResource->set('publishedon', 0);
$newResource->set('publishedby', 0);
$newResource->set('context_key', $contextKey);
if ($newResource->save()) {
/* copy all TV values */
$templateVarResources = $resource->getMany('TemplateVarResources');
foreach ($templateVarResources as $oldTemplateVarResource) {
$newTemplateVarResource = $this->modx->newObject('modTemplateVarResource');
$newTemplateVarResource->set('contentid', $newResource->get('id'));
$newTemplateVarResource->set('tmplvarid', $oldTemplateVarResource->get('tmplvarid'));
$newTemplateVarResource->set('value', $oldTemplateVarResource->get('value'));
$newTemplateVarResource->save();
}
/* set parent of duplicate as a folder */
if ($newParentId) {
$newParent = $this->modx->getObject('modResource', $newParentId);
if ($newParent) {
$newParent->set('is_folder', 1);
$newParent->save();
}
}
} else {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not duplicate resource: ' . $resource->get('id') . ' in context: ' . $contextKey);
$newResource = null;
}
return $newResource;
}
示例10: createPDF
/**
* Create a PDF with the options set in the class
*
* @param modResource $resource
* @param string|boolean $aliasPath
* @return string
*/
public function createPDF($resource, $aliasPath)
{
// Create folders
if (!@is_dir($this->getOption('pdfPath'))) {
if (!@mkdir($this->getOption('pdfPath'), $this->modx->getOption('new_folder_permissions', null, 0775))) {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not create the pdf output path: ' . $this->getOption('pdfPath'), '', 'PDFResource');
return '';
}
}
if ($aliasPath && !@is_dir($this->getOption('pdfPath') . $aliasPath)) {
if (!@mkdir($this->getOption('pdfPath') . $aliasPath, $this->modx->getOption('new_folder_permissions', null, 0775))) {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not create the pdf alias path: ' . $this->getOption('pdfPath') . $aliasPath, '', 'PDFResource');
return '';
}
}
// Get options
$id = $resource->get('id');
$pdfTpl = $this->getOption('pdfTpl', null, 'tplPDF');
$cssTpl = $this->getOption('cssTpl', null, 'tplCSS');
$optionsTV = $this->getOption('pdfTvOptions', null, 'pdf_options');
$processTVs = $this->getOption('processTVs', null, false);
$tvPrefix = $this->getOption('tvPrefix', null, 'tv.');
$placeholder = $resource->toArray();
// Prepare template variables and resource based options
$pdfOptions = null;
$tvs = $this->modx->getCollection('modTemplateVar');
foreach ($tvs as $tv) {
/** @var modTemplateVar $tv */
$placeholder[$tvPrefix . $tv->get('name')] = $processTVs ? $tv->renderOutput($id) : $tv->getValue($id);
if ($tv->get('name') == $optionsTV && $tv->getValue($id) != '') {
$pdfOptions = json_decode($tv->getValue($id), true);
if ($pdfOptions) {
$pdfTpl = $this->modx->getOption('pdfTpl', $pdfOptions, $pdfTpl);
$cssTpl = $this->modx->getOption('cssTpl', $pdfOptions, $cssTpl);
}
}
}
// Parse template chunks
$placeholder['tplPath'] = $this->modx->getOption('assets_path');
$html = $this->getChunk($pdfTpl, $placeholder);
$this->modx->getParser()->processElementTags('', $html, false, false, '[[', ']]', array(), $this->modx->getOption('max_iterations'));
$this->modx->getParser()->processElementTags('', $html, true, true, '[[', ']]', array(), $this->modx->getOption('max_iterations'));
$css = $this->getChunk($cssTpl, $placeholder);
unset($placeholder);
// Generate PDF file
$this->initPDF(array('mode' => $this->getOption('mode', $pdfOptions, 'utf-8'), 'format' => $this->getOption('format', $pdfOptions, 'A4'), 'defaultFontSize' => intval($this->getOption('defaultFontSize', $pdfOptions, 8)), 'defaultFont' => $this->getOption('defaultFont', $pdfOptions, ''), 'mgl' => intval($this->getOption('mgl', $pdfOptions, 10)), 'mgr' => intval($this->getOption('mgr', $pdfOptions, 10)), 'mgt' => intval($this->getOption('mgt', $pdfOptions, 7)), 'mgb' => intval($this->getOption('mgb', $pdfOptions, 7)), 'mgh' => intval($this->getOption('mgh', $pdfOptions, 10)), 'mgf' => intval($this->getOption('mgf', $pdfOptions, 10)), 'orientation' => $this->getOption('orientation', $pdfOptions, 'P'), 'customFonts' => $this->getOption('customFonts', $pdfOptions, '[]')));
$this->pdf->SetTitle($resource->get('pagetitle'));
$this->pdf->SetAuthor($this->getOption('author', $pdfOptions, $this->modx->getOption('site_name')));
$this->pdf->SetCreator($this->getOption('creator', $pdfOptions, $this->modx->getOption('site_url') . ' powered by PDFResource/mPDF'));
// Password protection
$userPassword = $this->getOption('userPassword', $pdfOptions, '');
$ownerPassword = $this->getOption('ownerPassword', $pdfOptions, '');
$permissions = json_decode($this->getOption('permissions', $pdfOptions, ''), true);
if ($userPassword || $ownerPassword) {
// Set default permissions if needed
$permissions = $permissions ? $permissions : array();
// Random owner password if needed
$ownerPassword = $ownerPassword ? $ownerPassword : null;
$this->pdf->SetProtection($permissions, $userPassword, $ownerPassword, 128);
}
// Call additional mPDF methods
$mpdfMethods = json_decode($this->getOption('mPDFMethods', $pdfOptions, ''), true);
$mpdfMethods = is_array($mpdfMethods) ? $mpdfMethods : array();
foreach ($mpdfMethods as $methodName) {
$value = $this->getOption($methodName, $pdfOptions, '');
$value = is_array($value) ? $value : json_decode($value, true);
if ($value && method_exists($this->pdf, $methodName)) {
call_user_func_array(array($this->pdf, $methodName), $value);
}
}
$this->pdf->WriteHTML($css, 1);
$this->pdf->WriteHTML($html, 2);
if ($aliasPath) {
return $this->pdf->Output($this->getOption('pdfPath') . $aliasPath . $resource->get('alias') . '.pdf', 'F');
} else {
return $this->pdf->Output('', 'S');
}
}
示例11: _prepareResourceRow
/**
* @param modResource $resource
*
* @return array
*/
protected function _prepareResourceRow(modResource $resource)
{
$row = $resource->toArray('', false, true);
$row['type'] = $row['children'] > 0 ? 'folder' : 'resource';
$row['classes'] = $this->mxManager->getSubClasses($resource->get('class_key'), $this->_permissions);
$row['pagetitle'] = html_entity_decode($row['pagetitle'], ENT_QUOTES, $this->modx->getOption('modx_charset', null, 'UTF-8'));
unset($row['children']);
return $row;
}