public function updateOrInsert($data)
 {
     $lang = $data['lang'];
     if (!array_key_exists('deleted', $data)) {
         $data['deleted'] = 0;
     }
     $emptyEntity = array_fill_keys(array_keys($this->fields) + array_keys($this->translationFields), null);
     $entityData = array_merge($emptyEntity, $data);
     $entityExists = array_key_exists('id', $entityData) && $entityData['id'];
     $this->mapper->reset();
     if ($entityExists) {
         $this->mapper->load(array('id=?', $entityData['id']));
     }
     $this->mapper->copyfrom(array_intersect_key($entityData, $this->fields));
     if ($this->mapper->save()) {
         $fkName = $this->getModelName() . '_id';
         $entityData['id'] = $this->mapper->id;
         $entityData[$fkName] = $entityData['id'];
         if (!$entityExists) {
             $langs = \Services\LanguageService::instance()->getSupportedLanguages($lang);
         } else {
             $langs = array($lang);
         }
         foreach ($langs as $alang) {
             $entityData['lang'] = $alang;
             $this->translationMapper->reset();
             $this->translationMapper->load(array($fkName . ' = ? and lang = ?', $entityData[$fkName], $alang));
             $this->translationMapper->copyfrom(array_intersect_key($entityData, $this->translationFields));
             $this->translationMapper->save();
         }
         return array_merge($data, $this->mapper->cast() + $this->translationMapper->cast());
     } else {
         throw new \Exception("Can't save entity !");
     }
 }
예제 #2
0
 protected function render()
 {
     if ($this->f3->get('VERB') == 'POST') {
         $lexicon = \Services\LanguageService::instance()->getLexicon();
         if ($this->contact && is_array($this->contact) && array_key_exists('id', $this->contact) && $this->contact['id']) {
             $resutl = array('message' => $lexicon['lc_contact_success']);
         } else {
             $resutl = array('message' => $lexicon['lc_contact_error']);
         }
         return json_encode($resutl);
     } else {
         return parent::render();
         // TODO: Change the autogenerated stub
     }
 }
예제 #3
0
 /**
  * HTTP route pre-processor
  * @param \Base $f3
  */
 function beforeroute($f3)
 {
     if (!$this->pathSegments && $f3->get('PARAMS')[1]) {
         $this->pathSegments = explode("/", $f3->get('PARAMS')[1]);
     }
     if (!$this->lang) {
         $lang = \Services\LanguageService::instance();
         if (count($this->pathSegments) > 0 && $lang->isValidLanguage($this->pathSegments[0])) {
             $language = array_shift($this->pathSegments);
             $this->lang = $language;
             $lang->setLanguage($language);
         } else {
             $this->lang = $lang->detectLanguage();
             $lang->setLanguage($this->lang);
         }
     }
 }
예제 #4
0
 function index($f3)
 {
     if ($this->pathSegments && count($this->pathSegments) > 0 && $this->pathSegments[0] == 'preview') {
         array_shift($this->pathSegments);
         $this->ptService = \Services\PageTree::instance($this->lang, true);
     } else {
         $this->ptService = \Services\PageTree::instance($this->lang);
     }
     if ($this->pathSegments) {
         $this->page = $this->ptService->matchPath($this->pathSegments);
     }
     if ($f3->get('AJAX')) {
         $this->setTemplate('ajax.htm');
     } else {
         $menu = $this->ptService->getMenu();
         $f3->set('menu', $menu);
         $supportedLanguages = \Services\LanguageService::instance()->getSupportedLanguages();
         $langUrls = $this->ptService->getLanguageUrls($supportedLanguages);
         $f3->set('langUrls', $langUrls);
     }
     if ($this->page) {
         $this->page($f3);
     } else {
         if (!$this->pathSegments) {
             $this->onePager($f3);
         } else {
             http_response_code(404);
         }
     }
     $f3->set('title', 'Le musc et la plume');
     $f3->set('lang', $this->lang);
     if ($f3->get('VERB') == 'POST') {
         $f3->set('content', 'post.htm');
     } else {
         $f3->set('content', 'index.htm');
     }
 }
예제 #5
0
 protected function render()
 {
     $lexicon = \Services\LanguageService::instance()->getLexicon();
     $hive = array_merge($lexicon, $this->scope);
     return \Template::instance()->render('layouts/' . $this->page["layout"] . '.htm', $this->mime, $hive);
 }
예제 #6
0
 public function get()
 {
     header('Cache-Control: no-cache, must-revalidate');
     header('Content-type: application/json');
     echo json_encode(\Services\LanguageService::instance()->getSupportedLanguages());
 }