Example #1
0
 public static function getJobIdsByTag($tag)
 {
     $c = new Criteria();
     $c->add(TaggingPeer::TAG_ID, $tag->getId());
     $c->add(TaggingPeer::TAGGABLE_MODEL, "Job");
     $ids = array();
     $taggings = TaggingPeer::doSelect($c);
     foreach ($taggings as $t) {
         $ids[] = $t->getTaggableId();
     }
     return $ids;
 }
Example #2
0
 public function getTaggings($criteria = null, $con = null)
 {
     include_once 'plugins/sfPropelActAsTaggableBehaviorPlugin/lib/model/om/BaseTaggingPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collTaggings === null) {
         if ($this->isNew()) {
             $this->collTaggings = array();
         } else {
             $criteria->add(TaggingPeer::TAG_ID, $this->getID());
             TaggingPeer::addSelectColumns($criteria);
             $this->collTaggings = TaggingPeer::doSelect($criteria, $con);
         }
     } else {
         if (!$this->isNew()) {
             $criteria->add(TaggingPeer::TAG_ID, $this->getID());
             TaggingPeer::addSelectColumns($criteria);
             if (!isset($this->lastTaggingCriteria) || !$this->lastTaggingCriteria->equals($criteria)) {
                 $this->collTaggings = TaggingPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastTaggingCriteria = $criteria;
     return $this->collTaggings;
 }
Example #3
0
 /**
  * Gets an array of Tagging objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this Tag has previously been saved, it will retrieve
  * related Taggings from storage. If this Tag is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array Tagging[]
  * @throws     PropelException
  */
 public function getTaggings($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(TagPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collTaggings === null) {
         if ($this->isNew()) {
             $this->collTaggings = array();
         } else {
             $criteria->add(TaggingPeer::TAG_ID, $this->id);
             TaggingPeer::addSelectColumns($criteria);
             $this->collTaggings = TaggingPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return the collection.
             $criteria->add(TaggingPeer::TAG_ID, $this->id);
             TaggingPeer::addSelectColumns($criteria);
             if (!isset($this->lastTaggingCriteria) || !$this->lastTaggingCriteria->equals($criteria)) {
                 $this->collTaggings = TaggingPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastTaggingCriteria = $criteria;
     return $this->collTaggings;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(TaggingPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(TaggingPeer::DATABASE_NAME);
         $criteria->add(TaggingPeer::ID, $pks, Criteria::IN);
         $objs = TaggingPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
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();
$tag_old = array(16168, 16105, 16182, 15962, 15963, 1442, 7389, 8331, 6304, 6417, 8019, 15923, 15969, 16198, 15953, 1077, 15957, 16180, 2251, 2252, 7457, 15973, 2406, 7902, 8163, 2253, 2254, 15987, 16018, 15983, 2328, 15996, 15945, 2256, 6100, 16190, 16078, 1182, 16062, 8332, 1282, 7736, 1341, 6109, 1345, 205, 15914, 7339, 4563, 5858, 4977, 8183, 1234, 1246, 1237, 5548, 6059, 6150, 16070, 8290, 8089, 16171, 15968, 2411, 2250, 4256, 8291, 2214, 8091, 15931, 8090, 1686, 15990, 15994, 8076, 6299, 16167, 16106, 15981, 15988, 16169, 6034, 7375, 88, 5596, 15982, 6306, 482, 8337, 6673, 6734, 16132, 7360, 8046, 665, 16131, 4265, 8132, 4536, 1627, 1629, 15937, 1850, 16174, 16075, 16133, 1654, 7287, 1665, 16225, 2362, 4498, 5336, 8012, 1302);
$tag_new = array(17, 22, 63, 98, 98, 141, 313, 708, 832, 838, 838, 857, 946, 1072, 1073, 1090, 1092, 1137, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1181, 1266, 1281, 1294, 1338, 1338, 1338, 1338, 1422, 1423, 1423, 1433, 1562, 1618, 1618, 1618, 1618, 1618, 1641, 1655, 1655, 1655, 1655, 1655, 1655, 1657, 1657, 1657, 1662, 1662, 1663, 1663, 1663, 1685, 1704, 1803, 1812, 1812, 1812, 1812, 1829, 1877, 4255, 4484, 4497, 4849, 5073, 5073, 5073, 5351, 5718, 5726, 5728, 6633, 7169, 7398, 8184, 8184, 16206, 16210, 16210, 16211, 16215, 16216, 16216, 16217, 16218, 16221, 16221, 16222, 16222, 16225, 16225, 16226, 16226, 16229, 16230);
if (count($tag_old) == count($tag_new)) {
    $number_tagging_ok = 0;
    $number_tagging_no = 0;
    //SOSTITUISCI OGGETTI TAGGATI CON NUOVO TAG
    foreach ($tag_old as $k => $old) {
        $c = new Criteria();
        $c->add(TaggingPeer::TAG_ID, $old);
        $results = TaggingPeer::doSelect($c);
        foreach ($results as $rs) {
            $obj_tag = TagPeer::retrieveByPk($tag_new[$k]);
            if ($obj_tag) {
                $c = new Criteria();
                $c->add(TaggingPeer::TAG_ID, $tag_new[$k]);
                $c->add(TaggingPeer::TAGGABLE_ID, $rs->getTaggableId());
                $c->add(TaggingPeer::TAGGABLE_MODEL, $rs->getTaggableModel());
                $r = TaggingPeer::doSelectOne($c);
                if (!$r) {
                    $rs->setTagId($tag_new[$k]);
                    $rs->save();
                    echo "sostituito " . $old . " con " . $tag_new[$k] . " in " . $rs->getTaggableId() . "\n";
                    $number_tagging_ok = $number_tagging_ok + 1;
                } else {
                    $rs->delete();
 /**
  * Tags saving logic, runned after the object himself has been saved
  *
  * @param      BaseObject  $object
  */
 public function postSave(BaseObject $object)
 {
     $tags = self::get_tags($object);
     $removed_tags = self::get_removed_tags($object);
     // read some config parameters and defaults
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
     $tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
     $use_unique_triple_values = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_use_unique_triple_values', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_use_unique_triple_values', false));
     $user = @sfContext::getInstance()->getUser();
     // save new tags
     foreach ($tags as $tagname) {
         if ($use_unique_triple_values) {
             $tag = TagPeer::retrieveOrCreateByTripleValue($tagname);
         } else {
             $tag = TagPeer::retrieveOrCreateByTagName($tagname);
         }
         $tag->save();
         $tagging = TaggingPeer::retrieveOrCreateByTagAndTaggable($tag->getId(), $object->getPrimaryKey(), get_class($object));
         $user_id = deppPropelActAsTaggableToolkit::getUserId();
         if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '') {
             if ($tagging->isNew()) {
                 $tagging->setUserId($user_id);
             }
         }
         $tagging->save();
     }
     // remove removed tags
     $removed_tag_ids = array();
     $c = new Criteria();
     $c->add(TagPeer::NAME, $removed_tags, Criteria::IN);
     if (Propel::VERSION >= '1.3') {
         $rs = TagPeer::doSelectStmt($c);
         while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
             $removed_tag_ids[] = intval($row['ID']);
         }
     } else {
         $rs = TagPeer::doSelectRS($c);
         while ($rs->next()) {
             $removed_tag_ids[] = $rs->getInt(1);
         }
     }
     $c = new Criteria();
     $c->add(TaggingPeer::TAG_ID, $removed_tag_ids, Criteria::IN);
     $c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
     $c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     // for authenticated users that do not have tagging_removal_credentials
     // if the only tags they're allowed to remove are their own
     // then, remove only those tags
     // this only works, if anonymnous_tagging is set to false
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '' && $allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
         $c->add(TaggingPeer::USER_ID, $user_id);
     }
     // delete e non doDelete, in modo che anche sul tagging si possano attivare i behavior (per le news)
     // TaggingPeer::doDelete($c);
     $tags_to_delete = TaggingPeer::doSelect($c);
     foreach ($tags_to_delete as $tag_to_delete) {
         $tag_to_delete->delete();
     }
     $tags = array_merge(self::get_tags($object), $this->getSavedTags($object));
     self::set_saved_tags($object, $tags);
     self::clear_tags($object);
     self::clear_removed_tags($object);
 }
<?php

/*
 * This file is part of the Openpolis project
 *
 * (c) 2008 Guglielmo Celata <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 * find all taggings related to a non-existing opp_atto record and remove them
 *
 */
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();
$cnt = 0;
echo "Processing all taggings\n";
$c = new Criteria();
$taggings = TaggingPeer::doSelect($c);
foreach ($taggings as $i => $tagging) {
    $atto = $tagging->getTaggedAtto();
    if (!$atto instanceof OppAtto) {
        $cnt++;
        echo $tagging->getID() . " - " . $tagging->getTaggableId() . "\n";
        $tagging->delete();
    }
}
echo "\n{$i} taggings processed ({$cnt} broken links deleted)\n";