private function autogenerateMenuItemFromPageId($itemId, $parentId, $recursive = false) { $pageObject = new Pages(); $select = $pageObject->select()->setIntegrityCheck(false)->from('Pages')->joinInner('PagesIndex', 'PI_PageID = P_ID')->where('PI_LanguageID = ?', Zend_Registry::get('languageID'))->where('P_ParentID = ?', $parentId)->order('P_Position'); $pages = $pageObject->fetchAll($select)->toArray(); foreach ($pages as $item) { $page_id = $item['P_ID']; $position = $this->_db->fetchCol("SELECT count(*) FROM MenuItemData WHERE MID_ParentID = '{$itemId}' AND MID_MenuID = '{$this->_id}'"); $position = $position[0]; $langs = Cible_FunctionsGeneral::getAllLanguage(); foreach ($langs as $lang) { $page_details = Cible_FunctionsPages::getPageDetails($page_id, $lang['L_ID']); $page_title = !empty($page_details['PI_PageTitle']) ? $page_details['PI_PageTitle'] : null; if ($page_title != null) { $found_status = $this->autogenerate_checkIfAlreadyExists($itemId, $page_id, $lang['L_ID']); if (!$found_status['data']) { $menuData = new MenuItem(); $_data = $menuData->createRow(); $_data->setFromArray(array('MID_MenuID' => $this->_id, 'MID_ParentID' => $itemId, 'MID_Position' => $position)); $_data->save(); $_dataId = $this->_db->lastInsertId(); $menuIndex = new MenuItemIndex(); $_index = $menuIndex->createRow(); $_index->setFromArray(array('MII_LanguageID' => $item['PI_LanguageID'], 'MII_MenuItemDataID' => $_dataId, 'MII_Title' => $page_title, 'MII_Link' => '', 'MII_PageID' => $page_id)); $_index->save(); } else { if ($found_status['data'] && !$found_status['lang']) { $_dataId = $found_status['dataID']; $menuIndex = new MenuItemIndex(); $_index = $menuIndex->createRow(); $_index->setFromArray(array('MII_LanguageID' => $lang['L_ID'], 'MII_MenuItemDataID' => $_dataId, 'MII_Title' => $page_title, 'MII_Link' => '', 'MII_PageID' => $page_id)); $_index->save(); } } } } if ($_dataId != -1 && $recursive) { $this->autogenerateMenuItemFromPageId($_dataId, $page_id, $recursive); } } }
function editAction() { $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest); $this->view->assign('success', false); $this->view->title = "Modification de la page"; // retrieve the ID of the requested page $PageID = (int) $this->_getParam('ID'); if (Cible_ACL::hasAccess($PageID)) { // get page informations $Page = Cible_FunctionsPages::getPageDetails($PageID, $this->_currentEditLanguage); $page_info = $Page->toArray(); $this->view->home = $page_info['P_Home']; $this->view->pageTitle = isset($page_info['PI_PageTitle']) ? $page_info['PI_PageTitle'] : ''; $imageHeaderArray = $this->_findImagesFiles(); $form = new FormPage(array('baseDir' => $this->view->baseUrl(), 'pageID' => $PageID, 'imageHeaderArray' => $imageHeaderArray)); $layouts = Cible_FunctionsPages::getAvailableLayouts(); $templates = Cible_FunctionsPages::getAvailableTemplates(); $form = Cible_FunctionsPages::fillSelectLayouts($form, $layouts); $form = Cible_FunctionsPages::fillSelectTemplates($form, $templates); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); $PageIndex = $formData['PI_PageIndex']; // replace all double underscore by simple underscore while (substr_count($PageIndex, "__") > 0) { $PageIndex = str_replace("__", "_", $PageIndex); } if (isset($page_info['PI_PageIndex']) && $page_info['PI_PageIndex'] == $formData['PI_PageIndex']) { $form->getElement('PI_PageIndex')->clearValidators(); } if ($form->isValid($formData)) { $db = $this->_db; // update the P_LayoutID for the current Page $db->update('Pages', array('P_LayoutID' => $formData['P_LayoutID'], 'P_ShowTitle' => $formData['P_ShowTitle']), 'P_ID = ' . $PageID); // check to update P_ViewID if ($formData['P_ViewID'] != $page_info['P_ViewID']) { //get current number of zones $previous_zone_count = $page_info['V_ZoneCount']; // update the P_ViewID for the current Page $db->update('Pages', array('P_ViewID' => $formData['P_ViewID']), 'P_ID = ' . $PageID); // Fetch the new selected view details $new_view_details = Cible_FunctionsPages::getPageViewDetails($PageID); $new_zone_count = $new_view_details['V_ZoneCount']; // if our new zone count is smaller then our previous zone count, we need to move our deleted zone blocks to zone 1 if ($new_zone_count < $previous_zone_count) { //reset where just in case $where = array(); $where[] = $db->quoteInto('B_PageID = ?', $PageID); $where[] = $db->quoteInto('B_ZoneID > ?', $new_zone_count); $db->update('Blocks', array('B_ZoneID' => '-1'), $where); } } //$Page['PI_LanguageID'] = $this->_currentEditLanguage; if (isset($Page['PI_PageTitle'])) { $Page['PI_PageTitle'] = $formData['PI_PageTitle']; $Page['PI_PageIndex'] = $PageIndex; $Page['PI_Status'] = $formData['PI_Status']; $Page['PI_MetaTitle'] = $formData['PI_MetaTitle']; $Page['PI_MetaDescription'] = $formData['PI_MetaDescription']; $Page['PI_MetaKeywords'] = $formData['PI_MetaKeywords']; $Page['PI_MetaOther'] = $formData['PI_MetaOther']; if (!empty($formData['PI_TitleImageSrc'])) { $Page['PI_TitleImageSrc'] = $formData['PI_TitleImageSrc']; } if (!empty($formData['PI_AltPremiereImage'])) { $Page['PI_AltPremiereImage'] = $formData['PI_AltPremiereImage']; } $Page->save(); } else { $data = array('PI_PageID' => $PageID, 'PI_LanguageID' => $this->_currentEditLanguage, 'PI_PageTitle' => $formData['PI_PageTitle'], 'PI_PageIndex' => $PageIndex, 'PI_Status' => $formData['PI_Status'], 'PI_MetaTitle' => $formData['PI_MetaTitle'], 'PI_MetaDescription' => $formData['PI_MetaDescription'], 'PI_MetaKeywords' => $formData['PI_MetaKeywords'], 'PI_MetaOther' => $formData['PI_MetaOther'], 'PI_TitleImageSrc' => $formData['PI_TitleImageSrc'], 'PI_AltPremiereImage' => $formData['PI_AltPremiereImage']); $this->_db->insert('PagesIndex', $data); } $indexData['pageID'] = $PageID; $indexData['moduleID'] = 0; $indexData['contentID'] = $PageID; $indexData['languageID'] = Zend_Registry::get("currentEditLanguage"); $indexData['title'] = $formData['PI_PageTitle']; $indexData['text'] = ''; $indexData['link'] = ''; $indexData['contents'] = $formData['PI_PageTitle']; if ($formData['PI_Status'] == 1) { $indexData['action'] = 'update'; } else { $indexData['action'] = 'delete'; } Cible_FunctionsIndexation::indexation($indexData); // if not and ajax request, redirect else simply return as json success code and page details if (!$this->_isXmlHttpRequest) { $this->_redirect('/'); } else { $buttonAction = $formData['buttonAction']; $this->view->assign('buttonAction', $buttonAction); $this->view->assign('success', true); $this->view->assign('pageID', $PageID); $this->view->assign('pageTitle', $formData['PI_PageTitle']); $this->view->assign('currentEditLanguage', $this->_currentEditLanguage); } } else { $form->getElement('PI_MetaOther')->clearFilters(); $form->populate($formData); } } else { if ($PageID > 0) { $form->getElement('PI_MetaOther')->clearFilters(); $form->populate($Page->toArray()); } } } }
public function editBlockAction() { // variables $_pageID = $this->_getParam('ID'); $_blockID = $this->_getParam('blockID'); $_baseDir = $this->getFrontController()->getBaseUrl(); $this->view->assign('success', false); if (Cible_ACL::hasAccess($_pageID)) { // generate the form $_options = array('baseDir' => $_baseDir, 'pageID' => $_pageID, 'blockID' => $_blockID); $form = $this->getForm($_options); // get page informations $page = $this->view->page = Cible_FunctionsPages::getPageDetails($_pageID); $page_info = $page->toArray(); // get block informations $block = Cible_FunctionsBlocks::getBlockDetailsByLangID($_blockID, $this->_currentEditLanguage); $this->view->assign('block_zone', $block['B_ZoneID']); $this->view->assign('blockID', $block['B_ID']); // send form the the viewer $form->submit->setLabel('Enregistrer'); $this->view->form = $form; // action if user save if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $this->saveBlock($formData, $_pageID, $_blockID); if (!$this->_isXmlHttpRequest) { $this->_redirect('/page/manage/index/ID/' . $_pageID); } else { $this->view->assign('success', true); $this->view->assign('block_id', $block['B_ID']); $this->view->assign('blockTitle', $block['BI_BlockTitle']); $this->view->assign('blockLangID', $this->_currentEditLanguage); $this->view->assign('blockDescription', $this->getManageDescription($_blockID)); } } } else { if ($_blockID > 0) { $block = Cible_FunctionsBlocks::getBlockDetailsByLangID($_blockID, $this->_currentEditLanguage); $form->populate($block->toArray()); $blockParameters = Cible_FunctionsBlocks::getBlockParameters($_blockID); foreach ($blockParameters as $parameter) { $element = $form->getElement("Param{$parameter['P_Number']}"); if ($element) { $element->setValue($parameter['P_Value']); } else { echo "Param{$parameter['P_Number']} is not found"; } } } } } $this->view->jQuery()->enable(); }
private function _getParentsMenuId(array $itemMenu, MenuObject $oMenu = null) { if (is_null($oMenu)) { $page = Cible_FunctionsPages::getPageDetails($itemMenu['PageID'], Zend_Registry::get('languageID')); $page = $page->toArray(); $menu = Cible_FunctionsPages::getMenuByPageId($page['P_ParentID']); /*var_dump($menu);*/ $oMenu = new MenuObject($menu[0]['MID_MenuID']); $menuId = $menu[0]['MID_ID']; } else { $menuId = $itemMenu['MID_ParentID']; } $menuId = $itemMenu['MID_ParentID']; $tmpArray = array(); while ($menuId != 0) { $details = $oMenu->getMenuItemById($menuId); array_push($tmpArray, $details['MID_ID']); $menuId = $details['MID_ParentID']; } $this->_parentsMenuId = $tmpArray; }
/** * Build the breadcrumd for the catalog page. * * @param int $lang <Optional> Id of the current language * * @return string */ public function breadcrumbCatalog($level = 1, $showHome = true, $langId = null) { if ($langId == null) { $langId = Zend_Registry::get('languageID'); } $_baseUrl = Zend_Registry::get('baseUrl'); $_breadcrumb = array(); $_first = true; $pathInfo = $this->view->request->getPathInfo(); $oProducts = new ProductsCollection(); $oProducts->setActions($pathInfo); $oProducts->getDataByName(); $catId = $oProducts->getCatId(); $subCatId = $oProducts->getSubCatId(); $prodId = $oProducts->getProdId(); if ($catId == null && $subCatId == null && $prodId == null) { $_breadcrumb = $this->view->breadcrumb(true) . "<b>" . $this->view->selectedPage . "</b>"; return $_breadcrumb; } else { $pathElemts = $oProducts->getActions(); if ($prodId) { $_class = ''; $product = new ProductsObject(); $details = $product->populate($prodId, $langId); if ($_first) { $_class = 'current_page'; } $link = $_first ? "<b>" . $details['PI_Name'] . "</b>" : "<a href='{$_baseUrl}/{$this->view->selectedPage}/{$pathElemts[0]}/{$pathElemts[1]}/{$pathElemts[2]}' class='{$_class}'>{$details['PI_Name']}</a>"; array_push($_breadcrumb, $link); if ($_first) { $_first = false; } } if ($subCatId) { $_class = ''; $object = new SubCategoriesObject(); $details = $object->populate($subCatId, $langId); if ($_first) { $_class = 'current_page'; } $link = $_first ? "<b>" . $details['SCI_Name'] . "</b>" : "<a href='{$_baseUrl}/{$this->view->selectedPage}/{$pathElemts[0]}/{$pathElemts[1]}' class='{$_class}'>{$details['SCI_Name']}</a>"; array_push($_breadcrumb, $link); if ($_first) { $_first = false; } } if ($catId) { $_class = ''; $object = new CatalogCategoriesObject(); $details = $object->populate($catId, $langId); if ($_first) { $_class = 'current_page'; } $link = $_first ? "<b>" . $details['CCI_Name'] . "</b>" : "<a href='{$_baseUrl}/{$this->view->selectedPage}/{$pathElemts[0]}' class='{$_class}'>{$details['CCI_Name']}</a>"; array_push($_breadcrumb, $link); if ($_first) { $_first = false; } } $details = Cible_FunctionsPages::getPageDetails($this->view->currentPageID, $langId); $link = $_first ? '' : "<a href='{$_baseUrl}/{$details['PI_PageIndex']}' class='{$_class}'>{$details['PI_PageTitle']}</a>"; array_push($_breadcrumb, $link); if ($showHome) { $homeDetails = Cible_FunctionsPages::getHomePageDetails(); $link = "<a href='{$_baseUrl}/{$homeDetails['PI_PageIndex']}' class='{$_class}'>" . $homeDetails['PI_PageTitle'] . "</a>"; array_push($_breadcrumb, $link); } $_breadcrumb = array_reverse($_breadcrumb); //var_dump($_breadcrumb); // for($i=0;$i<$level;$i++){ // array_splice($_breadcrumb,$i+1,1); // } // add the > after the breadcrumb when only on item is found if (count($_breadcrumb) == 1) { return "{$_breadcrumb[0]} > "; } else { return implode(' > ', $_breadcrumb); } } }