Example #1
0
 /**
  * 
  * @param string $object
  * @param string $tag
  */
 public function addTagAction($object, $tag)
 {
     $iNbAdded = 0;
     $sLibTag = 'tag';
     $aError = array();
     $repository = $this->repository;
     $sName = $this->objectName;
     $repository::transco($object);
     $aId = $repository::getListBySlugName($object[$sName]);
     if (count($aId) > 0) {
         $object = $aId[0]['id'];
     } else {
         throw new \Exception(static::OBJ_NOT_EXIST, 1);
     }
     $aTags = explode(",", $tag);
     foreach ($aTags as $sTag) {
         $bOkyToAdd = true;
         $iIdTag = TagsRepository::getTagId($sTag, 1, 0);
         if (!empty($iIdTag)) {
             $bLink = TagsRepository::isLink($sName, $object, $iIdTag);
             if ($bLink) {
                 $aError[] = $sTag;
                 $bOkyToAdd = false;
             }
         }
         if ($bOkyToAdd) {
             TagsRepository::add($sTag, $this->objectName, $object, 1);
             $iNbAdded++;
         }
     }
     if (count($aTags) == 1) {
         $sLibTag = $aTags[0];
     } else {
         if (count($aTags) > 1) {
             $sLibTag .= "s";
         }
     }
     if ($iNbAdded > 0) {
         InputOutput::display($sLibTag . " has been successfully added to the object", true, 'green');
         if ($iNbAdded > 0 && count($aError) > 0) {
             throw new \Exception("but some tags already exists : '" . implode("', '", $aError) . "'", 1);
         }
     } else {
         throw new \Exception($sLibTag . " already exists", 1);
     }
 }
 public function testGetTagId()
 {
     $this->assertEquals(1, TagsRepository::getTagId('Tag1'));
 }