Example #1
0
 /**
  * @param \RokGallery_Model_File $file
  * @param array $tags
  */
 public static function addTagsToFile(RokGallery_Model_File &$file, array $tags = array())
 {
     try {
         foreach ($tags as $tag) {
             $found = false;
             foreach ($file->Tags as $current_tag) {
                 if (strtolower($tag) == $current_tag['tag']) {
                     $found = true;
                     continue 2;
                 }
             }
             $next = $file->Tags->count();
             $file->Tags[$next]['tag'] = $tag;
             $galleries = RokGallery_Model_GalleryTable::getByTag($tag);
             foreach ($galleries as $gallery) {
                 $file->updateSlicesForGallery($gallery);
             }
             // If a Slice has the same tag delete it   its moved to the file now
             $query = Doctrine_Query::create()->delete('RokGallery_Model_SliceTags st')->whereIn('st.slice_id', $file->Slices->getPrimaryKeys())->andWhere('st.tag = ?', $tag);
             $query->execute();
         }
         $file->save();
     } catch (Exception $e) {
         throw $e;
     }
 }