Exemplo n.º 1
0
 public static function updateTagRelationCache($manualLock = false)
 {
     if (!$manualLock) {
         self::checkTagRelationCache('lock');
     }
     try {
         $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php";
         $c = new Criteria();
         $allTags = TagPeer::doSelect($c);
         $content = "<?php \n";
         foreach ($allTags as $singleTag) {
             $c = new Criteria();
             $c->add(TagrelationPeer::TAG_ID, $singleTag->getId());
             $tagRelations = TagrelationPeer::doSelect($c);
             if ($tagRelations) {
                 $elementsArr = "array(";
                 foreach ($tagRelations as $tagRelation) {
                     $elementsArr .= $tagRelation->getId() . ",";
                 }
                 $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n";
             }
         }
         $content .= "\n?>";
         if (FileHelper::writeFile($tagRelationsFile, $content)) {
             BackendService::loadTagsRelations();
         } else {
             echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR);
         }
     } catch (Exception $e) {
         echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR);
     }
     if (!$manualLock) {
         self::checkTagRelationCache('unlock');
     }
 }
 public static function retrieveTagsFromTTPK($id)
 {
     $c = new Criteria();
     $c->add(OppTagHasTtPeer::TESEOTT_ID, $id);
     $c->addJoin(OppTagHasTtPeer::TAG_ID, TagPeer::ID);
     $c->addAscendingOrderByColumn(TagPeer::TRIPLE_VALUE);
     return TagPeer::doSelect($c);
 }
 public function getTags()
 {
     $c = new Criteria();
     $c->add(OppTagHasTtPeer::TESEOTT_ID, $this->getId());
     $c->addJoin(OppTagHasTtPeer::TAG_ID, TagPeer::ID);
     $c->addAscendingOrderByColumn(TagPeer::TRIPLE_VALUE);
     return TagPeer::doSelect($c);
 }
 public function getConfigurationModes()
 {
     $aResult = array();
     $aResult['templates'] = AdminManager::getSiteTemplatesForListOutput();
     $aResult['tags'] = array();
     foreach (TagPeer::doSelect(new Criteria()) as $oTag) {
         $aResult['tags'][] = array('name' => $oTag->getName(), 'count' => $oTag->countTagInstances(), 'id' => $oTag->getId());
     }
     $aResult['types'] = TagInstancePeer::getTaggedModels();
     return $aResult;
 }
Exemplo n.º 5
0
 public static function getNamesForAutocomplete($q)
 {
     sfLoader::loadHelpers("Url");
     $c = new Criteria();
     $c->add(TagPeer::NAME, $q . "%", Criteria::LIKE);
     $c->setLimit(10);
     $names = array();
     $tags = TagPeer::doSelect($c);
     foreach ($tags as $tag) {
         $names[] = array("id" => $tag->getId(), "name" => $tag->getName(), "searchUrl" => url_for("job_listby_tag", $tag));
     }
     return $names;
 }
 /**
  * @action search
  * 
  * Action to search tags using a string of 3 letters or more.
  * @param KalturaTagFilter $tagFilter
  * @param KalturaFilterPager $pager
  * @return KalturaTagListResponse
  */
 public function searchAction(KalturaTagFilter $tagFilter, KalturaFilterPager $pager = null)
 {
     if (!$tagFilter) {
         $tagFilter = new KalturaTagFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $tagFilter->validate();
     $c = KalturaCriteria::create(TagPeer::OM_CLASS);
     $tagCoreFilter = new TagFilter();
     $tagFilter->toObject($tagCoreFilter);
     $tagCoreFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $tags = TagPeer::doSelect($c);
     $searchResponse = new KalturaTagListResponse();
     $searchResponse->objects = KalturaTagArray::fromDbArray($tags);
     $searchResponse->totalCount = $c->getRecordsCount();
     return $searchResponse;
 }
Exemplo n.º 7
0
 /**
  * returns the Tags (TaggingsJoinTag) that makes the object indirectly monitored
  *
  * @return Tagging objects (with Tag infoz)
  * @author Guglielmo Celata
  **/
 public function getIndirectlyMonitoringTags($user_id, $criteria = null, $con = null)
 {
     include_once 'plugins/deppPropelActAsTaggableBehaviorPlugin/lib/model/om/BaseTaggingPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collIMTags === null) {
         if ($this->isNew()) {
             $this->collIMTags = array();
         } else {
             $criteria->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
             $criteria->addJoin(MonitoringPeer::MONITORABLE_ID, TagPeer::ID);
             $criteria->add(TaggingPeer::TAGGABLE_ID, $this->getId());
             $criteria->add(MonitoringPeer::USER_ID, $user_id);
             $this->collIMTags = TagPeer::doSelect($criteria, $con);
         }
     } else {
         $criteria->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
         $criteria->addJoin(MonitoringPeer::MONITORABLE_ID, TagPeer::ID);
         $criteria->add(TaggingPeer::TAGGABLE_ID, $this->getId());
         $criteria->add(MonitoringPeer::USER_ID, $user_id);
         if (!isset($this->lastIMTagsCriteria) || !$this->lastIMTagsCriteria->equals($criteria)) {
             $this->collIMTags = TagPeer::doSelect($criteria, $con);
         }
     }
     $this->lastIMTagsCriteria = $criteria;
     return $this->collIMTags;
 }
Exemplo n.º 8
0
 /**
  * @action indexCategoryEntryTags
  * 
  * @param int $categoryId 
  * @param string $pcToDecrement
  * @param string $pcToIncrement
  */
 public function indexCategoryEntryTagsAction($categoryId, $pcToDecrement, $pcToIncrement)
 {
     $pcToDecrementArray = explode(',', $pcToDecrement);
     $c = KalturaCriteria::create(TagPeer::OM_CLASS);
     $c->add(TagPeer::PARTNER_ID, kCurrentContext::getCurrentPartnerId());
     $c->add(TagPeer::PRIVACY_CONTEXT, $pcToDecrementArray, KalturaCriteria::IN);
     TagPeer::setUseCriteriaFilter(false);
     $tagsToDecrement = TagPeer::doSelect($c);
     TagPeer::setUseCriteriaFilter(true);
     foreach ($tagsToDecrement as $tag) {
         /* @var $tag Tag */
         $tag->decrementInstanceCount();
     }
     $pcToIncrementArray = explode(',', $pcToIncrement);
     $tagsToIncrement = array();
     $c = new Criteria();
     $c->add(categoryEntryPeer::CATEGORY_ID, $categoryId);
     $catEntries = categoryEntryPeer::doSelect($c);
     foreach ($catEntries as $catEntry) {
         /* @var $catEntry categoryEntry */
         $entry = entryPeer::retrieveByPK($catEntry->getEntryId());
         if ($entry) {
             $tagsToIncrement = array_merge($tagsToIncrement, explode(',', $entry->getTags()));
         }
     }
     $tagsToIncrement = array_unique($tagsToIncrement);
     kTagFlowManager::addOrIncrementTags(implode(",", $tagsToIncrement), kCurrentContext::getCurrentPartnerId(), "entry", $pcToIncrementArray);
 }
while ($entryResults && count($entryResults)) {
    foreach ($entryResults as $entry) {
        /* @var $entry entry */
        $entryTags = trimObjectTags($entry->getTags());
        if (!count($entryTags)) {
            continue;
        }
        $c = kTagFlowManager::getTagObjectsByTagStringsCriteria($entryTags, taggedObjectType::ENTRY, $entry->getPartnerId());
        $c->applyFilters();
        $numTagsFound = $c->getRecordsCount();
        if (!$numTagsFound) {
            $requiredTags = $entryTags;
        } else {
            $crit = new Criteria();
            $crit->addAnd(TagPeer::ID, $c->getFetchedIds(), KalturaCriteria::IN);
            $foundTagObjects = TagPeer::doSelect($crit);
            $foundTags = array();
            foreach ($foundTagObjects as $foundTag) {
                $foundTag->incrementInstanceCount();
                $foundTags[] = $foundTag->getTag();
            }
            $requiredTags = array_diff($entryTags, $foundTags);
        }
        foreach ($requiredTags as $tagString) {
            $tag = new Tag();
            $tag->setTag($tagString);
            $tag->setPartnerId($entry->getPartnerId());
            $tag->setObjectType(taggedObjectType::ENTRY);
            $tag->save();
        }
    }
 /**
  * Function which checks the object tags agains DB
  * and returns an array of tags ids which need to be deleted.
  * @param BaseObject $object
  * @return array
  */
 protected function checkExistForDelete(BaseObject $object, $tagsToCheck = null)
 {
     $objectTags = $tagsToCheck ? $this->trimObjectTags($tagsToCheck) : $this->trimObjectTags($object->getTags());
     $objectTags = str_replace(self::$specialCharacters, self::$specialCharactersReplacement, $objectTags);
     $tagsToKeep = array();
     foreach ($objectTags as $objectTag) {
         $peer = $object->getPeer();
         $c = KalturaCriteria::create(get_class($object));
         $c->addAnd(self::PARTNER_ID_FIELD, $object->getPartnerId(), KalturaCriteria::EQUAL);
         $c->addAnd($peer::TAGS, $objectTag, KalturaCriteria::LIKE);
         $c->addAnd($peer::ID, array($object->getId()), KalturaCriteria::NOT_IN);
         $selectResults = $peer->doSelect($c);
         foreach ($selectResults as $selectResult) {
             $resultTags = $this->trimObjectTags($selectResult->getTags());
             if (in_array($objectTag, $resultTags)) {
                 //    	            if(isset($tagsToKeep[$objectTag]))
                 //    	                $tagsToKeep[$objectTag]++;
                 //    	            else
                 //    	                $tagsToKeep[$objectTag] = 1;
                 if (!in_array($objectTag, $tagsToKeep)) {
                     $tagsToKeep[] = $objectTag;
                 }
             }
         }
     }
     KalturaLog::debug("tags to keep: " . print_r($tagsToKeep, true));
     if (count($tagsToKeep)) {
         //Decrement instance count for the tags that we keep
         $c = self::getTagObjectsByTagStringsCriteria($tagsToKeep, $this->getObjectIdByClassName(get_class($object)), $object->getPartnerId());
         $tagsToKeepObjects = TagPeer::doSelect($c);
         foreach ($tagsToKeepObjects as $tagToKeepObject) {
             /* @var $tagToKeepObject Tag */
             $tagToKeepObject->decrementInstanceCount();
         }
     }
     //Return the IDs of the rest of the tags for removal.
     $tagsToRemove = array_diff($objectTags, $tagsToKeep);
     KalturaLog::debug("tags to delete: " . print_r($tagsToRemove, true));
     if ($tagsToRemove) {
         $c = self::getTagObjectsByTagStringsCriteria($tagsToRemove, $this->getObjectIdByClassName(get_class($object)), $object->getPartnerId());
         $c->applyFilters();
         $recordsToRemove = $c->getRecordsCount();
         return $c->getFetchedIds();
     }
     return array();
 }
Exemplo n.º 11
0
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
// initialize instance
sfContext::createInstance($configuration);
// set default TIMEZONE
$tz = OptionPeer::retrieveOption('TIMEZONE');
if ($tz) {
    date_default_timezone_set($tz);
}
// load URL helper
sfLoader::loadHelpers('Url');
sfConfig::set('sf_relative_url_root', sfConfig::get('app_general_base_url'));
$c = new Criteria();
$expiration_age = OptionPeer::retrieveOption('BUY_DELETE_AFTER') * 24 * 3600;
$c->add(TagPeer::VALID_UNTIL, time() - $expiration_age, Criteria::LESS_EQUAL);
$c->add(TagPeer::STATUS, TagPeer::ST_EXPIRED);
$c->add(TagPeer::IS_PRIMARY, false);
$tags = TagPeer::doSelect($c);
if ($tags) {
    foreach ($tags as $tag) {
        $interesteds = $tag->getInteresteds();
        $jotag = $tag->getJotag();
        $tag->deleteFromUser();
        Mailer::sendEmail($tag->getUser()->getPrimaryEmail(), 'deletedJotag', array('jotag' => $tag, 'jotag_name' => $jotag), $tag->getUser()->getPreferedLanguage());
        if ($interesteds) {
            foreach ($interesteds as $interested) {
                // notify interested users that this jotag is available again
                Mailer::sendEmail($interested->getUser()->getPrimaryEmail(), 'interestNotifyInterested', array('user' => $interested->getUser(), 'jotag' => $interested->getJotag()), $interested->getUser()->getPreferedLanguage());
            }
        }
    }
}
 /**
  * esporta csv con dati storici della rilevanza dei tag, con limite custom
  *
  * @return void
  * @author Guglielmo Celata
  */
 public function executeRilevanzaTagExport()
 {
     sfLoader::loadHelpers(array('Number'));
     $this->session = $this->getUser();
     $this->forward404Unless($this->session->hasCredential('adhoc'));
     $data_inizio = OppLegislaturaPeer::$legislature[OppLegislaturaPeer::getCurrent()]['data_inizio'];
     $data_fine = OppTagHistoryCachePeer::fetchLastData();
     $date = Util::buildCacheDatesArray($data_inizio, $data_fine);
     $limit = $this->getRequestParameter('limit', 50);
     $c = new Criteria();
     $c->addJoin(TagPeer::ID, OppTagHistoryCachePeer::CHI_ID);
     $c->add(OppTagHistoryCachePeer::CHI_TIPO, 'S');
     $c->add(OppTagHistoryCachePeer::DATA, $data_fine);
     $c->addDescendingOrderByColumn(OppTagHistoryCachePeer::INDICE);
     $c->setLimit($limit);
     $tags = TagPeer::doSelect($c);
     $csv_rows = array();
     // costruzione delle serie storiche per ogni politico (da inizio legislatura)
     foreach ($tags as $cnt => $tag) {
         $tag_id = $tag->getId();
         // genero il label
         $label = sprintf("%s(%s)", $tag->getTripleValue(), $tag->getTripleNamespace());
         // arrotonda l'array dei valori storici a due cifre decimali (max)
         $storico = OppTagHistoryCachePeer::getHistory('S', $tag->getId());
         // primi campi (dati fissi)
         $csv_row = "{$tag_id},\"{$label}\",";
         foreach ($date as $cnt => $data) {
             if (array_key_exists($data, $storico)) {
                 $storico[$data] = format_number(round($storico[$data], 2), 'it_IT');
             } else {
                 $storico[$data] = 0;
             }
             $csv_row .= '"' . $storico[$data] . '"';
             if ($cnt < count($date) - 1) {
                 $csv_row .= ",";
             }
         }
         $csv_rows[] = $csv_row;
     }
     $this->csv_header = "tag_id,tag(namespace)," . implode(",", $date);
     $this->csv_rows = $csv_rows;
     $this->setLayout(false);
     $this->response->setContentType('text/plain');
 }
Exemplo n.º 13
0
 public static function getTagsOfDocumentById($documentId)
 {
     if (!$documentId) {
         return null;
     }
     try {
         $c = new Criteria();
         $c->add(TagrelationPeer::ID, $documentId);
         $tagRelations = TagrelationPeer::doSelect($c);
         $tagIDs = array();
         foreach ($tagRelations as $tagRel) {
             $tagIDs[] = $tagRel->getTagid();
         }
         if (!empty($tagIDs)) {
             $c = new Criteria();
             $c->add(TagPeer::ID, $tagIDs, Criteria::IN);
             $tags = TagPeer::doSelect($c);
         }
         return $tags;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 14
0
 /**
  * Decrements instance count of tags found on a deleted object
  * @param string $tagsToCheck
  * @param int $partnerId
  * @param string $objectClass
  * @param array $privacyContexts
  */
 public static function decrementExistingTagsInstanceCount($tagsToCheck, $partnerId, $objectClass, $privacyContexts = null)
 {
     $objectTags = self::trimObjectTags($tagsToCheck);
     if (!count($objectTags)) {
         return;
     }
     $c = self::getTagObjectsByTagStringsCriteria($objectTags, self::getObjectTypeByClassName($objectClass), $partnerId);
     if (!is_null($privacyContexts)) {
         if (count($privacyContexts)) {
             $c->addAnd(TagPeer::PRIVACY_CONTEXT, $privacyContexts, Criteria::IN);
         }
     } else {
         $c->addAnd(TagPeer::PRIVACY_CONTEXT, self::NULL_PC);
     }
     TagPeer::setUseCriteriaFilter(false);
     $tagsToDecrement = TagPeer::doSelect($c);
     TagPeer::setUseCriteriaFilter(true);
     foreach ($tagsToDecrement as $tag) {
         /* @var $tag Tag */
         $tag->decrementInstanceCount();
     }
 }
DbManager::setConfig($dbConf);
DbManager::initialize();
$c = new Criteria();
if ($argc > 1 && is_numeric($argv[1])) {
    $c->add(TagPeer::ID, $argv[1], Criteria::GREATER_EQUAL);
}
if ($argc > 2 && is_numeric($argv[2])) {
    $c->add(TagPeer::PARTNER_ID, $argv[2], Criteria::EQUAL);
}
$c->addAscendingOrderByColumn(TagPeer::ID);
$c->setLimit(10000);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
//$sphinxCon = DbManager::getSphinxConnection();
$tags = TagPeer::doSelect($c, $con);
$sphinx = new kSphinxSearchManager();
while (count($tags)) {
    foreach ($tags as $tag) {
        /* @var $tag Tag */
        KalturaLog::log('tag id ' . $tag->getId() . ' tag string [' . $tag->getTag() . '] crc id[' . $sphinx->getSphinxId($tag) . ']');
        try {
            $ret = $sphinx->saveToSphinx($tag, true);
        } catch (Exception $e) {
            KalturaLog::err($e->getMessage());
            exit - 1;
        }
    }
    $c->setOffset($c->getOffset() + count($tags));
    kMemoryManager::clearMemory();
    $tags = TagPeer::doSelect($c, $con);
}
KalturaLog::log('Done');
Exemplo n.º 16
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(TagPeer::ID, $pks, Criteria::IN);
         $objs = TagPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 17
0
/**
 * Genera l'elenco csv di valori e namespace dei tag
 * TAG_ID, TRIPLE_VALUE, TRIPLE_NAMESPACE
 */
function run_stlab_genera_tags_csv($task, $args, $options)
{
    static $loaded;
    // load application context
    if (!$loaded) {
        _loader();
    }
    $file_path = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . "stlab" . DIRECTORY_SEPARATOR . "tags.csv";
    if (array_key_exists('file_path', $options)) {
        $file_path = strtolower($options['file_path']);
    }
    echo "memory usage: " . memory_get_usage() . "\n";
    $start_time = time();
    $msg = sprintf("generazione csv dei tags\n");
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    $fh = fopen($file_path, 'w');
    $tags = TagPeer::doSelect(new Criteria());
    $n_tags = count($tags);
    foreach ($tags as $cnt => $tag) {
        $row = sprintf("%d,%s,%s", $tag->getId(), $tag->getTripleValue(), $tag->getTripleNamespace());
        printf("%5d/%5d: %s\n", $cnt, $n_tags, $row);
        fprintf($fh, "%s\n", $row);
    }
    fclose($fh);
    $msg = sprintf("%d tag elaborati\n", $cnt);
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    $msg = sprintf(" [%4d sec] [%10d bytes]\n", time() - $start_time, memory_get_usage());
    echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false));
}
 /**
  * Retrieves from the database tags that have been atached to the object.
  * Once loaded, this saved tags list is cached and updated in memory.
  *
  * @param      BaseObject  $object
  */
 private function getSavedTags(BaseObject $object)
 {
     if (!isset($object->_tags) || !$object->_tags->hasNamespace('saved_tags')) {
         $c = new Criteria();
         $c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
         $c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
         $c->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
         $saved_tags = TagPeer::doSelect($c);
         $tags = array();
         foreach ($saved_tags as $tag) {
             $tags[$tag->getName()] = $tag->getName();
         }
         self::set_saved_tags($object, $tags);
         return $tags;
     } else {
         return self::get_saved_tags($object);
     }
 }
 *
 * (c) 2009 Guglielmo Celata <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
echo "starting\n";
$con = Propel::getConnection(TagPeer::DATABASE_NAME);
$c = new Criteria(TagPeer::DATABASE_NAME);
$argomenti = TagPeer::doSelect($c, $con);
$ninterventi_tot = 0;
$ninterventi_max = 0;
foreach ($argomenti as $a) {
    echo $a->getTripleValue() . ": ";
    $c = new Criteria(TagPeer::DATABASE_NAME);
    $c->addJoin(OppInterventoPeer::ATTO_ID, OppAttoPeer::ID);
    $c->addJoin(TaggingPeer::TAGGABLE_ID, OppAttoPeer::ID);
    $c->add(TaggingPeer::TAGGABLE_MODEL, 'OppAtto');
    $c->add(TaggingPeer::TAG_ID, $a->getId());
    $ninterventi = OppInterventoPeer::doCount($c, $con);
    $ninterventi_tot += $ninterventi;
    if ($ninterventi > $ninterventi_max) {
        $ninterventi_max = $ninterventi;
    }
    echo " {$ninterventi} ({$ninterventi_max})\n";
Exemplo n.º 20
0
function run_tags_relations($task, $args)
{
    ini_set("memory_limit", "2048M");
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', 'frontend');
    define('SF_ENVIRONMENT', 'dev');
    define('SF_DEBUG', false);
    sfConfig::set("sf_use_relations_cache", false);
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    echo_cms_title("GENERATING TAGS RELATION CACHE...");
    //if(!class_exists("XMLParser")) include sfConfig::get('sf_root_dir')."/lib/tools/XMLParser.class.php";
    if (!class_exists("FileHelper")) {
        include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php";
    }
    //echo_cms_sep();
    $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php";
    try {
        $c = new Criteria();
        $allTags = TagPeer::doSelect($c);
        //echo_cms("Processing tags :");
        $i = 0;
        $content = "<?php \n";
        foreach ($allTags as $singleTag) {
            $c = new Criteria();
            $c->add(TagrelationPeer::TAG_ID, $singleTag->getId());
            $tagRelations = TagrelationPeer::doSelect($c);
            if ($tagRelations) {
                $elementsArr = "array(";
                foreach ($tagRelations as $tagRelation) {
                    $elementsArr .= $tagRelation->getId() . ",";
                    $i++;
                }
                $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n";
            }
        }
        echo " ====> " . $i . " tags cached\n";
        $content .= "\n?>";
        if (FileHelper::writeFile($tagRelationsFile, $content)) {
            echo_cms($tagRelationsFile . " Written successfully");
        } else {
            echo_cms_error("Error writing " . $tagRelationsFile . " !");
        }
        //echo_cms_sep();
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
    sfConfig::set("sf_use_relations_cache", true);
    //echo_cms_sep();
}
Exemplo n.º 21
0
 /**
  * Returns the tags that are related to one or more other tags, with their
  * associated weight (see sfPropelActAsTaggableToolkit::normalize for more
  * details).
  * The "related tags" of one tag are the ones which have at least one
  * taggable object in common.
  *
  * The first optionnal parameter permits to add some restrictions on the
  * objects the selected tags are related to.
  * The second optionnal parameter permits to restrict the tag selection with
  * different criterias
  *
  * @param      mixed       $tags
  * @param      array       $options
  * @return     array
  */
 public static function getRelatedTags($tags = array(), $options = array())
 {
     $tags = sfPropelActAsTaggableToolkit::explodeTagString($tags);
     if (is_string($tags)) {
         $tags = array($tags);
     }
     $tagging_options = $options;
     if (isset($tagging_options['limit'])) {
         unset($tagging_options['limit']);
     }
     $taggings = self::getTaggings($tags, $tagging_options);
     $result = array();
     foreach ($taggings as $key => $tagging) {
         $c = new Criteria();
         $c->add(TagPeer::NAME, $tags, Criteria::NOT_IN);
         $c->add(TaggingPeer::TAGGABLE_ID, $tagging, Criteria::IN);
         $c->add(TaggingPeer::TAGGABLE_MODEL, $key);
         $c->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
         $tag_objects = TagPeer::doSelect($c);
         foreach ($tag_objects as $tag) {
             if (!isset($result[$tag->getName()])) {
                 $result[$tag->getName()] = 0;
             }
             $result[$tag->getName()]++;
         }
     }
     if (isset($options['limit'])) {
         arsort($result);
         $result = array_slice($result, 0, $options['limit'], true);
     }
     ksort($result);
     return sfPropelActAsTaggableToolkit::normalize($result);
 }
 /**
  * Retrieves from the database tags that have been attached to the object by a user
  * If the user_id parameter is not passed, then retrieve all tags attached by the users (user_id is not null)
  *
  * @param      BaseObject  $object
  * @param      integer     $user_id
  */
 private function getUserSavedTags(BaseObject $object, $user_id = null)
 {
     $c = new Criteria();
     $c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
     $c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
     $c->addJoin(TaggingPeer::TAG_ID, TagPeer::ID);
     if (!is_null($user_id) && $user_id != '') {
         $c->add(TaggingPeer::USER_ID, $user_id);
     } else {
         $c->add(TaggingPeer::USER_ID, null, Criteria::ISNOTNULL);
     }
     $saved_tags = TagPeer::doSelect($c);
     $tags = array();
     foreach ($saved_tags as $tag) {
         $tags[$tag->getName()] = $tag->getName();
     }
     return $tags;
 }
Exemplo n.º 23
0
<?php

chdir(dirname(__FILE__));
require_once __DIR__ . '/../../bootstrap.php';
$c = KalturaCriteria::create(TagPeer::OM_CLASS);
$filter = new TagFilter();
$filter->set('_eq_instance_count', 0);
$filter->attachToCriteria($c);
$count = $c->getRecordsCount();
if (!$count) {
    die('No tags pending for deletion.');
}
TagPeer::setUseCriteriaFilter(false);
$tagsForDelete = TagPeer::doSelect($c);
TagPeer::setUseCriteriaFilter(true);
foreach ($tagsForDelete as $tag) {
    /* @var $tag Tag */
    switch ($tag->getObjectType()) {
        case taggedObjectType::ENTRY:
            resolveEntryTag($tag);
            break;
        case taggedObjectType::CATEGORY:
            resolveCategoryTag($tag);
            break;
    }
}
function resolveEntryTag(Tag $tag)
{
    $c = KalturaCriteria::create(entryPeer::OM_CLASS);
    $c->add(entryPeer::PARTNER_ID, $tag->getPartnerId());
    if ($tag->getPrivacyContext() != kTagFlowManager::NULL_PC) {