Beispiel #1
0
function getTag($tag_id)
{
    # Get tag object
    $tag_object = TagQuery::create()->findOneById($tag_id);
    # Return tag object
    return $tag_object;
}
Beispiel #2
0
 public function renderFrontend()
 {
     $aData = unserialize($this->getData());
     $oTemplate = new Template($aData['template']);
     $oItemTemplatePrototype = new Template($aData['template'] . '_item');
     $bItemFound = false;
     // FIXME: Keep track of output $oCorrespondingItems and refuse output if already done
     foreach ($aData['tags'] as $iTagID) {
         $oTag = TagQuery::create()->findPk($iTagID);
         if ($oTag === null) {
             continue;
         }
         $aCorrespondingItems = $oTag->getAllCorrespondingDataEntries($aData['types']);
         foreach ($aCorrespondingItems as $i => $oCorrespondingItem) {
             if (!method_exists($oCorrespondingItem, 'renderListItem')) {
                 return;
             }
             if (!$oCorrespondingItem->shouldBeIncludedInList(Session::language(), FrontendManager::$CURRENT_PAGE)) {
                 continue;
             }
             $bItemFound = true;
             $oItemTemplate = clone $oItemTemplatePrototype;
             $oItemTemplate->replaceIdentifier('model', get_class($oCorrespondingItem));
             $oItemTemplate->replaceIdentifier('counter', $i + 1);
             $oCorrespondingItem->renderListItem($oItemTemplate);
             $oTemplate->replaceIdentifierMultiple("items", $oItemTemplate);
         }
     }
     if (!$bItemFound) {
         return null;
     }
     return $oTemplate;
 }
 public function saveData($aTagData)
 {
     $aTagData['name'] = StringUtil::normalize($aTagData['name']);
     if ($this->iTagId === null) {
         $oTag = new Tag();
     } else {
         $oTag = TagQuery::create()->findPk($this->iTagId);
     }
     $this->validate($aTagData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $sStringName = "tag.{$aTagData['name']}";
     if ($oTag->getName() !== $aTagData['name']) {
         //Rename Strings for the tag
         $sOldStringName = "tag.{$oTag->getName()}";
         foreach (TranslationQuery::create()->filterByStringKey($sOldStringName)->find() as $oString) {
             $sLanguageId = $oString->getLanguageId();
             //You can’t technically rename strings because string_key is the PKEY so we delete it and re-generate
             $oString->delete();
             $oString = new Translation();
             $oString->setStringKey($sStringName);
             $oString->setLanguageId($sLanguageId);
             $oString->save();
         }
         $oTag->setName($aTagData['name']);
     }
     foreach ($aTagData['edited_languages'] as $iIndex => $sLanguageId) {
         TranslationPeer::addOrUpdateString($sStringName, $aTagData['text'][$iIndex], $sLanguageId);
     }
     $oTag->save();
 }
 public function tagId($sTagName)
 {
     $oTag = TagQuery::create()->filterByName($sTagName)->findOne();
     if ($oTag === null) {
         return null;
     }
     return $oTag->getId();
 }
Beispiel #5
0
 public function TagsByQuery($module, $config)
 {
     $ret = array();
     $rows = TagQuery::TagsByQuery($this->db, $module, $config);
     while ($d = $this->db->fetch_array($rows)) {
         $ret[] = $d['tag'];
     }
     return $ret;
 }
 public function getCriteria()
 {
     $oQuery = TagQuery::create();
     $aExcludes = array(CriteriaListWidgetDelegate::SELECT_ALL, 'Tag');
     if ($this->oDelegateProxy->getTagModelName() !== CriteriaListWidgetDelegate::SELECT_ALL) {
         $oQuery->distinct()->joinTagInstance()->useQuery('TagInstance')->filterByModelName($this->oDelegateProxy->getTagModelName())->endUse();
     }
     return $oQuery;
 }
 public static function getTagOptions()
 {
     $aResult = TagQuery::create()->filterByTagged('Document')->select(array('Id', 'Name'))->find()->toKeyValue('Id', 'Name');
     if (count($aResult) > 0 && !Settings::getSetting('admin', 'list_allows_multiple_categories', true)) {
         $aResult = array('' => ' ---- ') + $aResult;
     }
     if (count($aResult) === 0) {
         $aResult = array('' => TranslationPeer::getString('wns.document_list.no_tags_available'));
     }
     return $aResult;
 }
Beispiel #8
0
 public static function TagsSave(Ab_Database $db, $module, $owner, $ownerid, $tags, $groupid = 0)
 {
     $sql = "\n          DELETE FROM " . $db->prefix . "tag_owner\n          WHERE modname='" . bkstr($module) . "'\n              AND owner='" . bkstr($owner) . "'\n              AND ownerid=" . intval($ownerid) . "\n        ";
     $db->query_write($sql);
     $ret = array();
     $rows = TagQuery::TagsByTags($db, $tags);
     while ($d = $db->fetch_array($rows)) {
         $ret[] = $d['tag'];
         $sql = "\n                INSERT INTO " . $db->prefix . "tag_owner\n                    (modname,owner,ownerid,tagid,groupid,userid)\n                VALUES (\n                    '" . bkstr($module) . "',\n                    '" . bkstr($owner) . "',\n                    " . intval($ownerid) . ",\n                    " . intval($d['tagid']) . ",\n                    " . intval($groupid) . ",\n                    " . intval(Abricos::$user->id) . "\n                )\n            ";
         $db->query_write($sql);
     }
     return $ret;
 }
Beispiel #9
0
function getLessonTags($lesson_id, $order_by = 'vote_count')
{
    # Get lesson object
    $lesson_object = getLesson($lesson_id);
    # Get lesson tags IDs
    $lesson_tags_ids = $lesson_object->getLessonTags()->getPrimaryKeys();
    # Get tag verse column to sort by
    $tag_verse_column_to_order_by = Propel::getDatabaseMap()->getTableByPhpName('TagVerse')->getColumnByPhpName('VerseId')->getFullyQualifiedName();
    # Get applicable tag objects
    $tags_objects = TagQuery::create()->useLessonTagQuery()->filterByPrimaryKeys($lesson_tags_ids)->endUse()->_if($order_by == 'vote_count')->orderByVoteCount()->_elseif($order_by == 'date_tagged')->orderById('DESC')->_endif()->joinWithTagVerse()->addAscendingOrderByColumn($tag_verse_column_to_order_by)->find();
    # Handle lesson tags objects
    $lesson_tags_to_return = [];
    foreach ($tags_objects as $tag_object) {
        # Append lesson tag to lesson tags to return
        $lesson_tags_to_return[] = ['id' => $tag_object->getId()];
    }
    # Return lesson tags
    return $lesson_tags_to_return;
}
Beispiel #10
0
 /**
  * Remove tag from the Page given by the id
  */
 public static function removeTagFrom($sPageId, $mTag)
 {
     if (is_string($mTag)) {
         $mTag = TagQuery::create()->findOneByName($mTag);
     }
     if ($mTag instanceof TagInstance) {
         $mTag = $mTag->getTag();
     }
     if (!$mTag instanceof Tag) {
         return;
     }
     $oQuery = TagInstanceQuery::create();
     $oQuery->filterByTaggedItemId($sPageId);
     $oQuery->filterByModelName("Page");
     $oQuery->filterByTag($mTag);
     $oTagInstance = $oQuery->findOne();
     if ($oTagInstance) {
         $oTagInstance->delete();
     }
 }
Beispiel #11
0
function find_tags_by_keyword($keyword, $tag_type_value = false)
{
    # Find keyword
    $keyword = find_keyword($keyword);
    # Find tag type
    if ($tag_type_value) {
        $tag_type = find_tag_type($tag_type_value);
    }
    # Find tags
    $tags = TagQuery::create()->filterByKeyword($keyword);
    if ($tag_type) {
        $tags->filterByType($tag_type);
    }
    $tags->find();
    # Return tag
    return $tags;
}
Beispiel #12
0
 /**
  * Get the associated Tag object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Tag The associated Tag object.
  * @throws PropelException
  */
 public function getTag(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aTag === null && $this->tag_id !== null && $doQuery) {
         $this->aTag = TagQuery::create()->findPk($this->tag_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aTag->addTagInstances($this);
            */
     }
     return $this->aTag;
 }
Beispiel #13
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(TagPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = TagQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(TagPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.custom", array("role_key" => "tags")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Beispiel #14
0
<?php

require_once '../vendor/autoload.php';
require_once '../generated-conf/config.php';
$tag_object = TagQuery::create()->filterById(1)->findOne();
$tag_vote_object = new TagVote();
$tag_vote_object->setTag($tag_object)->save();
 public function getCriteria()
 {
     return TagQuery::create()->filterByTagged($this->oTagList->getTaggedModelName());
 }
Beispiel #16
0
 public function getHasTags()
 {
     return TagQuery::create()->filterByTagged($this)->count() > 0;
 }
Beispiel #17
0
 /**
  * Returns a new TagQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   TagQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return TagQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof TagQuery) {
         return $criteria;
     }
     $query = new TagQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
/**
* Returns the relevant tags for the current user
*
* @return array
*/
function get_relevant_tags($oUser, $sTag)
{
    $aTagList = isset($_SESSION['tagList']) ? $_SESSION['tagList'] : array();
    $tagTree = array();
    $documentList = '';
    // Get the previous tag info:
    // the list of documents that contain the tag to search within
    // the tags that have already been filtered so they aren't displayed again
    if (!empty($aTagList)) {
        $aPrevTag = end($aTagList);
        $sPrevTag = $aPrevTag['tag'];
        $documentList = $aPrevTag['docs'];
        $tagTree = $aPrevTag['tagTree'];
    }
    if (empty($sTag)) {
        // If there is no tag specified then get all tags.
        $aUserPermissions = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read');
        if (PEAR::isError($aUserPermissions)) {
            return array();
        }
        // ensure the user has read permission on the documents
        list($sWhere, $aParams, $sJoins) = $aUserPermissions;
        $sql = "SELECT TW.tag, count(*) as freq\n    \t\tFROM document_tags DT\n    \t\tINNER JOIN tag_words TW ON DT.tag_id=TW.id\n    \t\tWHERE DT.document_id in (SELECT D.id FROM documents D {$sJoins} WHERE {$sWhere} AND D.status_id = '1')\n    \t\tGROUP BY TW.tag";
        $tags = DBUtil::getResultArray(array($sql, $aParams));
    } else {
        // Create a new tag query to get the document id's associated with the tag
        $oQuery = new TagQuery($oUser, $sTag);
        $aOptions = array();
        $aOptions['select'] = 'DISTINCT DTS.document_id';
        $aQuery = $oQuery->getQuery($aOptions);
        $sInnerQuery = $aQuery[0];
        $aParams = $aQuery[1];
        $aDocIds = DBUtil::getResultArrayKey($aQuery, 'document_id');
        $sDocs = implode(',', $aDocIds);
        // Make sure user not opening a new window on tag cloud filters
        if (!$sDocs) {
            return array();
        }
        // Don't display tags that have already been selected.
        $tagTree[] = $sTag;
        $cnt = count($tagTree);
        $sIgnoreTags = '?';
        for ($i = 1; $i < $cnt; $i++) {
            $sIgnoreTags .= ',?';
        }
        // Get the tags within the documents that haven't been selected before
        $sQuery = "SELECT TW.tag, count(*) as freq\n        FROM document_tags DT INNER JOIN tag_words TW ON DT.tag_id=TW.id\n        WHERE DT.document_id in ({$sDocs}) AND TW.tag NOT IN ({$sIgnoreTags})\n        GROUP BY TW.tag";
        $tags = DBUtil::getResultArray(array($sQuery, $tagTree));
        if (PEAR::isError($tags)) {
            echo $tags->getMessage();
        }
        // Add new tag to the session
        if ($sPrevTag != $sTag) {
            $aTagList[] = array('tag' => $sTag, 'docs' => $sDocs, 'tagTree' => $tagTree);
            $_SESSION['tagList'] = $aTagList;
        }
    }
    $aTags = array();
    if ($tags) {
        foreach ($tags as $tag) {
            $word = $tag['tag'];
            $freq = $tag['freq'];
            $aTags[$word] = $freq;
        }
    }
    return $aTags;
}
 public function listTags()
 {
     return TagQuery::create()->find()->toArray();
 }
 /**
  * renderTagCloudWidget()
  *
  * description:
  * display tags with variable font-size, @see config.yml section journal tag_cloud [pixel_size_min, pixel_size_max]
  * @return Template object / null
  */
 private function renderTagCloudWidget()
 {
     // get all tags related to
     // • model JournalEntry
     // • active journal_enties with current journal_id
     $aIncludeJournalEntryIds = $this->createQuery()->filterByJournalId($this->aJournalIds)->select('Id')->find()->getData();
     $oTagQuery = TagQuery::create()->orderByName()->withTagInstanceCountFilteredByModel('JournalEntry', $aIncludeJournalEntryIds);
     $aTags = $oTagQuery->find()->toKeyValue('Name', 'TagInstanceCount');
     if (empty($aTags)) {
         return null;
     }
     // Configure display style of cloud
     $bUseSizes = false;
     $iMinPixelFontSize = null;
     $iMaxPixelFontSize = null;
     $aSizeParams = Settings::getSetting('journal', 'tag_cloud', null);
     if (isset($aSizeParams['pixel_size_min'])) {
         $iMinPixelFontSize = $aSizeParams['pixel_size_min'];
     }
     if (isset($aSizeParams['pixel_size_max'])) {
         $iMaxPixelFontSize = $aSizeParams['pixel_size_max'];
     }
     if ($iMinPixelFontSize !== null && $iMaxPixelFontSize !== null) {
         $bUseSizes = true;
     }
     // Calculate font sizes
     if ($bUseSizes) {
         $iMinCount = min($aTags);
         $iMaxCount = max($aTags);
         $iFactor = 1;
         if ($iMaxCount > $iMinCount) {
             $iFactor = $iMaxCount - $iMinCount;
         }
         $iPixelStep = ($iMaxPixelFontSize - $iMinPixelFontSize) / $iFactor;
     }
     // Render tags
     $oTemplate = $this->constructTemplate('widget_tag');
     if ($this->tagFilterIsActive()) {
         $sHref = LinkUtil::link($this->oNavigationItem->getLink(), null, array(self::RESET_TAGS => 'true'));
         $oTemplate->replaceIdentifier('reset_tags_href', $sHref, null, Template::NO_HTML_ESCAPE);
     }
     $oItemPrototype = $this->constructTemplate('widget_tag_item');
     foreach ($aTags as $sName => $iCount) {
         $oItemTemplate = clone $oItemPrototype;
         if ($bUseSizes) {
             $iFontSize = (int) ceil($iMinPixelFontSize + ($iCount - $iMinCount) * $iPixelStep);
             $oItemTemplate->replaceIdentifier('size_style', ' style="font-size:' . $iFontSize . 'px;line-height:' . ceil($iFontSize * 1.2) . 'px;"', null, Template::NO_HTML_ESCAPE);
         }
         if (is_array($this->aFilteredTags) && in_array($sName, $this->aFilteredTags)) {
             $oItemTemplate->replaceIdentifier('class_active', ' active');
             $oItemTemplate->replaceIdentifier('tag_link_title', TranslationPeer::getString('tag_link_title.remove'));
             $oItemTemplate->replaceIdentifier('tag_link', LinkUtil::link($this->oNavigationItem->getLink(), null, array(self::REMOVE_TAG => $sName)));
         } else {
             $oItemTemplate->replaceIdentifier('tag_link', LinkUtil::link($this->oNavigationItem->getLink(), null, array(self::ADD_TAG => $sName)));
             $oItemTemplate->replaceIdentifier('tag_link_title', TranslationPeer::getString('tag_link_title.add', null, null, array('tagname' => StringUtil::makeReadableName($sName)), true));
         }
         $oItemTemplate->replaceIdentifier('tag_name', ucfirst(TranslationPeer::getString('tag.' . $sName, null, $sName)));
         $oItemTemplate->replaceIdentifier('count_instances', $iCount);
         $oTemplate->replaceIdentifierMultiple('tag_item', $oItemTemplate);
     }
     return $oTemplate;
 }
 public function getTagName()
 {
     if ($iTagId = $this->oDelegateProxy->getListSettings()->getFilterColumnValue('has_tags')) {
         return TagQuery::create()->filterById($iTagId)->select('Name')->findOne();
     }
     return null;
 }
         <td><h3><?php echo __('Comments', null, 'sf_simple_blog') ?></h3></td>
       </tr>
       <tr>
         <td><?php echo sfSimpleBlogPostQuery::create()->count() ?> Posts</td>
         <td><?php echo $nbComments = sfNestedCommentQuery::create()->count() ?> Comments</td>
       </tr>
       <tr>
         <td><?php echo sfSimpleBlogPageQuery::create()->count() ?> Pages</td>
         <td><?php echo $nbApprovedComments = sfNestedCommentQuery::create()->approved()->count() ?> Approved</td>
       </tr>
       <tr>
         <td><?php echo sfSimpleBlogCategoryQuery::create()->count() ?> Categories</td>
         <td><?php echo $nbComments - $nbApprovedComments ?> Pending</td>
       </tr>
       <tr>
         <td><?php echo TagQuery::create()->count() ?> Tags</td>
       </tr>
     </tbody>
   </table>
 </div>
 <div class="box">
   <h2><?php echo __('Recent Comments', null, 'sf_simple_blog') ?></h2>
   <table>
     <tbody>
       <?php foreach ($recentComments as $i => $recentComment): ?>
         <tr>
           <td><?php echo $i+1 ?></td>
           <td>
             <h4><?php echo __('From ') ?><?php echo $recentComment->getAuthorName() ?><?php echo __(' on ') ?>"<?php echo $recentComment->getCommentableTitle() ?>"</h4>
             <?php $strippedComment = strip_tags($recentComment->getContent(ESC_RAW)) ?>
             <?php if (strlen($strippedComment) > 100): ?>