| Conditions | 107 |
| Paths | 3 |
| Total Lines | 959 |
| Code Lines | 533 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 1475 | public function set_extra_fields_in_form( |
||
| 1476 | $form, |
||
| 1477 | $extraData, |
||
| 1478 | $adminPermissions = false, |
||
| 1479 | $extra = [], |
||
| 1480 | $itemId = null, |
||
| 1481 | $exclude = [], |
||
| 1482 | $useTagAsSelect = false, |
||
| 1483 | $showOnlyTheseFields = [], |
||
| 1484 | $orderFields = [] |
||
| 1485 | ) { |
||
| 1486 | $jquery_ready_content = null; |
||
| 1487 | if (!empty($extra)) { |
||
| 1488 | $newOrder = []; |
||
| 1489 | if (!empty($orderFields)) { |
||
| 1490 | foreach ($orderFields as $order) { |
||
| 1491 | foreach ($extra as $field_details) { |
||
| 1492 | if ($order == $field_details['variable']) { |
||
| 1493 | $newOrder[] = $field_details; |
||
| 1494 | } |
||
| 1495 | } |
||
| 1496 | } |
||
| 1497 | $extra = $newOrder; |
||
| 1498 | } |
||
| 1499 | |||
| 1500 | foreach ($extra as $field_details) { |
||
| 1501 | if (!empty($showOnlyTheseFields)) { |
||
| 1502 | if (!in_array($field_details['variable'], $showOnlyTheseFields)) { |
||
| 1503 | continue; |
||
| 1504 | } |
||
| 1505 | } |
||
| 1506 | |||
| 1507 | // Getting default value id if is set |
||
| 1508 | $defaultValueId = null; |
||
| 1509 | if (isset($field_details['options']) && !empty($field_details['options'])) { |
||
| 1510 | $valueToFind = null; |
||
| 1511 | if (isset($field_details['field_default_value'])) { |
||
| 1512 | $valueToFind = $field_details['field_default_value']; |
||
| 1513 | } |
||
| 1514 | // If a value is found we override the default value |
||
| 1515 | if (isset($extraData['extra_'.$field_details['variable']])) { |
||
| 1516 | $valueToFind = $extraData['extra_'.$field_details['variable']]; |
||
| 1517 | } |
||
| 1518 | |||
| 1519 | foreach ($field_details['options'] as $option) { |
||
| 1520 | if ($option['option_value'] == $valueToFind) { |
||
| 1521 | $defaultValueId = $option['id']; |
||
| 1522 | } |
||
| 1523 | } |
||
| 1524 | } |
||
| 1525 | |||
| 1526 | if (!$adminPermissions) { |
||
| 1527 | if ($field_details['visible_to_self'] == 0) { |
||
| 1528 | continue; |
||
| 1529 | } |
||
| 1530 | |||
| 1531 | if (in_array($field_details['variable'], $exclude)) { |
||
| 1532 | continue; |
||
| 1533 | } |
||
| 1534 | } |
||
| 1535 | |||
| 1536 | $freezeElement = false; |
||
| 1537 | if (!$adminPermissions) { |
||
| 1538 | $freezeElement = $field_details['visible_to_self'] == 0 || $field_details['changeable'] == 0; |
||
| 1539 | } |
||
| 1540 | |||
| 1541 | switch ($field_details['field_type']) { |
||
| 1542 | case self::FIELD_TYPE_TEXT: |
||
| 1543 | $form->addElement( |
||
| 1544 | 'text', |
||
| 1545 | 'extra_'.$field_details['variable'], |
||
| 1546 | $field_details['display_text'], |
||
| 1547 | [ |
||
| 1548 | 'id' => 'extra_'.$field_details['variable'] |
||
| 1549 | ] |
||
| 1550 | ); |
||
| 1551 | $form->applyFilter( |
||
| 1552 | 'extra_'.$field_details['variable'], |
||
| 1553 | 'stripslashes' |
||
| 1554 | ); |
||
| 1555 | $form->applyFilter( |
||
| 1556 | 'extra_'.$field_details['variable'], |
||
| 1557 | 'trim' |
||
| 1558 | ); |
||
| 1559 | if ($freezeElement) { |
||
| 1560 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1561 | } |
||
| 1562 | break; |
||
| 1563 | case self::FIELD_TYPE_TEXTAREA: |
||
| 1564 | $form->addHtmlEditor( |
||
| 1565 | 'extra_'.$field_details['variable'], |
||
| 1566 | $field_details['display_text'], |
||
| 1567 | false, |
||
| 1568 | false, |
||
| 1569 | [ |
||
| 1570 | 'ToolbarSet' => 'Profile', |
||
| 1571 | 'Width' => '100%', |
||
| 1572 | 'Height' => '130', |
||
| 1573 | 'id' => 'extra_'.$field_details['variable'] |
||
| 1574 | ] |
||
| 1575 | ); |
||
| 1576 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1577 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1578 | if ($freezeElement) { |
||
| 1579 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1580 | } |
||
| 1581 | break; |
||
| 1582 | case self::FIELD_TYPE_RADIO: |
||
| 1583 | $group = []; |
||
| 1584 | if (isset($field_details['options']) && |
||
| 1585 | !empty($field_details['options']) |
||
| 1586 | ) { |
||
| 1587 | foreach ($field_details['options'] as $option_details) { |
||
| 1588 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 1589 | $group[] = $form->createElement( |
||
| 1590 | 'radio', |
||
| 1591 | 'extra_'.$field_details['variable'], |
||
| 1592 | $option_details['option_value'], |
||
| 1593 | $option_details['display_text'].'<br />', |
||
| 1594 | $option_details['option_value'] |
||
| 1595 | ); |
||
| 1596 | } |
||
| 1597 | } |
||
| 1598 | $form->addGroup( |
||
| 1599 | $group, |
||
| 1600 | 'extra_'.$field_details['variable'], |
||
| 1601 | $field_details['display_text'] |
||
| 1602 | ); |
||
| 1603 | if ($freezeElement) { |
||
| 1604 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1605 | } |
||
| 1606 | break; |
||
| 1607 | case self::FIELD_TYPE_CHECKBOX: |
||
| 1608 | $group = []; |
||
| 1609 | if (isset($field_details['options']) && |
||
| 1610 | !empty($field_details['options']) |
||
| 1611 | ) { |
||
| 1612 | foreach ($field_details['options'] as $option_details) { |
||
| 1613 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 1614 | $group[] = $form->createElement( |
||
| 1615 | 'checkbox', |
||
| 1616 | 'extra_'.$field_details['variable'], |
||
| 1617 | $option_details['option_value'], |
||
| 1618 | $option_details['display_text'].'<br />', |
||
| 1619 | $option_details['option_value'] |
||
| 1620 | ); |
||
| 1621 | } |
||
| 1622 | } else { |
||
| 1623 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 1624 | $checkboxAttributes = []; |
||
| 1625 | if (is_array($extraData) && |
||
| 1626 | array_key_exists($fieldVariable, $extraData) |
||
| 1627 | ) { |
||
| 1628 | if (!empty($extraData[$fieldVariable])) { |
||
| 1629 | $checkboxAttributes['checked'] = 1; |
||
| 1630 | } |
||
| 1631 | } |
||
| 1632 | |||
| 1633 | // We assume that is a switch on/off with 1 and 0 as values |
||
| 1634 | $group[] = $form->createElement( |
||
| 1635 | 'checkbox', |
||
| 1636 | 'extra_'.$field_details['variable'], |
||
| 1637 | null, |
||
| 1638 | //$field_details['display_text'].'<br />', |
||
| 1639 | get_lang('Yes'), |
||
| 1640 | $checkboxAttributes |
||
| 1641 | ); |
||
| 1642 | } |
||
| 1643 | |||
| 1644 | $form->addGroup( |
||
| 1645 | $group, |
||
| 1646 | 'extra_'.$field_details['variable'], |
||
| 1647 | $field_details['display_text'] |
||
| 1648 | ); |
||
| 1649 | if ($freezeElement) { |
||
| 1650 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1651 | } |
||
| 1652 | break; |
||
| 1653 | case self::FIELD_TYPE_SELECT: |
||
| 1654 | self::addSelectElement($form, $field_details, $defaultValueId, $freezeElement); |
||
| 1655 | break; |
||
| 1656 | case self::FIELD_TYPE_SELECT_MULTIPLE: |
||
| 1657 | $options = []; |
||
| 1658 | foreach ($field_details['options'] as $option_id => $option_details) { |
||
| 1659 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 1660 | } |
||
| 1661 | $form->addElement( |
||
| 1662 | 'select', |
||
| 1663 | 'extra_'.$field_details['variable'], |
||
| 1664 | $field_details['display_text'], |
||
| 1665 | $options, |
||
| 1666 | [ |
||
| 1667 | 'multiple' => 'multiple', |
||
| 1668 | 'id' => 'extra_'.$field_details['variable'] |
||
| 1669 | ] |
||
| 1670 | ); |
||
| 1671 | if ($freezeElement) { |
||
| 1672 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1673 | } |
||
| 1674 | break; |
||
| 1675 | case self::FIELD_TYPE_DATE: |
||
| 1676 | $form->addDatePicker('extra_'.$field_details['variable'], $field_details['display_text']); |
||
| 1677 | if ($freezeElement) { |
||
| 1678 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1679 | } |
||
| 1680 | break; |
||
| 1681 | case self::FIELD_TYPE_DATETIME: |
||
| 1682 | $form->addDateTimePicker( |
||
| 1683 | 'extra_'.$field_details['variable'], |
||
| 1684 | $field_details['display_text'] |
||
| 1685 | ); |
||
| 1686 | |||
| 1687 | $defaults['extra_'.$field_details['variable']] = api_get_local_time(); |
||
| 1688 | if (!isset($form->_defaultValues['extra_'.$field_details['variable']])) { |
||
| 1689 | $form->setDefaults($defaults); |
||
| 1690 | } |
||
| 1691 | if ($freezeElement) { |
||
| 1692 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1693 | } |
||
| 1694 | break; |
||
| 1695 | case self::FIELD_TYPE_DOUBLE_SELECT: |
||
| 1696 | $jquery_ready_content .= self::addDoubleSelectElement( |
||
| 1697 | $form, |
||
| 1698 | $field_details, |
||
| 1699 | $extraData, |
||
| 1700 | $freezeElement |
||
| 1701 | ); |
||
| 1702 | break; |
||
| 1703 | case self::FIELD_TYPE_DIVIDER: |
||
| 1704 | $form->addHtml(' |
||
| 1705 | <div class="form-group "> |
||
| 1706 | <div class="col-sm-12"> |
||
| 1707 | <div class="panel-separator"> |
||
| 1708 | <h4 id="'.$field_details['variable'].'" class="form-separator">' |
||
| 1709 | .$field_details['display_text'].' |
||
| 1710 | </h4> |
||
| 1711 | </div> |
||
| 1712 | </div> |
||
| 1713 | </div> |
||
| 1714 | '); |
||
| 1715 | break; |
||
| 1716 | case self::FIELD_TYPE_TAG: |
||
| 1717 | $variable = $field_details['variable']; |
||
| 1718 | $field_id = $field_details['id']; |
||
| 1719 | |||
| 1720 | $tagsSelect = $form->addSelect( |
||
| 1721 | "extra_{$field_details['variable']}", |
||
| 1722 | $field_details['display_text'], |
||
| 1723 | [], |
||
| 1724 | ['style' => 'width: 100%;'] |
||
| 1725 | ); |
||
| 1726 | |||
| 1727 | if ($useTagAsSelect == false) { |
||
| 1728 | $tagsSelect->setAttribute('class', null); |
||
| 1729 | } |
||
| 1730 | |||
| 1731 | $tagsSelect->setAttribute('id', "extra_{$field_details['variable']}"); |
||
| 1732 | $tagsSelect->setMultiple(true); |
||
| 1733 | |||
| 1734 | $selectedOptions = []; |
||
| 1735 | if ($this->type === 'user') { |
||
| 1736 | // The magic should be here |
||
| 1737 | $user_tags = UserManager::get_user_tags($itemId, $field_details['id']); |
||
| 1738 | |||
| 1739 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
| 1740 | foreach ($user_tags as $tag) { |
||
| 1741 | if (empty($tag['tag'])) { |
||
| 1742 | continue; |
||
| 1743 | } |
||
| 1744 | $tagsSelect->addOption( |
||
| 1745 | $tag['tag'], |
||
| 1746 | $tag['tag'] |
||
| 1747 | ); |
||
| 1748 | $selectedOptions[] = $tag['tag']; |
||
| 1749 | } |
||
| 1750 | } |
||
| 1751 | $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php'; |
||
| 1752 | } else { |
||
| 1753 | $em = Database::getManager(); |
||
| 1754 | $fieldTags = $em |
||
| 1755 | ->getRepository('ChamiloCoreBundle:ExtraFieldRelTag') |
||
| 1756 | ->findBy( |
||
| 1757 | [ |
||
| 1758 | 'fieldId' => $field_id, |
||
| 1759 | 'itemId' => $itemId, |
||
| 1760 | ] |
||
| 1761 | ); |
||
| 1762 | /** @var ExtraFieldRelTag $fieldTag */ |
||
| 1763 | foreach ($fieldTags as $fieldTag) { |
||
| 1764 | /** @var Tag $tag */ |
||
| 1765 | $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId()); |
||
| 1766 | |||
| 1767 | if (empty($tag)) { |
||
| 1768 | continue; |
||
| 1769 | } |
||
| 1770 | $tagsSelect->addOption( |
||
| 1771 | $tag->getTag(), |
||
| 1772 | $tag->getTag() |
||
| 1773 | ); |
||
| 1774 | $selectedOptions[] = $tag->getTag(); |
||
| 1775 | } |
||
| 1776 | |||
| 1777 | if ($useTagAsSelect) { |
||
| 1778 | $fieldTags = $em |
||
| 1779 | ->getRepository('ChamiloCoreBundle:ExtraFieldRelTag') |
||
| 1780 | ->findBy([ |
||
| 1781 | 'fieldId' => $field_id |
||
| 1782 | ]); |
||
| 1783 | $tagsAdded = []; |
||
| 1784 | foreach ($fieldTags as $fieldTag) { |
||
| 1785 | $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId()); |
||
| 1786 | |||
| 1787 | if (empty($tag)) { |
||
| 1788 | continue; |
||
| 1789 | } |
||
| 1790 | |||
| 1791 | $tagText = $tag->getTag(); |
||
| 1792 | |||
| 1793 | if (in_array($tagText, $tagsAdded)) { |
||
| 1794 | continue; |
||
| 1795 | } |
||
| 1796 | |||
| 1797 | $tagsSelect->addOption( |
||
| 1798 | $tag->getTag(), |
||
| 1799 | $tag->getTag(), |
||
| 1800 | [] |
||
| 1801 | ); |
||
| 1802 | |||
| 1803 | $tagsAdded[] = $tagText; |
||
| 1804 | } |
||
| 1805 | } |
||
| 1806 | $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php'; |
||
| 1807 | } |
||
| 1808 | |||
| 1809 | $form->setDefaults( |
||
| 1810 | [ |
||
| 1811 | 'extra_'.$field_details['variable'] => $selectedOptions |
||
| 1812 | ] |
||
| 1813 | ); |
||
| 1814 | |||
| 1815 | if ($useTagAsSelect == false) { |
||
| 1816 | $jquery_ready_content .= " |
||
| 1817 | $('#extra_$variable').select2({ |
||
| 1818 | ajax: { |
||
| 1819 | url: '$url?a=search_tags&field_id=$field_id&type={$this->type}', |
||
| 1820 | processResults: function (data) { |
||
| 1821 | return { |
||
| 1822 | results: data.items |
||
| 1823 | } |
||
| 1824 | } |
||
| 1825 | }, |
||
| 1826 | cache: false, |
||
| 1827 | tags: true, |
||
| 1828 | tokenSeparators: [','], |
||
| 1829 | placeholder: '".get_lang('StartToType')."' |
||
| 1830 | }); |
||
| 1831 | "; |
||
| 1832 | } |
||
| 1833 | break; |
||
| 1834 | case self::FIELD_TYPE_TIMEZONE: |
||
| 1835 | $form->addElement( |
||
| 1836 | 'select', |
||
| 1837 | 'extra_'.$field_details['variable'], |
||
| 1838 | $field_details['display_text'], |
||
| 1839 | api_get_timezones(), |
||
| 1840 | '' |
||
| 1841 | ); |
||
| 1842 | if ($freezeElement) { |
||
| 1843 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1844 | } |
||
| 1845 | break; |
||
| 1846 | case self::FIELD_TYPE_SOCIAL_PROFILE: |
||
| 1847 | // get the social network's favicon |
||
| 1848 | $extra_data_variable = isset($extraData['extra_'.$field_details['variable']]) |
||
| 1849 | ? $extraData['extra_'.$field_details['variable']] |
||
| 1850 | : null; |
||
| 1851 | $field_default_value = isset($field_details['field_default_value']) |
||
| 1852 | ? $field_details['field_default_value'] |
||
| 1853 | : null; |
||
| 1854 | $icon_path = UserManager::get_favicon_from_url( |
||
| 1855 | $extra_data_variable, |
||
| 1856 | $field_default_value |
||
| 1857 | ); |
||
| 1858 | // special hack for hi5 |
||
| 1859 | $leftpad = '1.7'; |
||
| 1860 | $top = '0.4'; |
||
| 1861 | $domain = parse_url($icon_path, PHP_URL_HOST); |
||
| 1862 | if ($domain == 'www.hi5.com' or $domain == 'hi5.com') { |
||
| 1863 | $leftpad = '3'; |
||
| 1864 | $top = '0'; |
||
| 1865 | } |
||
| 1866 | // print the input field |
||
| 1867 | $form->addElement( |
||
| 1868 | 'text', |
||
| 1869 | 'extra_'.$field_details['variable'], |
||
| 1870 | $field_details['display_text'], |
||
| 1871 | [ |
||
| 1872 | 'size' => 60, |
||
| 1873 | 'size' => implode( |
||
| 1874 | '; ', |
||
| 1875 | [ |
||
| 1876 | "background-image: url('$icon_path')", |
||
| 1877 | 'background-repeat: no-repeat', |
||
| 1878 | "background-position: 0.4em {$top}em", |
||
| 1879 | "padding-left: {$leftpad}em" |
||
| 1880 | ] |
||
| 1881 | ) |
||
| 1882 | ] |
||
| 1883 | ); |
||
| 1884 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1885 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1886 | if ($freezeElement) { |
||
| 1887 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1888 | } |
||
| 1889 | break; |
||
| 1890 | case self::FIELD_TYPE_MOBILE_PHONE_NUMBER: |
||
| 1891 | $form->addElement( |
||
| 1892 | 'text', |
||
| 1893 | 'extra_'.$field_details['variable'], |
||
| 1894 | $field_details['display_text']." (".get_lang('CountryDialCode').")", |
||
| 1895 | ['size' => 40, 'placeholder' => '(xx)xxxxxxxxx'] |
||
| 1896 | ); |
||
| 1897 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1898 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1899 | $form->applyFilter('extra_'.$field_details['variable'], 'mobile_phone_number_filter'); |
||
| 1900 | $form->addRule( |
||
| 1901 | 'extra_'.$field_details['variable'], |
||
| 1902 | get_lang('MobilePhoneNumberWrong'), |
||
| 1903 | 'mobile_phone_number' |
||
| 1904 | ); |
||
| 1905 | if ($freezeElement) { |
||
| 1906 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1907 | } |
||
| 1908 | break; |
||
| 1909 | case self::FIELD_TYPE_INTEGER: |
||
| 1910 | $form->addElement( |
||
| 1911 | 'number', |
||
| 1912 | 'extra_'.$field_details['variable'], |
||
| 1913 | $field_details['display_text'], |
||
| 1914 | ['class' => 'span1', 'step' => 1] |
||
| 1915 | ); |
||
| 1916 | |||
| 1917 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1918 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1919 | $form->applyFilter('extra_'.$field_details['variable'], 'intval'); |
||
| 1920 | |||
| 1921 | if ($freezeElement) { |
||
| 1922 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1923 | } |
||
| 1924 | break; |
||
| 1925 | case self::FIELD_TYPE_FILE_IMAGE: |
||
| 1926 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 1927 | $fieldTexts = [ |
||
| 1928 | $field_details['display_text'] |
||
| 1929 | ]; |
||
| 1930 | |||
| 1931 | if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) { |
||
| 1932 | if (file_exists(api_get_path(SYS_UPLOAD_PATH).$extraData[$fieldVariable])) { |
||
| 1933 | $fieldTexts[] = Display::img( |
||
| 1934 | api_get_path(WEB_UPLOAD_PATH).$extraData[$fieldVariable], |
||
| 1935 | $field_details['display_text'], |
||
| 1936 | ['width' => '300'] |
||
| 1937 | ); |
||
| 1938 | } |
||
| 1939 | } |
||
| 1940 | |||
| 1941 | if ($fieldTexts[0] === 'Image') { |
||
| 1942 | $fieldTexts[0] = get_lang($fieldTexts[0]); |
||
| 1943 | } |
||
| 1944 | |||
| 1945 | $form->addFile( |
||
| 1946 | $fieldVariable, |
||
| 1947 | $fieldTexts, |
||
| 1948 | ['accept' => 'image/*', 'id' => 'extra_image', 'crop_image' => 'true'] |
||
| 1949 | ); |
||
| 1950 | |||
| 1951 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1952 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1953 | |||
| 1954 | $allowed_picture_types = ['jpg', 'jpeg', 'png', 'gif']; |
||
| 1955 | $form->addRule( |
||
| 1956 | 'extra_'.$field_details['variable'], |
||
| 1957 | get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', |
||
| 1958 | 'filetype', |
||
| 1959 | $allowed_picture_types |
||
| 1960 | ); |
||
| 1961 | |||
| 1962 | if ($freezeElement) { |
||
| 1963 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1964 | } |
||
| 1965 | break; |
||
| 1966 | case self::FIELD_TYPE_FLOAT: |
||
| 1967 | $form->addElement( |
||
| 1968 | 'number', |
||
| 1969 | 'extra_'.$field_details['variable'], |
||
| 1970 | $field_details['display_text'], |
||
| 1971 | ['class' => 'span1', 'step' => '0.01'] |
||
| 1972 | ); |
||
| 1973 | |||
| 1974 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1975 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1976 | $form->applyFilter('extra_'.$field_details['variable'], 'floatval'); |
||
| 1977 | |||
| 1978 | if ($freezeElement) { |
||
| 1979 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1980 | } |
||
| 1981 | break; |
||
| 1982 | case self::FIELD_TYPE_FILE: |
||
| 1983 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 1984 | $fieldTexts = [ |
||
| 1985 | $field_details['display_text'] |
||
| 1986 | ]; |
||
| 1987 | |||
| 1988 | if (is_array($extraData) && |
||
| 1989 | array_key_exists($fieldVariable, $extraData) |
||
| 1990 | ) { |
||
| 1991 | if (file_exists(api_get_path(SYS_UPLOAD_PATH).$extraData[$fieldVariable])) { |
||
| 1992 | $fieldTexts[] = Display::url( |
||
| 1993 | api_get_path(WEB_UPLOAD_PATH).$extraData[$fieldVariable], |
||
| 1994 | api_get_path(WEB_UPLOAD_PATH).$extraData[$fieldVariable], |
||
| 1995 | [ |
||
| 1996 | 'title' => $field_details['display_text'], |
||
| 1997 | 'target' => '_blank' |
||
| 1998 | ] |
||
| 1999 | ); |
||
| 2000 | } |
||
| 2001 | } |
||
| 2002 | |||
| 2003 | $form->addElement( |
||
| 2004 | 'file', |
||
| 2005 | $fieldVariable, |
||
| 2006 | $fieldTexts, |
||
| 2007 | [] |
||
| 2008 | ); |
||
| 2009 | |||
| 2010 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 2011 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 2012 | |||
| 2013 | if ($freezeElement) { |
||
| 2014 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2015 | } |
||
| 2016 | break; |
||
| 2017 | case self::FIELD_TYPE_VIDEO_URL: |
||
| 2018 | $form->addUrl( |
||
| 2019 | "extra_{$field_details['variable']}", |
||
| 2020 | $field_details['display_text'], |
||
| 2021 | false, |
||
| 2022 | ['placeholder' => 'https://'] |
||
| 2023 | ); |
||
| 2024 | if ($freezeElement) { |
||
| 2025 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2026 | } |
||
| 2027 | break; |
||
| 2028 | case self::FIELD_TYPE_LETTERS_ONLY: |
||
| 2029 | $form->addTextLettersOnly( |
||
| 2030 | "extra_{$field_details['variable']}", |
||
| 2031 | $field_details['display_text'] |
||
| 2032 | ); |
||
| 2033 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 2034 | |||
| 2035 | if ($freezeElement) { |
||
| 2036 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2037 | } |
||
| 2038 | break; |
||
| 2039 | case self::FIELD_TYPE_ALPHANUMERIC: |
||
| 2040 | $form->addTextAlphanumeric( |
||
| 2041 | "extra_{$field_details['variable']}", |
||
| 2042 | $field_details['display_text'] |
||
| 2043 | ); |
||
| 2044 | $form->applyFilter( |
||
| 2045 | 'extra_'.$field_details['variable'], |
||
| 2046 | 'stripslashes' |
||
| 2047 | ); |
||
| 2048 | if ($freezeElement) { |
||
| 2049 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2050 | } |
||
| 2051 | break; |
||
| 2052 | case self::FIELD_TYPE_LETTERS_SPACE: |
||
| 2053 | $form->addTextLettersAndSpaces( |
||
| 2054 | "extra_{$field_details['variable']}", |
||
| 2055 | $field_details['display_text'] |
||
| 2056 | ); |
||
| 2057 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 2058 | |||
| 2059 | if ($freezeElement) { |
||
| 2060 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2061 | } |
||
| 2062 | break; |
||
| 2063 | case self::FIELD_TYPE_ALPHANUMERIC_SPACE: |
||
| 2064 | $form->addTextAlphanumericAndSpaces( |
||
| 2065 | "extra_{$field_details['variable']}", |
||
| 2066 | $field_details['display_text'] |
||
| 2067 | ); |
||
| 2068 | $form->applyFilter( |
||
| 2069 | 'extra_'.$field_details['variable'], |
||
| 2070 | 'stripslashes' |
||
| 2071 | ); |
||
| 2072 | if ($freezeElement) { |
||
| 2073 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2074 | } |
||
| 2075 | break; |
||
| 2076 | case self::FIELD_TYPE_GEOLOCALIZATION: |
||
| 2077 | $dataValue = isset($extraData['extra_'.$field_details['variable']]) |
||
| 2078 | ? $extraData['extra_'.$field_details['variable']] |
||
| 2079 | : ''; |
||
| 2080 | $form->addElement( |
||
| 2081 | 'text', |
||
| 2082 | 'extra_'.$field_details['variable'], |
||
| 2083 | $field_details['display_text'], |
||
| 2084 | ['id' => 'extra_'.$field_details['variable']] |
||
| 2085 | ); |
||
| 2086 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 2087 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 2088 | if ($freezeElement) { |
||
| 2089 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2090 | } |
||
| 2091 | |||
| 2092 | $form->addHtml(" |
||
| 2093 | <script> |
||
| 2094 | $(document).ready(function() { |
||
| 2095 | if (typeof google === 'object') { |
||
| 2096 | var address = '$dataValue'; |
||
| 2097 | initializeGeo{$field_details['variable']}(address, false); |
||
| 2098 | |||
| 2099 | $('#geolocalization_extra_{$field_details['variable']}').on('click', function() { |
||
| 2100 | var address = $('#extra_{$field_details['variable']}').val(); |
||
| 2101 | initializeGeo{$field_details['variable']}(address, false); |
||
| 2102 | return false; |
||
| 2103 | }); |
||
| 2104 | |||
| 2105 | $('#myLocation_extra_{$field_details['variable']}').on('click', function() { |
||
| 2106 | myLocation{$field_details['variable']}(); |
||
| 2107 | return false; |
||
| 2108 | }); |
||
| 2109 | |||
| 2110 | $('#extra_{$field_details['variable']}').keypress(function(event) { |
||
| 2111 | if (event.which == 13) { |
||
| 2112 | $('#geolocalization_extra_{$field_details['variable']}').click(); |
||
| 2113 | return false; |
||
| 2114 | } |
||
| 2115 | }); |
||
| 2116 | |||
| 2117 | return; |
||
| 2118 | } |
||
| 2119 | |||
| 2120 | $('#map_extra_{$field_details['variable']}') |
||
| 2121 | .html('<div class=\"alert alert-info\">" |
||
| 2122 | .get_lang('YouNeedToActivateTheGoogleMapsPluginInAdminPlatformToSeeTheMap') |
||
| 2123 | ."</div>'); |
||
| 2124 | }); |
||
| 2125 | |||
| 2126 | function myLocation{$field_details['variable']}() { |
||
| 2127 | if (navigator.geolocation) { |
||
| 2128 | var geoPosition = function(position) { |
||
| 2129 | var lat = position.coords.latitude; |
||
| 2130 | var lng = position.coords.longitude; |
||
| 2131 | var latLng = new google.maps.LatLng(lat, lng); |
||
| 2132 | initializeGeo{$field_details['variable']}(false, latLng) |
||
| 2133 | }; |
||
| 2134 | |||
| 2135 | var geoError = function(error) { |
||
| 2136 | console.log(error); |
||
| 2137 | alert('Geocode ".get_lang('Error').": ' + error); |
||
| 2138 | }; |
||
| 2139 | |||
| 2140 | var geoOptions = { |
||
| 2141 | enableHighAccuracy: true |
||
| 2142 | }; |
||
| 2143 | |||
| 2144 | navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions); |
||
| 2145 | } |
||
| 2146 | } |
||
| 2147 | |||
| 2148 | function initializeGeo{$field_details['variable']}(address, latLng) { |
||
| 2149 | var geocoder = new google.maps.Geocoder(); |
||
| 2150 | var latlng = new google.maps.LatLng(-34.397, 150.644); |
||
| 2151 | var myOptions = { |
||
| 2152 | zoom: 15, |
||
| 2153 | center: latlng, |
||
| 2154 | mapTypeControl: true, |
||
| 2155 | mapTypeControlOptions: { |
||
| 2156 | style: google.maps.MapTypeControlStyle.DROPDOWN_MENU |
||
| 2157 | }, |
||
| 2158 | navigationControl: true, |
||
| 2159 | mapTypeId: google.maps.MapTypeId.ROADMAP |
||
| 2160 | }; |
||
| 2161 | |||
| 2162 | map_{$field_details['variable']} = new google.maps.Map( |
||
| 2163 | document.getElementById('map_extra_{$field_details['variable']}'), |
||
| 2164 | myOptions |
||
| 2165 | ); |
||
| 2166 | |||
| 2167 | var parameter = address ? {'address': address} : latLng ? {'latLng': latLng} : false; |
||
| 2168 | |||
| 2169 | if (geocoder && parameter) { |
||
| 2170 | geocoder.geocode(parameter, function(results, status) { |
||
| 2171 | if (status == google.maps.GeocoderStatus.OK) { |
||
| 2172 | if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { |
||
| 2173 | map_{$field_details['variable']}.setCenter(results[0].geometry.location); |
||
| 2174 | if (!address) { |
||
| 2175 | $('#extra_{$field_details['variable']}').val(results[0].formatted_address); |
||
| 2176 | } |
||
| 2177 | var infowindow = new google.maps.InfoWindow({ |
||
| 2178 | content: '<b>' + $('#extra_{$field_details['variable']}').val() + '</b>', |
||
| 2179 | size: new google.maps.Size(150, 50) |
||
| 2180 | }); |
||
| 2181 | |||
| 2182 | var marker = new google.maps.Marker({ |
||
| 2183 | position: results[0].geometry.location, |
||
| 2184 | map: map_{$field_details['variable']}, |
||
| 2185 | title: $('#extra_{$field_details['variable']}').val() |
||
| 2186 | }); |
||
| 2187 | google.maps.event.addListener(marker, 'click', function() { |
||
| 2188 | infowindow.open(map_{$field_details['variable']}, marker); |
||
| 2189 | }); |
||
| 2190 | } else { |
||
| 2191 | alert('".get_lang('NotFound')."'); |
||
| 2192 | } |
||
| 2193 | } else { |
||
| 2194 | alert('Geocode ".get_lang('Error').": ".get_lang("AddressField") |
||
| 2195 | ." ".get_lang('NotFound')."'); |
||
| 2196 | } |
||
| 2197 | }); |
||
| 2198 | } |
||
| 2199 | } |
||
| 2200 | </script> |
||
| 2201 | "); |
||
| 2202 | $form->addHtml(' |
||
| 2203 | <div class="form-group"> |
||
| 2204 | <label for="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2205 | class="col-sm-2 control-label"></label> |
||
| 2206 | <div class="col-sm-8"> |
||
| 2207 | <button class="null btn btn-default" |
||
| 2208 | id="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2209 | name="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2210 | type="submit"> |
||
| 2211 | <em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').' |
||
| 2212 | </button> |
||
| 2213 | <button class="null btn btn-default" id="myLocation_extra_'.$field_details['variable'].'" |
||
| 2214 | name="myLocation_extra_'.$field_details['variable'].'" |
||
| 2215 | type="submit"> |
||
| 2216 | <em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').' |
||
| 2217 | </button> |
||
| 2218 | </div> |
||
| 2219 | </div> |
||
| 2220 | '); |
||
| 2221 | |||
| 2222 | $form->addHtml(' |
||
| 2223 | <div class="form-group"> |
||
| 2224 | <label for="map_extra_'.$field_details['variable'].'" class="col-sm-2 control-label"> |
||
| 2225 | '.$field_details['display_text'].' - '.get_lang('Map').' |
||
| 2226 | </label> |
||
| 2227 | <div class="col-sm-8"> |
||
| 2228 | <div name="map_extra_'.$field_details['variable'].'" |
||
| 2229 | id="map_extra_'.$field_details['variable'].'" style="width:100%; height:300px;"> |
||
| 2230 | </div> |
||
| 2231 | </div> |
||
| 2232 | </div> |
||
| 2233 | '); |
||
| 2234 | break; |
||
| 2235 | case self::FIELD_TYPE_GEOLOCALIZATION_COORDINATES: |
||
| 2236 | $dataValue = isset($extraData['extra_'.$field_details['variable']]) |
||
| 2237 | ? $extraData['extra_'.$field_details['variable']] |
||
| 2238 | : ''; |
||
| 2239 | $form->addElement( |
||
| 2240 | 'text', |
||
| 2241 | 'extra_'.$field_details['variable'], |
||
| 2242 | $field_details['display_text'], |
||
| 2243 | ['id' => 'extra_'.$field_details['variable']] |
||
| 2244 | ); |
||
| 2245 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 2246 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 2247 | if ($freezeElement) { |
||
| 2248 | $form->freeze('extra_'.$field_details['variable']); |
||
| 2249 | } |
||
| 2250 | $latLag = explode(",", $dataValue); |
||
| 2251 | |||
| 2252 | // if no value, set default coordinates value |
||
| 2253 | if (empty($dataValue)) { |
||
| 2254 | $lat = '-34.397'; |
||
| 2255 | $lng = '150.644'; |
||
| 2256 | } else { |
||
| 2257 | $lat = $latLag[0]; |
||
| 2258 | $lng = $latLag[1]; |
||
| 2259 | } |
||
| 2260 | |||
| 2261 | $form->addHtml(" |
||
| 2262 | <script> |
||
| 2263 | $(document).ready(function() { |
||
| 2264 | if (typeof google === 'object') { |
||
| 2265 | var lat = '$lat'; |
||
| 2266 | var lng = '$lng'; |
||
| 2267 | var latLng = new google.maps.LatLng(lat, lng); |
||
| 2268 | initializeGeo{$field_details['variable']}(false, latLng); |
||
| 2269 | |||
| 2270 | $('#geolocalization_extra_{$field_details['variable']}').on('click', function() { |
||
| 2271 | var latLng = $('#extra_{$field_details['variable']}').val().split(','); |
||
| 2272 | var lat = latLng[0]; |
||
| 2273 | var lng = latLng[1]; |
||
| 2274 | var latLng = new google.maps.LatLng(lat, lng); |
||
| 2275 | initializeGeo{$field_details['variable']}(false, latLng); |
||
| 2276 | return false; |
||
| 2277 | }); |
||
| 2278 | |||
| 2279 | $('#myLocation_extra_{$field_details['variable']}').on('click', function() { |
||
| 2280 | myLocation{$field_details['variable']}(); |
||
| 2281 | return false; |
||
| 2282 | }); |
||
| 2283 | |||
| 2284 | $('#extra_{$field_details['variable']}').keypress(function (event) { |
||
| 2285 | if (event.which == 13) { |
||
| 2286 | $('#geolocalization_extra_{$field_details['variable']}').click(); |
||
| 2287 | return false; |
||
| 2288 | } |
||
| 2289 | }); |
||
| 2290 | |||
| 2291 | return; |
||
| 2292 | } |
||
| 2293 | |||
| 2294 | |||
| 2295 | $('#map_extra_{$field_details['variable']}') |
||
| 2296 | .html('<div class=\"alert alert-info\">" |
||
| 2297 | .get_lang('YouNeedToActivateTheGoogleMapsPluginInAdminPlatformToSeeTheMap') |
||
| 2298 | ."</div>'); |
||
| 2299 | }); |
||
| 2300 | |||
| 2301 | function myLocation{$field_details['variable']}() { |
||
| 2302 | if (navigator.geolocation) { |
||
| 2303 | var geoPosition = function(position) { |
||
| 2304 | var lat = position.coords.latitude; |
||
| 2305 | var lng = position.coords.longitude; |
||
| 2306 | var latLng = new google.maps.LatLng(lat, lng); |
||
| 2307 | initializeGeo{$field_details['variable']}(false, latLng) |
||
| 2308 | }; |
||
| 2309 | |||
| 2310 | var geoError = function(error) { |
||
| 2311 | alert('Geocode ".get_lang('Error').": ' + error); |
||
| 2312 | }; |
||
| 2313 | |||
| 2314 | var geoOptions = { |
||
| 2315 | enableHighAccuracy: true |
||
| 2316 | }; |
||
| 2317 | |||
| 2318 | navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions); |
||
| 2319 | } |
||
| 2320 | } |
||
| 2321 | |||
| 2322 | function initializeGeo{$field_details['variable']}(address, latLng) { |
||
| 2323 | var geocoder = new google.maps.Geocoder(); |
||
| 2324 | var latlng = new google.maps.LatLng(-34.397, 150.644); |
||
| 2325 | var myOptions = { |
||
| 2326 | zoom: 15, |
||
| 2327 | center: latlng, |
||
| 2328 | mapTypeControl: true, |
||
| 2329 | mapTypeControlOptions: { |
||
| 2330 | style: google.maps.MapTypeControlStyle.DROPDOWN_MENU |
||
| 2331 | }, |
||
| 2332 | navigationControl: true, |
||
| 2333 | mapTypeId: google.maps.MapTypeId.ROADMAP |
||
| 2334 | }; |
||
| 2335 | |||
| 2336 | map_{$field_details['variable']} = new google.maps.Map( |
||
| 2337 | document.getElementById('map_extra_{$field_details['variable']}'), |
||
| 2338 | myOptions |
||
| 2339 | ); |
||
| 2340 | |||
| 2341 | var parameter = address ? {'address': address} : latLng ? {'latLng': latLng} : false; |
||
| 2342 | |||
| 2343 | if (geocoder && parameter) { |
||
| 2344 | geocoder.geocode(parameter, function(results, status) { |
||
| 2345 | if (status == google.maps.GeocoderStatus.OK) { |
||
| 2346 | if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { |
||
| 2347 | map_{$field_details['variable']}.setCenter(results[0].geometry.location); |
||
| 2348 | |||
| 2349 | $('#extra_{$field_details['variable']}') |
||
| 2350 | .val(results[0].geometry.location.lat() + ',' + results[0].geometry.location.lng()); |
||
| 2351 | |||
| 2352 | var infowindow = new google.maps.InfoWindow({ |
||
| 2353 | content: '<b>' + $('#extra_{$field_details['variable']}').val() + '</b>', |
||
| 2354 | size: new google.maps.Size(150, 50) |
||
| 2355 | }); |
||
| 2356 | |||
| 2357 | var marker = new google.maps.Marker({ |
||
| 2358 | position: results[0].geometry.location, |
||
| 2359 | map: map_{$field_details['variable']}, |
||
| 2360 | title: $('#extra_{$field_details['variable']}').val() |
||
| 2361 | }); |
||
| 2362 | google.maps.event.addListener(marker, 'click', function() { |
||
| 2363 | infowindow.open(map_{$field_details['variable']}, marker); |
||
| 2364 | }); |
||
| 2365 | } else { |
||
| 2366 | alert('".get_lang("NotFound")."'); |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | } else { |
||
| 2370 | alert('Geocode ".get_lang('Error').": ' + status); |
||
| 2371 | } |
||
| 2372 | }); |
||
| 2373 | } |
||
| 2374 | } |
||
| 2375 | </script> |
||
| 2376 | "); |
||
| 2377 | $form->addHtml(' |
||
| 2378 | <div class="form-group"> |
||
| 2379 | <label for="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2380 | class="col-sm-2 control-label"></label> |
||
| 2381 | <div class="col-sm-8"> |
||
| 2382 | <button class="null btn btn-default " |
||
| 2383 | id="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2384 | name="geolocalization_extra_'.$field_details['variable'].'" |
||
| 2385 | type="submit"> |
||
| 2386 | <em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').' |
||
| 2387 | </button> |
||
| 2388 | <button class="null btn btn-default" |
||
| 2389 | id="myLocation_extra_'.$field_details['variable'].'" |
||
| 2390 | name="myLocation_extra_'.$field_details['variable'].'" type="submit"> |
||
| 2391 | <em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').' |
||
| 2392 | </button> |
||
| 2393 | </div> |
||
| 2394 | </div> |
||
| 2395 | '); |
||
| 2396 | |||
| 2397 | $form->addHtml(' |
||
| 2398 | <div class="form-group"> |
||
| 2399 | <label for="map_extra_'.$field_details['variable'].'" class="col-sm-2 control-label"> |
||
| 2400 | '.$field_details['display_text'].' - '.get_lang('Map').' |
||
| 2401 | </label> |
||
| 2402 | <div class="col-sm-8"> |
||
| 2403 | <div name="map_extra_'.$field_details['variable'].'" |
||
| 2404 | id="map_extra_'.$field_details['variable'].'" |
||
| 2405 | style="width:100%; height:300px;"> |
||
| 2406 | </div> |
||
| 2407 | </div> |
||
| 2408 | </div> |
||
| 2409 | '); |
||
| 2410 | break; |
||
| 2411 | case self::FIELD_TYPE_SELECT_WITH_TEXT_FIELD: |
||
| 2412 | $jquery_ready_content .= self::addSelectWithTextFieldElement( |
||
| 2413 | $form, |
||
| 2414 | $field_details, |
||
| 2415 | $freezeElement |
||
| 2416 | ); |
||
| 2417 | break; |
||
| 2418 | case self::FIELD_TYPE_TRIPLE_SELECT: |
||
| 2419 | $jquery_ready_content .= self::addTripleSelectElement( |
||
| 2420 | $form, |
||
| 2421 | $field_details, |
||
| 2422 | is_array($extraData) ? $extraData : [], |
||
| 2423 | $freezeElement |
||
| 2424 | ); |
||
| 2425 | break; |
||
| 2426 | } |
||
| 2427 | } |
||
| 2428 | } |
||
| 2429 | |||
| 2430 | $return = []; |
||
| 2431 | $return['jquery_ready_content'] = $jquery_ready_content; |
||
| 2432 | |||
| 2433 | return $return; |
||
| 2434 | } |
||
| 3399 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: