Exemple #1
0
 public function fullgallery()
 {
     if (isset($_POST['tags']) && !empty($_POST['tags'])) {
         $this->viewData['searh_tags'] = $_POST['tags'];
         $tags = explode(',', $_POST['tags']);
     }
     $imagesList = array();
     $model = new GalleryModel();
     $tagModel = new TagModel();
     foreach ($tags as $tag) {
         $images = $model->getAllItemsByTagName(trim($tag));
         $imagesList = array_merge($imagesList, $images);
     }
     $this->viewData['images'] = $imagesList;
     shuffle($this->viewData['images']);
     $this->viewData['tags'] = $tagModel->getAllItems();
     echo $this->twig->render('gallery/gallery.html.twig', $this->viewData);
 }
 public function insertTag($tagList, $itemId)
 {
     $tagModel = new TagModel();
     foreach ($tagList as $tag) {
         //check if tag exist and return id
         $tagId = $tagModel->getByName($tag);
         if (!$tagId || $tagId == null) {
             //else create the tag and return id
             $tagId = $tagModel->insertTag(array('tag' => $tag));
         } else {
             $tagId = $tagId[0]['id'];
         }
         //echo $tag . ' ' . $tagId . ' / ';
         //link tag to gallery item
         $tagModel->insertTagForItem(array('tag_id' => $tagId, 'gallery_item_id' => $itemId));
     }
 }