public function executeGBlogs(sfWebRequest $request) { $this->setLayout('gestio'); $this->IDS = $this->getUser()->getSessionPar('idS'); //Add,Edit,Delete Multimedia //Add,Edit,Delete Page //Add,Edit,Delete Entry //Principal view -> Blogs //You Select a blog -> Choice Menus - Pages //Edit Page - Menu $this->APP_BLOG = $request->getParameter('APP_BLOG', -1); $this->APP_PAGE = $request->getParameter('APP_PAGE', -1); $this->APP_ENTRY = $request->getParameter('APP_ENTRY', -1); $this->APP_MENU = $request->getParameter('APP_MENU', -1); $this->APP_MULTIMEDIA = $request->getParameter('APP_MULTIMEDIA', -1); $this->APP_FORM = $request->getParameter('APP_FORM', 1); $this->APP_FORM_ENTRY = $request->getParameter('APP_FORM_ENTRY', 0); $this->accio = $request->getParameter('accio', 'VB'); // $this->APP_BLOG = $this->getUser()->ParReqSesForm($request,'APP_BLOG',-1); // $this->APP_PAGE = $this->getUser()->ParReqSesForm($request,'APP_PAGE',-1); // $this->APP_ENTRY = $this->getUser()->ParReqSesForm($request,'APP_ENTRY',-1); // $this->APP_MENU = $this->getUser()->ParReqSesForm($request,'APP_MENU',-1); // $this->APP_MULTIMEDIA = $this->getUser()->ParReqSesForm($request,'APP_MULTIMEDIA',-1); // $this->APP_FORM = $this->getUser()->ParReqSesForm($request,'APP_FORM',1); // $this->APP_FORM_ENTRY = $this->getUser()->ParReqSesForm($request,'APP_FORM_ENTRY',0); $accio = $request->getParameter('accio', 'GP'); $this->MODE = 'CERCA'; if ($request->isMethod('POST')) { if ($request->hasParameter('B_NEW_MENU')) { $accio = 'NEW_MENU'; } elseif ($request->hasParameter('B_EDIT_MENU')) { $accio = 'EDIT_MENU'; } elseif ($request->hasParameter('B_DELETE_MENU')) { $accio = 'DELETE_MENU'; } elseif ($request->hasParameter('B_SAVE_MENU')) { $accio = 'SAVE_MENU'; } elseif ($request->hasParameter('B_NEW_PAGE')) { $accio = 'NEW_PAGE'; } elseif ($request->hasParameter('B_EDIT_PAGE')) { $accio = 'EDIT_PAGE'; } elseif ($request->hasParameter('B_DELETE_PAGE')) { $accio = 'DELETE_PAGE'; } elseif ($request->hasParameter('B_SAVE_PAGE')) { $accio = 'SAVE_PAGE'; } elseif ($request->hasParameter('B_NEW_ENTRY')) { $accio = 'NEW_ENTRY'; } elseif ($request->hasParameter('B_EDIT_ENTRY')) { $accio = 'EDIT_ENTRY'; } elseif ($request->hasParameter('B_DELETE_ENTRY')) { $accio = 'DELETE_ENTRY'; } elseif ($request->hasParameter('B_SAVE_ENTRY')) { $accio = 'SAVE_ENTRY'; } elseif ($request->hasParameter('B_NEW_BLOG')) { $accio = 'NEW_BLOG'; } elseif ($request->hasParameter('B_EDIT_BLOG')) { $accio = 'EDIT_BLOG'; } elseif ($request->hasParameter('B_DELETE_BLOG')) { $accio = 'DELETE_BLOG'; } elseif ($request->hasParameter('B_SAVE_BLOG')) { $accio = 'SAVE_BLOG'; } elseif ($request->hasParameter('B_VIEW_CONTENT')) { $accio = 'VIEW_CONTENT'; } elseif ($request->hasParameter('B_VIEW_STADISTICS')) { $accio = 'VIEW_STADISTICS'; } elseif ($request->hasParameter('B_VIEW_FORM')) { $accio = 'VIEW_FORM'; } } switch ($accio) { case 'NEW_MENU': $this->FORM_MENU = AppBlogsMenuPeer::initialize(0, $this->APP_BLOG, $this->IDS); break; case 'EDIT_MENU': $this->FORM_MENU = AppBlogsMenuPeer::initialize($this->APP_MENU, $this->APP_BLOG, $this->IDS); break; case 'DELETE_MENU': $this->FORM_MENU = AppBlogsMenuPeer::initialize($this->APP_MENU, $this->APP_BLOG, $this->IDS); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_MENU->getObject()); $this->FORM_MENU->getObject()->setInactiu(); $this->redirect('gestio/gBlogs?accio=VIEW_CONTENT'); break; case 'SAVE_MENU': $RP = $request->getParameter('app_blogs_menu'); $this->APP_MENU = $RP['id']; $this->APP_BLOG = $RP['blog_id']; $this->FORM_MENU = AppBlogsMenuPeer::initialize($this->APP_MENU, $this->APP_BLOG, $this->IDS); $this->FORM_MENU->bind($RP); if ($this->FORM_MENU->isValid()) { try { $this->FORM_MENU->save(); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_MENU->getObject()); $this->APP_MENU = $this->FORM_MENU->getObject()->getId(); unset($this->APP_MENU); $this->reloadBlog(); } catch (Exception $e) { echo $e->getMessage(); } } break; case 'NEW_PAGE': $this->FORM_PAGE = AppBlogsPagesPeer::initialize(0, $this->APP_BLOG, $this->IDS); break; case 'EDIT_PAGE': $this->FORM_PAGE = AppBlogsPagesPeer::initialize($this->APP_PAGE, $this->APP_BLOG, $this->IDS); break; case 'DELETE_PAGE': try { $RP = $request->getParameter('app_blogs_pages'); $this->APP_PAGE = $RP['id']; $this->APP_BLOG = $RP['blog_id']; $this->FORM_PAGE = AppBlogsPagesPeer::initialize($this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_PAGE->getObject()); $this->FORM_PAGE->getObject()->setInactiu(); unset($this->FORM_PAGE); $this->reloadBlog(); } catch (Exception $e) { echo $e->getMessage(); } break; case 'SAVE_PAGE': $RP = $request->getParameter('app_blogs_pages'); $this->APP_PAGE = $RP['id']; $this->APP_BLOG = $RP['blog_id']; $this->FORM_PAGE = AppBlogsPagesPeer::initialize($this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->FORM_PAGE->bind($RP); if ($this->FORM_PAGE->isValid()) { try { $this->FORM_PAGE->save(); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_PAGE->getObject()); $this->APP_PAGE = $this->FORM_PAGE->getObject()->getId(); //Ara assignem també aquesta pàgina al menú que tenim seleccionat. Si no n'hi ha cap, no fem res. if ($this->APP_MENU > 0) { $FM = AppBlogsMenuPeer::initialize($this->APP_MENU, $this->APP_BLOG, $this->IDS); $FM->getObject()->setPageId($this->APP_PAGE)->save(); } unset($this->FORM_PAGE); $this->reloadBlog(); } catch (Exception $e) { echo $e->getMessage(); } } break; case 'NEW_ENTRY': $this->FORM_ENTRY = AppBlogsEntriesPeer::initialize($this->APP_ENTRY, 'CA', $this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->GALLERY = array(); break; case 'EDIT_ENTRY': $this->FORM_ENTRY = AppBlogsEntriesPeer::initialize($this->APP_ENTRY, 'CA', $this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->GALLERY = AppBlogsEntriesPeer::getFiles($this->APP_ENTRY, 'CA'); break; case 'DELETE_ENTRY': $RS = $request->getParameter('app_blogs_entries'); $this->APP_ENTRY = $RS['id']; $this->APP_PAGE = $RS['page_id']; $this->FORM_ENTRY = AppBlogsEntriesPeer::initialize($this->APP_ENTRY, 'CA', $this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_ENTRY->getObject()); $this->FORM_ENTRY->getObject()->setInactiu(); $this->reloadBlog(); break; case 'SAVE_ENTRY': $RS = $request->getParameter('app_blogs_entries'); $this->APP_ENTRY = $RS['id']; $this->APP_PAGE = $RS['page_id']; $this->FORM_ENTRY = AppBlogsEntriesPeer::initialize($this->APP_ENTRY, 'CA', $this->APP_PAGE, $this->APP_BLOG, $this->IDS); $this->FORM_ENTRY->bind($RS); if ($this->FORM_ENTRY->isValid()) { try { $this->FORM_ENTRY->save(); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_ENTRY->getObject()); $this->APP_ENTRY = $this->FORM_ENTRY->getObject()->getId(); $this->GUARDA_IMATGES($request->getFiles('arxiu'), $request->getParameter('desc'), $this->APP_ENTRY); unset($this->FORM_ENTRY); $this->reloadBlog(); } catch (Exception $e) { echo $e->getMessage(); } } $this->GALLERY = AppBlogsEntriesPeer::getFiles($this->APP_ENTRY, 'CA'); break; case 'NEW_BLOG': $this->FORM_BLOG = AppBlogsBlogsPeer::initialize(0, $this->IDS); break; case 'EDIT_BLOG': $this->FORM_BLOG = AppBlogsBlogsPeer::initialize($this->APP_BLOG, $this->IDS); break; case 'DELETE_BLOG': $RS = $request->getParameter('app_blogs_blogs'); $this->APP_BLOG = $RS['id']; $this->FORM_BLOG = AppBlogsBlogsPeer::initialize($this->APP_BLOG, $this->IDS); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_BLOG->getObject()); $this->FORM_BLOG->getObject()->setInactiu(); unset($this->FORM_BLOG); break; case 'DELETE_IMAGE': AppBlogsMultimediaPeer::initialize($this->APP_MULTIMEDIA, $this->IDS)->getObject()->setInactiu(); $this->getUser()->addLogAction($accio, 'gBlogs', $this->APP_MULTIMEDIA); break; case 'SAVE_BLOG': $RS = $request->getParameter('app_blogs_blogs'); $this->APP_BLOG = $RS['id']; $this->FORM_BLOG = AppBlogsBlogsPeer::initialize($this->APP_BLOG, $this->IDS); $this->FORM_BLOG->bind($RS); if ($this->FORM_BLOG->isValid()) { try { $this->FORM_BLOG->save(); $this->getUser()->addLogAction($accio, 'gBlogs', $this->FORM_BLOG->getObject()); $this->APP_BLOG = $this->FORM_BLOG->getObject()->getId(); unset($this->FORM_BLOG); $this->reloadBlog(); } catch (Exception $e) { echo $e->getMessage(); } } break; case 'VIEW_CONTENT': $this->reloadBlog($this->APP_BLOG); break; case 'AJAX_PAGE': $APP_PAGE = $request->getParameter('APP_PAGE'); $APP_ENTRY = $request->getParameter('APP_ENTRY'); $HTML = AppBlogsEntriesPeer::getOptionsEntries($APP_PAGE, $APP_ENTRY, $this->IDS); return $this->renderText($HTML); break; case 'AJAX_MENU': $APP_BLOG = $request->getParameter('APP_BLOG'); $APP_MENU = $request->getParameter('APP_MENU') > 0 ? $request->getParameter('APP_MENU') : 0; $APP_PAGE = $request->getParameter('APP_PAGE') > 0 ? $request->getParameter('APP_PAGE') : 0; $HTML = AppBlogsPagesPeer::getOptionsPages($APP_BLOG, $APP_MENU, $APP_PAGE, $this->IDS); return $this->renderText($HTML); break; case 'AJAX_ESTAT_FORM': $APP_FORM_ENTRY = $request->getParameter('APP_FORM_ENTRY'); $ESTAT = $request->getParameter('ESTAT'); $OO = AppBlogsFormsEntriesPeer::initialize($APP_FORM_ENTRY, $this->IDS)->getObject(); $OO->setEstat($ESTAT); $OO->save(); return $this->renderText('Canvi fet correctament'); break; case 'AJAX_SAVE_OBJECCIONS': $APP_FORM_ENTRY = $request->getParameter('APP_FORM_ENTRY'); $OO = AppBlogsFormsEntriesPeer::initialize($APP_FORM_ENTRY, $this->IDS); $OO->setObjeccions($request->getParameter('OBJECCIONS')); $OO->save(); return $this->renderText('Canvi fet correctament'); break; case 'VB': $this->APP_BLOG = -1; $this->APP_PAGE = -1; $this->APP_ENTRY = -1; $this->APP_MENU = -1; $this->APP_MULTIMEDIA = -1; $this->APP_FORM = -1; $this->getUser()->addLogAction('inside', 'gBlogs'); break; case 'VIEW_STADISTICS': //Veure estructura d'arbre $this->PAGES_WITHOUT_CONTENT = AppBlogsPagesPeer::getPagesWithoutContent($this->APP_BLOG, $this->IDS); $this->MENUS_WITHOUT_PAGES = AppBlogsMenuPeer::getMenusWithoutPages($this->APP_BLOG, $this->IDS); $this->TREE = AppBlogsMenuPeer::getOptionsMenus($this->APP_BLOG, null, false, $this->IDS); break; case 'VIEW_FORM': $datai = mktime(0, 0, 0, date('m', time()) - 2, date('d', time()), date('Y', time())); $this->VIEW_FORM_ENTRIES = AppBlogsFormsEntriesPeer::getEntries($this->APP_FORM, date('Y-m-d', $datai), $this->IDS); $this->VIEW_FIELDS = AppBlogsFormsEntriesPeer::getFields($this->APP_FORM, $this->IDS); break; } $this->BLOGS_ARRAY = AppBlogsBlogsPeer::getOptionsBlogs($this->APP_BLOG, $this->IDS); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeNoticiesculturals(sfWebRequest $request) { $this->IDS = 1; $this->PAGE_ID_QUE_ESTA_PASSANT = 1; $this->PAGE_ID_QUE_PASSARA = 2; $this->PAGE_ID_QUE_HA_PASSAT = 3; $this->FORM_ID = 2; $this->BLOG_ID = 4; $this->setLayout('blank'); $this->PAGE_ID = $this->ParReqSesForm($request, 'PAGE_ID', $this->PAGE_ID_QUE_ESTA_PASSANT); $this->NOTICIA_ID = $this->ParReqSesForm($request, 'NOTICIA_ID', -1); $this->PAGINA = $request->getParameter('PAGINA', 1); $this->MODE = $this->ParReqSesForm($request, 'MODE', 'CONTINGUT'); $this->ERRORS = ""; if ($this->MODE == 'CONTINGUT' && $request->hasParameter('NOTICIA_ID')) { $this->NOTICIA = AppBlogsEntriesPeer::retrieveByPK($request->getParameter('NOTICIA_ID')); $this->MODE = 'CONTINGUT'; } elseif ($this->MODE == 'CONTINGUT') { $order = $this->PAGE_ID == $this->PAGE_ID_QUE_HA_PASSAT ? false : true; $this->NOTICIES = AppBlogsEntriesPeer::getEntries($this->PAGE_ID, $this->PAGINA, $order, $this->IDS); $this->MODE = 'CONTINGUT'; } elseif ($this->MODE == 'FORM1') { $this->FORM1 = array('nom_entitat' => '', 'nom_cognoms' => '', 'lloc_ocupa' => '', 'nom_cognoms_contacte' => '', 'adreca' => '', 'codi_postal' => '', 'municipi' => '', 'comarca' => '', 'telefons' => '', 'email' => ''); } elseif ($this->MODE == 'FORM2') { $this->DADES = $request->getParameter('dades'); $this->getUser()->setAttribute('dades', $this->DADES); $this->FORM2 = array('titol' => '', 'subtitol1' => '', 'ciutat_acte' => '', 'dia_acte' => '', 'web' => '', 'imatge' => '', 'tipus' => '', 'resum' => ''); } elseif ($this->MODE == 'ENVIA_FINALITZA') { if (!$this->getUser()->hasAttribute('dades')) { $this->redirect('@noticies_culturals?MODE=FORM1'); } $this->getUser()->setAttribute('dades2', $request->getParameter('dades')); $this->DADES = $this->getUser()->getAttribute('dades'); $this->DADES2 = $this->getUser()->getAttribute('dades2'); foreach ($this->DADES2 as $K => $E) { $this->DADES[$K] = $E; } AppBlogsFormsPeer::save($this->FORM_ID, $this->DADES, $request->getFiles(), $this->IDS); $this->MODE = 'FORM_OK'; } elseif ($this->MODE == 'ACTUALITZA') { $next_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 2, date('d', time()), date('Y', time()))); $next_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 1, date('d', time()), date('Y', time()))); $today = date('Y-m-d', time()); $previous_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 1, date('d', time()), date('Y', time()))); $previous_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 2, date('d', time()), date('Y', time()))); //Captem els que s'han de migrar del formulari $C = new Criteria(); $C = AppBlogsFormsEntriesPeer::getCriteriaActiu($C, $this->IDS); $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID); $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT_WAIT); //Treballem i migrem els camps que hem marcat com "Per publicar" foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) { $RET = array(); foreach (explode("@@@", $OO->getDades()) as $E) { $EX = explode("###", $E); if (isset($EX[0]) && isset($EX[1])) { list($EXCAMP, $TEXT) = explode("###", $E); $RET[$EX[0]] = $EX[1]; } } try { $ON = AppBlogsEntriesPeer::initialize(0, 'CA', 1, 1, $this->IDS)->getObject(); $ON->setTitle($RET['titol']); $ON->setSubtitle1($RET['subtitol1']); $ON->setSubtitle2($RET['ciutat_acte'] . ', ' . $this->dataText($RET['dia_acte'])); $ON->setBody($RET['text']); $ON->setTags($RET['tipus']); echo stripos($RET['web'], 'http://'); if (!stripos($RET['web'], 'http://')) { $ON->setUrl('http://' . $RET['web']); } else { $ON->setUrl($RET['web']); } $ON->setDate($RET['dia_acte']); $dia = $RET['dia_acte']; if ($dia >= $today && $dia < $next_month) { $ON->setPageId($this->PAGE_ID_QUE_ESTA_PASSANT); } elseif ($dia < $today) { $ON->setPageId($this->PAGE_ID_QUE_HA_PASSAT); } elseif ($dia > $next_month) { $ON->setPageId($this->PAGE_ID_QUE_PASSARA); } $ON->save(); //Guardem la notÃcia //Guardem les imatges if (isset($RET['file'])) { $WEBSYSROOT = OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS); //Mirem l'extensió de l'arxiu $path_info = pathinfo($WEBSYSROOT . 'uploads/formularis/' . $RET['file']); //Si l'arxiu és una imatge, el tractem i el posem com a imatge if (strtolower($path_info['extension']) == 'jpg' || strtolower($path_info['extension']) == 'png') { try { $img = new sfImage($WEBSYSROOT . 'uploads/formularis/' . $RET['file'], 'image/jpeg'); $img->resize(200, null); $img->saveAs($WEBSYSROOT . 'images/blogs/' . $RET['file']); $OM = AppBlogsMultimediaPeer::initialize(0, $this->IDS)->getObject(); $OM->setName($RET['file']); $OM->setUrl($RET['file']); $OM->save(); echo 'ONID:' . $ON->getId(); $OME = AppBlogMultimediaEntriesPeer::initialize($ON->getId(), $OM->getId(), $this->IDS)->getObject()->save(); } catch (Exception $e) { echo 'hail'; echo $e->getMessage(); echo $e->getCode(); } } } $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT); $OO->save(); } catch (Exception $e) { echo 'fiodaf'; echo $e->getMessage(); echo $e->getCode(); } } /** * Captem els valors que han estat marcats com "Per arxivar" i els passem a "arxivats" */ $C = new Criteria(); $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS); $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID); $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT_WAIT); foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) { $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT); $OO->save(); } /** * Procès de canvi de lloc les notÃcies que ja han passat a una altra pà gina */ //Captem les notÃcies que han de canviar de pà gina... (Actual->Passades) $C = new Criteria(); $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS); $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_ESTA_PASSANT); $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::LESS_THAN); foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) { $OO->setPageid($this->PAGE_ID_QUE_HA_PASSAT); $OO->save(); } //Captem les notÃcies que han de canviar de pà gina... (Futures->actual) $C = new Criteria(); $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS); $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_PASSARA); $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::GREATER_THAN); $C->add(AppBlogsEntriesPeer::DATE, $next_month, CRITERIA::LESS_THAN); foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) { $OO->setPageid($this->PAGE_ID_QUE_ESTA_PASSANT); $OO->save(); } // $this->redirect('blogs/noticiesculturals?MODE=CONTINGUT&PAGE_ID='.$this->PAGE_ID_QUE_ESTA_PASSANT); } }