Exemplo n.º 1
0
 /**
  * Initialize the object
  * @param string
  */
 public function __construct($strTable)
 {
     $this->import('Session');
     $this->intGroupId = (int) \Session::getInstance()->get('iso_products_gid');
     // Check if the group exists
     if ($this->intGroupId > 0) {
         $objGroup = \Isotope\Model\Group::findByPk($this->intGroupId);
         if (null === $objGroup) {
             if (\BackendUser::getInstance()->isAdmin || !is_array(\BackendUser::getInstance()->iso_groups)) {
                 $this->intGroupId = 0;
             } elseif (!\BackendUser::getInstance()->isAdmin) {
                 $this->intGroupId = (int) \Database::getInstance()->prepare("SELECT id FROM " . \Isotope\Model\Group::getTable() . " WHERE id IN ('" . implode("','", \BackendUser::getInstance()->iso_groups) . "') ORDER BY " . \Database::getInstance()->findInSet('id', \BackendUser::getInstance()->iso_groups))->limit(1)->execute()->id;
             }
         }
     }
     // Redirect if the product was not found
     if (isset($_GET['id'])) {
         $objProduct = \Database::getInstance()->prepare("SELECT id FROM " . $strTable . " WHERE id=?")->limit(1)->execute(\Input::get('id', true));
         if (!$objProduct->numRows) {
             \Controller::redirect(preg_replace('/(&)?id=[^&]*/i', '', \Environment::get('request')));
         }
     }
     $arrClipboard = $this->Session->get('CLIPBOARD');
     // Cut all records
     if ($arrClipboard[$strTable]['mode'] == 'cutAll' && \Input::get('act') != 'cutAll') {
         \Controller::redirect(\Backend::addToUrl('&act=cutAll'));
     }
     parent::__construct($strTable);
 }
Exemplo n.º 2
0
 /**
  * Store initial values when creating a product
  *
  * @param   string $strTable
  * @param   int    $insertID
  * @param   array  $arrSet
  */
 public function updateNewRecord($strTable, $insertID, $arrSet)
 {
     if ($arrSet['pid'] > 0) {
         return;
     }
     $intType = 0;
     $intGroup = (int) \Session::getInstance()->get('iso_products_gid') ?: (\BackendUser::getInstance()->isAdmin ? 0 : intval(\BackendUser::getInstance()->iso_groups[0]));
     $objGroup = Group::findByPk($intGroup);
     if (null === $objGroup || null === $objGroup->getRelated('product_type')) {
         $objType = ProductType::findFallback();
     } else {
         $objType = $objGroup->getRelated('product_type');
     }
     if (null !== $objType) {
         $intType = $objType->id;
     }
     \Database::getInstance()->prepare("UPDATE {$strTable} SET gid=?, type=?, dateAdded=? WHERE id=?")->execute($intGroup, $intType, time(), $insertID);
 }
Exemplo n.º 3
0
 /**
  * Initialize the object
  * @param string
  */
 public function __construct($strTable)
 {
     $this->import('Session');
     $this->intGroupId = (int) \Session::getInstance()->get('iso_products_gid');
     // Check if the group exists
     if ($this->intGroupId > 0) {
         $objGroup = \Isotope\Model\Group::findByPk($this->intGroupId);
         if (null === $objGroup) {
             if (\BackendUser::getInstance()->isAdmin || !is_array(\BackendUser::getInstance()->iso_groups)) {
                 $this->intGroupId = 0;
             } elseif (!\BackendUser::getInstance()->isAdmin) {
                 $this->intGroupId = (int) \Database::getInstance()->prepare("SELECT id FROM tl_iso_group WHERE id IN ('" . implode("','", \BackendUser::getInstance()->iso_groups) . "') ORDER BY " . \Database::getInstance()->findInSet('id', \BackendUser::getInstance()->iso_groups))->limit(1)->execute()->id;
             }
         }
     }
     // Redirect if the product was not found
     if (isset($_GET['id'])) {
         $objProduct = \Database::getInstance()->prepare("SELECT id FROM {$strTable} WHERE id=?")->limit(1)->execute(\Input::get('id', true));
         if (!$objProduct->numRows) {
             \Controller::redirect(preg_replace('/(&)?id=[^&]*/i', '', \Environment::get('request')));
         }
     }
     $arrClipboard = $this->Session->get('CLIPBOARD');
     // Cut all records
     if ($arrClipboard[$strTable]['mode'] == 'cutAll' && \Input::get('act') != 'cutAll') {
         \Controller::redirect(\Backend::addToUrl('&act=cutAll'));
     }
     parent::__construct($strTable);
     // Allow to customize languages via the onload_callback
     if (isset($GLOBALS['TL_DCA'][$this->strTable]['config']['languages'])) {
         $arrPageLanguages = $GLOBALS['TL_DCA'][$this->strTable]['config']['languages'];
     } else {
         $arrPageLanguages = array_map(function ($strLang) {
             return str_replace('-', '_', $strLang);
         }, $this->Database->execute("SELECT DISTINCT language FROM tl_page WHERE type='root' AND language!=''")->fetchEach('language'));
     }
     if (count($arrPageLanguages) > 1) {
         $this->arrTranslationLabels = \System::getLanguages();
         $this->arrTranslations = array_intersect(array_keys($this->arrTranslationLabels), $arrPageLanguages);
     }
 }
Exemplo n.º 4
0
 /**
  * Add an image to each group in the tree
  * @param array
  * @param string
  * @param DataContainer
  * @param string
  * @param boolean
  * @return string
  */
 public function addIcon($row, $label, \DataContainer $dc = null, $imageAttribute = '', $blnReturnImage = false)
 {
     $image = \Image::getHtml('system/modules/isotope/assets/images/folder-network.png', '', $imageAttribute);
     if ($dc->table == 'tl_iso_product') {
         return $image . ' <span style="font-weight:bold">' . $label . '</span>';
     } else {
         $strProductType = '';
         if (($objProductType = Group::findByPk($row['id'])->getRelated('product_type')) !== null) {
             $strProductType = ' <span style="color:#b3b3b3; padding-left:3px;">[' . $objProductType->name . ']</span>';
         }
         return $image . ' ' . $label . $strProductType;
     }
 }
Exemplo n.º 5
0
    /**
     * Generate groups breadcrumb and return it as HTML string
     * @param integer
     * @param integer
     * @return string
     */
    public static function generate($intId, $intProductId = null)
    {
        $arrGroups = array();
        $objSession = \Session::getInstance();
        // Set a new gid
        if (isset($_GET['gid'])) {
            $objSession->set('iso_products_gid', \Input::get('gid'));
            \Controller::redirect(preg_replace('/&gid=[^&]*/', '', \Environment::get('request')));
        }
        // Return if there is no trail
        if (!$objSession->get('iso_products_gid') && !$intProductId) {
            return '';
        }
        $objUser = \BackendUser::getInstance();
        $objDatabase = \Database::getInstance();
        // Include the product in variants view
        if ($intProductId) {
            $objProduct = $objDatabase->prepare("SELECT gid, name FROM tl_iso_product WHERE id=?")->limit(1)->execute($intProductId);
            if ($objProduct->numRows) {
                $arrGroups[] = array('id' => $intProductId, 'name' => $objProduct->name);
                // Override the group ID
                $intId = $objProduct->gid;
            }
        }
        $intPid = $intId;
        // Generate groups
        do {
            $objGroup = Group::findByPk($intPid);
            if (null !== $objGroup) {
                $arrGroups[] = array('id' => $objGroup->id, 'name' => $objGroup->name);
                if ($objGroup->pid) {
                    // Do not show the mounted groups
                    if (!$objUser->isAdmin && $objUser->hasAccess($objGroup->id, 'iso_groups')) {
                        break;
                    }
                    $intPid = $objGroup->pid;
                }
            }
        } while ($objGroup->pid);
        $arrLinks = array();
        $strUrl = \Environment::get('request');
        // Remove the product ID from URL
        if ($intProductId) {
            $strUrl = preg_replace('/&id=[^&]*/', '', $strUrl);
        }
        // Generate breadcrumb trail
        foreach ($arrGroups as $arrGroup) {
            if (!$arrGroup['id']) {
                continue;
            }
            $buffer = '';
            // No link for the active group
            if (!$intProductId && $intId == $arrGroup['id'] || $intProductId && $intProductId == $arrGroup['id']) {
                $buffer .= '<img src="system/modules/isotope/assets/images/folder-network.png" width="16" height="16" alt="" style="margin-right:6px;">' . $arrGroup['name'];
            } else {
                $buffer .= '<img src="system/modules/isotope/assets/images/folder-network.png" width="16" height="16" alt="" style="margin-right:6px;"><a href="' . ampersand($strUrl) . '&amp;gid=' . $arrGroup['id'] . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectGroup']) . '">' . $arrGroup['name'] . '</a>';
            }
            $arrLinks[] = $buffer;
        }
        $arrLinks[] = sprintf('<a href="%s" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['allGroups']) . '"><img src="system/modules/isotope/assets/images/folders.png" width="16" height="16" alt="" style="margin-right:6px;"> %s</a>', ampersand($strUrl) . '&amp;gid=0', $GLOBALS['TL_LANG']['MSC']['filterAll']);
        return '
<ul id="tl_breadcrumb">
  <li>' . implode(' &gt; </li><li>', array_reverse($arrLinks)) . '</li>
</ul>';
    }