[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Form\Field; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('_JEXEC') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Workflow Stages field. 22 * 23 * @since 4.0.0 24 */ 25 class WorkflowstageField extends GroupedlistField 26 { 27 /** 28 * The form field type. 29 * 30 * @var string 31 * @since 4.0.0 32 */ 33 protected $type = 'Workflowstage'; 34 35 /** 36 * The component and section separated by ".". 37 * 38 * @var string 39 * @since 4.0.0 40 */ 41 protected $extension = ''; 42 43 /** 44 * Show only the stages which has an item attached 45 * 46 * @var boolean 47 * @since 4.0.0 48 */ 49 protected $activeonly = false; 50 51 /** 52 * Method to attach a Form object to the field. 53 * 54 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. 55 * @param mixed $value The form field value to validate. 56 * @param string $group The field name group control value. This acts as as an array container for the field. 57 * For example if the field has name="foo" and the group value is set to "bar" then the 58 * full field name would end up being "bar[foo]". 59 * 60 * @return boolean True on success. 61 * 62 * @since 4.0.0 63 */ 64 public function setup(\SimpleXMLElement $element, $value, $group = null) 65 { 66 $result = parent::setup($element, $value, $group); 67 68 if ($result) { 69 if (\strlen($element['extension'])) { 70 $this->extension = (string) $element['extension']; 71 } else { 72 $this->extension = Factory::getApplication()->input->getCmd('extension'); 73 } 74 75 if ((string) $element['activeonly'] === '1' || (string) $element['activeonly'] === 'true') { 76 $this->activeonly = true; 77 } 78 } 79 80 return $result; 81 } 82 83 /** 84 * Method to get the field option groups. 85 * 86 * @return array The field option objects as a nested array in groups. 87 * 88 * @since 4.0.0 89 * @throws \UnexpectedValueException 90 */ 91 protected function getGroups() 92 { 93 $db = $this->getDatabase(); 94 $query = $db->getQuery(true); 95 96 // Select distinct stages for existing articles 97 $query 98 ->select( 99 [ 100 'DISTINCT ' . $db->quoteName('ws.id', 'workflow_stage_id'), 101 $db->quoteName('ws.title', 'workflow_stage_title'), 102 $db->quoteName('w.title', 'workflow_title'), 103 $db->quoteName('w.id', 'workflow_id'), 104 $db->quoteName('w.ordering', 'ordering'), 105 $db->quoteName('ws.ordering', 'workflow_stage_ordering'), 106 ] 107 ) 108 ->from($db->quoteName('#__workflow_stages', 'ws')) 109 ->from($db->quoteName('#__workflows', 'w')) 110 ->where( 111 [ 112 $db->quoteName('ws.workflow_id') . ' = ' . $db->quoteName('w.id'), 113 $db->quoteName('w.extension') . ' = :extension', 114 ] 115 ) 116 ->bind(':extension', $this->extension) 117 ->order( 118 [ 119 $db->quoteName('w.ordering'), 120 $db->quoteName('ws.ordering'), 121 ] 122 ); 123 124 if ($this->activeonly) { 125 $query 126 ->from($db->quoteName('#__workflow_associations', 'wa')) 127 ->where( 128 [ 129 $db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws.id'), 130 $db->quoteName('wa.extension') . ' = :associationExtension', 131 ] 132 ) 133 ->bind(':associationExtension', $this->extension); 134 } 135 136 $stages = $db->setQuery($query)->loadObjectList(); 137 138 $workflowStages = array(); 139 140 // Grouping the stages by workflow 141 foreach ($stages as $stage) { 142 // Using workflow ID to differentiate workflows having same title 143 $workflowStageKey = Text::_($stage->workflow_title) . ' (' . $stage->workflow_id . ')'; 144 145 if (!\array_key_exists($workflowStageKey, $workflowStages)) { 146 $workflowStages[$workflowStageKey] = array(); 147 } 148 149 $workflowStages[$workflowStageKey][] = HTMLHelper::_('select.option', $stage->workflow_stage_id, Text::_($stage->workflow_stage_title)); 150 } 151 152 // Merge any additional options in the XML definition. 153 return array_merge(parent::getGroups(), $workflowStages); 154 } 155 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |