本文整理汇总了PHP中modResource类的典型用法代码示例。如果您正苦于以下问题:PHP modResource类的具体用法?PHP modResource怎么用?PHP modResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了modResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkRules
public function checkRules()
{
$DocID = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$rules = $this->getOptions("rules", array());
$flag = empty($rules);
if (!$flag && $DocID && $this->loadModClass("modResource")) {
$DOC = new modResource($this->_modx);
$data = $DOC->edit($DocID)->toArray();
$flag = true;
foreach ($rules as $item => $value) {
switch ($item) {
case 'id':
if ($DOC->getID() != $value) {
$flag = false;
}
break;
default:
if (!isset($data[$item]) || $data[$item] != $value) {
$flag = false;
}
break;
}
}
}
return $flag;
}
示例2: handleOriginalParent
/**
* @param \modResource $originalParent
*/
protected function handleOriginalParent($originalParent)
{
$originalGreatParent = $originalParent->Parent;
if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer' && $originalParent->hasChildren() == 0) {
$originalParent->set('show_in_tree', 0);
$originalParent->save();
}
}
示例3: beforeSave
public function beforeSave()
{
/** @var modResource $parent */
$parent = $this->modx->getObject('modResource', $this->object->parent);
if ($parent && $parent->class_key == 'CollectionContainer') {
$this->object->set('show_in_tree', 0);
} else {
$this->object->set('show_in_tree', 1);
}
return parent::beforeSave();
}
示例4: process
public function process()
{
/* @var modResourceGroupResource $resourceGroupResource */
$resourceGroupResource = $this->modx->getObject('modResourceGroupResource', array('document_group' => $this->resourceGroup->get('id'), 'document' => $this->resource->get('id')));
if (empty($resourceGroupResource)) {
return $this->failure($this->modx->lexicon('resource_group_resource_err_nf'));
}
if ($resourceGroupResource->remove() == false) {
return $this->failure($this->modx->lexicon('resource_group_resource_err_remove'));
} else {
$this->fireAfterRemove();
}
return $this->success('', $resourceGroupResource);
}
示例5: process
/**
* Process this page, load the resource, and present its values
* @return void
*/
public function process()
{
$data = $this->processInput($this->config['gpc']);
/* @var modProcessorResponse $response */
$response = $this->modx->runProcessor('resource/update', $data);
if (!$response->isError()) {
$tempRes = $response->getObject();
$this->resource = $this->modx->getObject('modResource', $tempRes['id']);
$this->setPlaceholders(array('message' => $this->modx->lexicon('updated'), 'resid' => $this->resource->get('id'), 'ctx' => $this->resource->get('context_key')));
} else {
$error = $response->getAllErrors();
$this->setPlaceholder('message', 'Something went wrong updating the Resource: ' . implode(', ', $error));
}
}
示例6: handleOriginalParent
/**
* @param \modResource $parent
* @param \modResource $resource
* @param \modResource $originalParent
*/
protected function handleOriginalParent($parent, $resource, $originalParent)
{
if ($originalParent->class_key == 'CollectionContainer') {
if ($parent->class_key != 'CollectionContainer') {
$resource->set('show_in_tree', 1);
}
} else {
/** @var \modResource $originalGreatParent */
$originalGreatParent = $originalParent->Parent;
if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer') {
$resource->set('show_in_tree', 1);
}
}
}
示例7: getResourceGroups
public function getResourceGroups()
{
$parentGroups = array();
if ($this->resource->get('id') == 0) {
$parent = $this->modx->getObject('modResource', $this->resource->get('parent'));
/** @var modResource $parent */
if ($parent) {
$parentResourceGroups = $parent->getMany('ResourceGroupResources');
/** @var modResourceGroupResource $parentResourceGroup */
foreach ($parentResourceGroups as $parentResourceGroup) {
$parentGroups[] = $parentResourceGroup->get('document_group');
}
$parentGroups = array_unique($parentGroups);
}
}
$this->resourceArray['resourceGroups'] = array();
$resourceGroups = $this->resource->getGroupsList(array('name' => 'ASC'), 0, 0);
/** @var modResourceGroup $resourceGroup */
foreach ($resourceGroups['collection'] as $resourceGroup) {
$access = (bool) $resourceGroup->get('access');
if (!empty($parent) && $this->resource->get('id') == 0) {
$access = in_array($resourceGroup->get('id'), $parentGroups) ? true : false;
}
$resourceGroupArray = array($resourceGroup->get('id'), $resourceGroup->get('name'), $access);
$this->resourceArray['resourceGroups'][] = $resourceGroupArray;
}
return $this->resourceArray['resourceGroups'];
}
示例8: modresource_populate_children
function modresource_populate_children(\Teleport\Action\Extract &$extract, modResource &$object, $criteria, $graph, $graphCriteria, $vehicle, &$vehicleCount)
{
unset($criteria['parent']);
$children = $object->getMany('Children', null, false);
if ($children) {
foreach ($children as &$child) {
/** @var modResource $child */
if ($graph !== null) {
$child->getGraph($graph, $graphCriteria);
}
if ($extract->package->put($child, $vehicle['attributes'])) {
$vehicleCount++;
}
modresource_populate_children($extract, $child, $criteria, $graph, $graphCriteria, $vehicle, $vehicleCount);
}
}
}
示例9: prepareResourceNode
/** {@inheritDoc} */
public function prepareResourceNode(modResource $resource)
{
$qtipField = $this->getProperty('qtipField');
$nodeField = $this->getProperty('nodeField');
$hasChildren = (int) $resource->get('childrenCount') > 0 && $resource->get('hide_children_in_tree') == 0 ? true : false;
// Assign an icon class based on the class_key
$class = $iconCls = array();
$classKey = strtolower($resource->get('class_key'));
if (substr($classKey, 0, 3) == 'mod') {
$classKey = substr($classKey, 3);
}
$classKeyIcon = $this->modx->getOption('mgr_tree_icon_' . $classKey, null, 'tree-resource');
$iconCls[] = $classKeyIcon;
$class[] = 'icon-' . strtolower(str_replace('mod', '', $resource->get('class_key')));
if (!$resource->isfolder) {
$class[] = 'x-tree-node-leaf icon-resource';
}
if (!$resource->get('published')) {
$class[] = 'unpublished';
}
if ($resource->get('deleted')) {
$class[] = 'deleted';
}
if ($resource->get('hidemenu')) {
$class[] = 'hidemenu';
}
if ($hasChildren) {
$class[] = 'haschildren';
$iconCls[] = $this->modx->getOption('mgr_tree_icon_folder', null, 'tree-folder');
$iconCls[] = 'parent-resource';
}
$qtip = '';
if (!empty($qtipField)) {
$qtip = '<b>' . strip_tags($resource->{$qtipField}) . '</b>';
} else {
if ($resource->longtitle != '') {
$qtip = '<b>' . strip_tags($resource->longtitle) . '</b><br />';
}
if ($resource->description != '') {
$qtip = '<i>' . strip_tags($resource->description) . '</i>';
}
}
$idNote = $this->modx->hasPermission('tree_show_resource_ids') ? ' <span dir="ltr">(' . $resource->id . ')</span>' : '';
$itemArray = array('text' => strip_tags($resource->{$nodeField}) . $idNote, 'id' => $resource->context_key . '_' . $resource->id, 'pk' => $resource->id, 'cls' => implode(' ', $class), 'iconCls' => implode(' ', $iconCls), 'type' => 'modResource', 'classKey' => $resource->class_key, 'ctx' => $resource->context_key, 'hide_children_in_tree' => $resource->hide_children_in_tree, 'qtip' => $qtip, 'checked' => !empty($resource->member) || $resource->id == $this->parent_id ? true : false, 'disabled' => $resource->id == $this->parent_id ? true : false);
if (!$hasChildren) {
$itemArray['hasChildren'] = false;
$itemArray['children'] = array();
$itemArray['expanded'] = true;
} else {
$itemArray['hasChildren'] = true;
}
if ($itemArray['classKey'] != 'msCategory') {
unset($itemArray['checked']);
}
return $itemArray;
}
示例10: getResource
/**
* Get the Resource associated
*
* @return modResource|string
*/
public function getResource()
{
$resourceId = $this->getProperty('resource', 0);
if (empty($resourceId)) {
$this->resource = $this->modx->newObject('modResource');
$this->resource->set('id', 0);
} else {
$this->resource = $this->modx->getObject('modResource', $resourceId);
if (empty($this->resource)) {
return $this->modx->lexicon('resource_err_nfs', array('id' => $resourceId));
}
/* check access */
if (!$this->resource->checkPolicy('view')) {
return $this->modx->lexicon('permission_denied');
}
}
return $this->resource;
}
示例11: process
public function process()
{
if (!$this->validate()) {
return $this->failure();
}
$this->resource->fromArray($this->getProperties());
if ($this->resource->save() === false) {
return $this->failure($this->modx->lexicon('resource_err_save'));
}
return $this->success();
}
示例12: process
/**
* @return array|string
*/
public function process()
{
if (!($data = $this->handleFile())) {
return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ns'));
}
$properties = $this->mediaSource->getProperties();
$tmp = explode('.', $data['name']);
$extension = strtolower(end($tmp));
$image_extensions = $allowed_extensions = array();
if (!empty($properties['imageExtensions']['value'])) {
$image_extensions = array_map('trim', explode(',', strtolower($properties['imageExtensions']['value'])));
}
if (!empty($properties['allowedFileTypes']['value'])) {
$allowed_extensions = array_map('trim', explode(',', strtolower($properties['allowedFileTypes']['value'])));
}
if (!empty($allowed_extensions) && !in_array($extension, $allowed_extensions)) {
return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ext'));
} else {
if (in_array($extension, $image_extensions)) {
$type = 'image';
} else {
$type = $extension;
}
}
$hash = sha1($data['stream']);
if ($this->modx->getCount('msResourceFile', array('resource_id' => $this->resource->id, 'hash' => $hash, 'parent' => 0))) {
return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_exists'));
}
$filename = !empty($properties['imageNameType']) && $properties['imageNameType']['value'] == 'friendly' ? $this->resource->cleanAlias($data['name']) : $hash . '.' . $extension;
$rank = isset($properties['imageUploadDir']) && empty($properties['imageUploadDir']['value']) ? 0 : $this->modx->getCount('msResourceFile', array('parent' => 0, 'resource_id' => $this->resource->id));
/* @var msResourceFile $product_file */
$product_file = $this->modx->newObject('msResourceFile', array('resource_id' => $this->resource->id, 'parent' => 0, 'name' => $data['name'], 'file' => $filename, 'path' => $this->resource->id . '/', 'source' => $this->mediaSource->get('id'), 'type' => $type, 'rank' => $rank, 'createdon' => date('Y-m-d H:i:s'), 'createdby' => $this->modx->user->id, 'active' => 1, 'hash' => $hash, 'properties' => $data['properties']));
$this->mediaSource->createContainer($product_file->path, '/');
$file = $this->mediaSource->createObject($product_file->get('path'), $product_file->get('file'), $data['stream']);
if ($file) {
$url = $this->mediaSource->getObjectUrl($product_file->get('path') . $product_file->get('file'));
$product_file->set('url', $url);
$product_file->save();
if (empty($rank)) {
$imagesTable = $this->modx->getTableName('msResourceFile');
$sql = "UPDATE {$imagesTable} SET rank = rank + 1 WHERE resource_id ='" . $this->resource->id . "' AND id !='" . $product_file->get('id') . "'";
$this->modx->exec($sql);
}
$generate = $product_file->generateThumbnails($this->mediaSource);
if ($generate !== true) {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnails for image with id = ' . $product_file->get('id') . '. ' . $generate);
return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_thumb'));
} else {
return $this->success();
}
} else {
return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_save') . ': ' . print_r($this->mediaSource->getErrors(), 1));
}
}
示例13: process
public function process()
{
$action = $this->resource->get('deleted') ? 'undelete' : 'delete';
$return = $this->hm->runProcessor(array('action' => 'resource/' . $action, 'id' => $this->resource->get('id')));
if ($return['success'] == 1) {
if ($action == 'undelete') {
$message = 'Successfully undeleted resource ' . $this->resource->get('pagetitle') . '.';
} else {
$message = 'Successfully deleted resource ' . $this->resource->get('pagetitle') . '.';
}
} else {
$message = 'Something went wrong. ' . $return['message'];
}
$this->setPlaceholder('message', $message);
}
示例14: clearCache
/**
* Empty site cache if specified to do so
* @return void
*/
public function clearCache()
{
$syncSite = $this->getProperty('syncsite', false);
$clearCache = $this->getProperty('clearCache', false);
if (!empty($syncSite) || !empty($clearCache)) {
$this->modx->cacheManager->refresh(array('db' => array(), 'auto_publish' => array('contexts' => array($this->object->get('context_key'))), 'context_settings' => array('contexts' => array($this->object->get('context_key'))), 'resource' => array('contexts' => array($this->object->get('context_key')))));
}
}
示例15: loadCollection
/**
* {@inheritDoc}
* @return array
*/
public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true)
{
if (!is_object($criteria)) {
$criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
$xpdo->addDerivativeCriteria($className, $criteria);
return parent::loadCollection($xpdo, $className, $criteria, $cacheFlag);
}