Exemplo n.º 1
0
 public static function getOrCreate($categoryName)
 {
     $categoryDAO = new Category();
     $category = $categoryDAO->findFirst("categoryName='{$categoryName}'");
     $pinyin = new Pinyin();
     if (!$category) {
         $category = new Category();
         $category->categoryName = $categoryName;
         $category->initial = substr($pinyin->transformUcwords($category->categoryName), 0, 1);
         $category->save();
     }
     return $category;
 }
Exemplo n.º 2
0
 public function updateEntry($data)
 {
     $textData = isset($data['text']) ? $data['text'] : array();
     $synonymies = isset($data['synonymies']) ? $data['synonymies'] : array();
     $categoryData = isset($data['categories']) ? $data['categories'] : array();
     if ($textData) {
         unset($data['text']);
         $text = new EntryTexts();
         $text->assign($textData);
         $this->text = $text;
     }
     $keywords = array();
     if ($synonymies) {
         unset($data['synonymies']);
         $synonymiesArray = is_array($synonymies) ? $synonymies : explode(',', $synonymies);
         $synonymiesArray[] = $data['title'];
         $entryKeyword = new EntryKeyword();
         $entryKeyword->fullUpdateEntryKeywords($this->id, $synonymiesArray);
     }
     if ($categoryData) {
         unset($data['categories']);
         $cateEntry = new CategoryEntry();
         $cateEntry->fullUpdateCategoriesEntries($this->id, $categoryData);
     }
     $this->assign($data);
     $pinyin = new Pinyin();
     $this->initial = substr($pinyin->transformUcwords($this->title), 0, 1);
     if (!$this->save()) {
         throw new RuntimeException('Create post failed');
     }
     return $this;
 }