public function __construct(&$item) { $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $user = JFactory::getUser(); $this->isFile = JoomDOCFileSystem::isFile($item); $this->isFolder = JoomDOCFileSystem::isFolder($item); $isFileSystemItem = $this->isFile || $this->isFolder; $this->docid = $isFileSystemItem ? JoomDOCHelper::getDocumentID($item) : $item->id; if (isset($item->document)) { $document = new JObject(); $document->setProperties($item->document); } elseif (!$isFileSystemItem) { if ($item instanceof JObject) { $document = $item; } else { $document = new JObject($item); $document->setProperties($item); } } else { $document = new JObject(); } $this->isTrashed = $isFileSystemItem ? @$item->file_state == JOOMDOC_STATE_TRASHED : $document->get('file_state') == JOOMDOC_STATE_TRASHED; if ($mainframe->isSite() && $document->get('state') == JOOMDOC_STATE_TRASHED) { $this->docid = null; } $this->relativePath = $isFileSystemItem ? $item->getRelativePath() : $item->path; $this->absolutePath = $isFileSystemItem ? $item->getAbsolutePath() : JoomDOCFileSystem::getFullPath($this->relativePath); $this->inRoot = $this->absolutePath == $config->path; $this->name = $isFileSystemItem ? $item->getFileName() : JFile::getName($this->relativePath); $this->alias = JoomDOCHelper::getDocumentAlias($item); $this->isChecked = JoomDOCHelper::isChecked($item); $this->isLocked = false; $this->fileType = JoomDOCHelper::getFileType($this->name); $this->canViewFileInfo = JoomDOCAccessFileSystem::viewFileInfo($this->docid, $this->relativePath); $this->fileVersion = JoomDOCHelper::getMaxVersion($this->relativePath); $this->canRename = JoomDOCAccessFileSystem::rename($this->docid, $this->relativePath); $this->canWebDav = JoomDOCAccessFileSystem::editWebDav($this->docid, $this->relativePath); $this->canEdit = $this->docid && JoomDOCAccessDocument::canEdit($document); $this->canCreate = !$this->docid && JoomDOCAccessDocument::create($this->relativePath); if ($config->documentAccess == 2 && $mainframe->isSite()) { $this->canDownload = $this->isFile && $document && $user->id == $document->get('access') && $document->get('download'); } else { $this->canDownload = $this->isFile && JoomDOCAccessFileSystem::download($this->docid, $this->relativePath); } $this->canEnterFolder = JoomDOCAccessFileSystem::enterFolder($this->docid, $this->relativePath); $this->canOpenFolder = $this->isFolder && $this->canEnterFolder; $this->canOpenFile = $this->isFile; $this->canEditStates = JoomDOCAccessDocument::editState($this->docid, $document->get('checked_out')); $this->canEditState = $this->docid && JoomDOCAccessDocument::editState($this->docid, $document->get('checked_out')); if ($mainframe->isAdmin()) { $this->canEditState = JoomDOCAccessDocument::editState(); } $this->canCopyMove = JoomDOCAccessFileSystem::copyMove($this->docid, $this->relativePath); $this->canDeleteDocs = JoomDOCAccessDocument::delete($this->docid); $this->canDeleteDoc = $this->docid && JoomDOCAccessDocument::delete($this->docid); $this->canDeleteFile = JoomDOCAccessFileSystem::deleteFile($this->docid, $this->relativePath); $this->canUpload = JoomDOCAccessFileSystem::uploadFile($this->docid, $this->relativePath); $this->canCreateFolder = JoomDOCAccessFileSystem::newFolder($this->docid, $this->relativePath); $this->canViewVersions = JoomDOCAccessDocument::viewVersions($this->docid); $this->canShowFileDates = $config->showCreated || $config->showModified; $this->canShowFileInfo = $config->showFilesize || $config->showHits; $this->canShowAllDesc = $config->showFolderDesc && $config->showFileDesc; $this->isFavorite = $document->get('favorite') == 1; $this->canDisplayFavorite = $this->isFavorite && $config->displayFavorite; $this->canAnyEditOp = $config->accessHandling && ($this->canEdit || $this->canWebDav || $this->canEditState || $this->canCreate || $this->canDeleteFile || $this->canDeleteDoc); if (!$this->docid || !$document->get('license_id')) { $license = JoomDOCHelper::license($this->relativePath); if ($license) { $this->licenseID = $license->id; $this->licenseAlias = $license->alias; $this->licenseTitle = $license->title; } } elseif ($document->get('license_state') == JOOMDOC_STATE_PUBLISHED) { $this->licenseID = $document->get('license_id'); $this->licenseAlias = $document->get('license_alias'); $this->licenseTitle = $document->get('license_title'); } $this->canManageVersions = false; $this->canUntrash = JoomDOCAccessFileSystem::untrash($this->docid, $this->relativePath); }
/** * Method to get the record form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return mixed A JForm object on success, false on failure */ public function getForm($data = array(), $loadData = true) { $form = $this->loadForm(sprintf('%s.%s', JOOMDOC_OPTION, JOOMDOC_DOCUMENT), JFile::read(JOOMDOC_MODELS . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR . JOOMDOC_DOCUMENT . '.xml'), array('control' => 'jform', 'load_data' => $loadData)); /* @var $form JForm */ $data = $this->loadFormData(); if (empty($form)) { return false; } $config = JoomDOCConfig::getInstance(); if ($config->documentAccess == 2) { // single user instead of access level $form->setFieldAttribute('access', 'type', 'user'); } else { $form->removeField('download'); } if (!$this->canEditState($form)) { $form->setFieldAttribute('publish_up', 'disabled', 'true'); $form->setFieldAttribute('publish_down', 'disabled', 'true'); $form->setFieldAttribute('state', 'disabled', 'true'); $form->setFieldAttribute('favorite', 'disabled', 'true'); $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'filter', 'unset'); $form->setFieldAttribute('publish_down', 'filter', 'unset'); $form->setFieldAttribute('state', 'filter', 'unset'); $form->setFieldAttribute('favorite', 'filter', 'unset'); $form->setFieldAttribute('ordering', 'filter', 'unset'); } if (!JoomDOCAccess::licenses()) { $form->setFieldAttribute('license', 'disabled', 'true'); $form->setFieldAttribute('license', 'filter', 'unset'); } $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ if ($config->versionDocument && JoomDOCAccessDocument::viewVersions($form->getValue('id'))) { $form->setValue('versionNote', ''); if ($config->versionRequired) { $form->setFieldAttribute('versionNote', 'required', 'true'); } } // load custom fields $query = $this->getDbo()->getQuery(true); $query->select('id, title, type, params')->from('#__joomdoc_field')->order('ordering')->where('published = 1'); $fields = $this->getDbo()->setQuery($query)->loadObjectList('id'); if ($fields) { // load custom fields options $query = $this->getDbo()->getQuery(true); $query->select('field, value, label')->from('#__joomdoc_option')->where('field IN (' . implode(', ', array_keys($fields)) . ')')->order('ordering'); $options = $this->getDbo()->setQuery($query)->loadObjectList(); $fieldmap[JOOMDOC_FIELD_TEXT] = 'text'; $fieldmap[JOOMDOC_FIELD_DATE] = 'calendar'; $fieldmap[JOOMDOC_FIELD_RADIO] = 'radio'; $fieldmap[JOOMDOC_FIELD_SELECT] = 'list'; $fieldmap[JOOMDOC_FIELD_CHECKBOX] = 'checkboxes'; $fieldmap[JOOMDOC_FIELD_TEXTAREA] = 'textarea'; $fieldmap[JOOMDOC_FIELD_EDITOR] = 'editor'; $fieldmap[JOOMDOC_FIELD_MULTI_SELECT] = 'list'; $fieldmap[JOOMDOC_FIELD_SUGGEST] = 'suggest'; foreach ($fields as $field) { // create basic form element $element = new SimpleXMLElement('<field/>'); // setup basic field params $element->addAttribute('field_id', $field->id); $element->addAttribute('name', 'field' . $field->id); $element->addAttribute('label', $field->title); if ($field->type == JOOMDOC_FIELD_EDITOR && !JFactory::getUser()->authorise('joomdoc.field.edit', 'com_joomdoc.field.' . $field->id)) { $element->addAttribute('type', 'div'); } else { $element->addAttribute('type', $fieldmap[$field->type]); } // setup other field params $params = new JRegistry($field->params); $params = $params->toArray(); // setup field options if ($field->type == JOOMDOC_FIELD_RADIO) { $element->addChild('option', JText::_('JNO'))->addAttribute('value', 0); $element->addChild('option', JText::_('JYES'))->addAttribute('value', 1); if (JFactory::getUser()->authorise('joomdoc.field.edit', 'com_joomdoc.field.' . $field->id)) { $params['class'] = JString::trim(JArrayHelper::getValue($params, 'class', '', 'string') . ' btn-group'); } } if ($field->type == JOOMDOC_FIELD_SELECT || $field->type == JOOMDOC_FIELD_CHECKBOX || $field->type == JOOMDOC_FIELD_MULTI_SELECT) { foreach ($options as $option) { if ($field->id == $option->field) { $child = $element->addChild('option', $option->label)->addAttribute('value', $option->value); } } } if ($field->type == JOOMDOC_FIELD_EDITOR) { $element->addAttribute('filter', 'JComponentHelper::filterText'); } if ($field->type == JOOMDOC_FIELD_MULTI_SELECT || $field->type == JOOMDOC_FIELD_SUGGEST) { $element->addAttribute('multiple', 'multiple'); } foreach ($params as $var => $val) { if ($var == 'required' && !JFactory::getUser()->authorise('joomdoc.field.edit', 'com_joomdoc.field.' . $field->id)) { continue; } if ($val) { $element->addAttribute($var, $val); } } if (!JFactory::getUser()->authorise('joomdoc.field.edit', 'com_joomdoc.field.' . $field->id)) { $element->addAttribute('disabled', 'true'); if ($field->type == JOOMDOC_FIELD_RADIO || $field->type == JOOMDOC_FIELD_CHECKBOX) { foreach ($element->children() as $option) { $option->addAttribute('disabled', 'true'); } } } $form->setField($element); if ($field->type == JOOMDOC_FIELD_CHECKBOX || $field->type == JOOMDOC_FIELD_MULTI_SELECT || $field->type == JOOMDOC_FIELD_SUGGEST) { $registry = new JRegistry(is_array($data) ? JArrayHelper::getValue($data, 'field' . $field->id) : $data->get('field' . $field->id)); is_array($data) ? $data['field' . $field->id] = (array) $registry->toArray() : $data->set('field' . $field->id, (array) $registry->toArray()); } } $form->bind($data); } return $form; }