My Console Application Class Reference

TagsController

Package application.controllers.TagsController
Inheritance class TagsController » Controller » SBaseController » CController » CBaseController » CComponent
Views index, publish, publishmenu, publishmenuadmin, publishmenucreate, publishmenuupdate, publishmenuview, publishthemeadmin, tag, tagSContent, timemapUTag
Source Code app/controllers/TagsController.php
TagsController defines tags actions, communicates between models and views.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
action CAction the action currently being executed, null if no active action. CController
back Controller
cachingStack CStack stack of COutputCache objects CController
clips CMap Returns the list of clips. CController
defaultAction string the name of the default action. CController
id string ID of the controller CController
layout string the default layout for the controller view. Controller
module CWebModule the module that this controller belongs to. CController
pageTitle string the page title. CController
roots Controller
route string the route (module ID, controller ID and action ID) of the current request. CController
selectedTA Controller
tree Controller
uniqueId string the controller ID that is prefixed with the module ID (if any). CController
viewPath string Returns the directory containing view files for this controller. CController

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() CController
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
accessRules() Specifies the access control rules. TagsController
actionAdd() Adds tag to tree. TagsController
actionCreateRoot() Creates tags tree root under the project. See also components/multiTrees TagsController
actionDragRecord() Add record to tag after dragging TagsController
actionLoadTree() Loads tree for for a particular tag/category. TagsController
actionMove() Move tag in the tree. TagsController
actionPublish() Publish tag, changes publish attribute of the tag. TagsController
actionPublishmenu() Shows menus of the published category site TagsController
actionPublishmenuadmin() Manages menu pages TagsController
actionPublishmenucreate() Create menu/page for the published category site, redirected to menu admin page if successful TagsController
actionPublishmenudelete() Deletes a menu/page TagsController
actionPublishmenuupdate() Updates menu page TagsController
actionPublishmenuview() View a published menu TagsController
actionPublishthemeadmin() Manages published site themes, changes theme for the site. TagsController
actionReload() Reload tags tree for the project. TagsController
actionRemove() Remove tag tree or tag. TagsController
actionRemoveRecord() Removes record from tag TagsController
actionRename() Rename tag TagsController
actionSearchInTag() Searchs keyword from the search box on top of the tag page TagsController
actionTag() Shows records in a category/tag TagsController
actionTimemapUTag() display timemap under tag TagsController
actions() Returns a list of external action classes. CController
adjustWeightMove() Adjust postion when move under same parent TagsController
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
beginCache() Begins fragment caching. CBaseController
beginClip() Begins recording a clip. CBaseController
beginContent() Begins the rendering of content that is to be decorated by the specified view. CBaseController
beginWidget() Creates a widget and executes it. CBaseController
behaviors() Returns a list of behaviors that this controller should behave as. CController
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clearPageStates() Removes all page states. CController
createAbsoluteUrl() Creates an absolute URL for the specified action defined in this controller. CController
createAction() Creates the action instance based on the action name. CController
createUrl() Creates a relative URL for the specified action defined in this controller. CController
createWidget() Creates a widget and initializes it. CBaseController
deleteFParent() Deletes a node from parent. TagsController
deleteTree() Find descendant delete their tagsH, tags, tagsStatic TagsController
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
endCache() Ends fragment caching. CBaseController
endClip() Ends recording a clip. CBaseController
endContent() Ends the rendering of content. CBaseController
endWidget() Ends the execution of the named widget. CBaseController
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
filterAccessControl() The filter method for 'accessControl' filter. CController
filterAjaxOnly() The filter method for 'ajaxOnly' filter. CController
filterPostOnly() The filter method for 'postOnly' filter. CController
filters() TagsController
forward() Processes the request using another controller action. CController
getAction() Returns the action currently being executed, null if no active action. CController
getAncestors() Gets ancestor nodes of a particular category/tag/node TagsController
getCachingStack() Returns stack of COutputCache objects CController
getClips() Returns the list of clips. CController
getDescendants() Gets descendant nodes of a particular category/tag/node TagsController
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns ID of the controller CController
getLayoutFile() Looks for the layout view script based on the layout name. CController
getModule() Returns the module that this controller belongs to. It returns null if the controller does not belong to any module CController
getPageState() Returns a persistent page state value. CController
getPageTitle() Returns the page title. Defaults to the controller name and the action name. CController
getRoute() Returns the route (module ID, controller ID and action ID) of the current request. CController
getTree() Output tree htmldata of the decendant tree under tree $id TagsController
getUniqueId() Returns the controller ID that is prefixed with the module ID (if any). CController
getViewFile() Looks for the view file according to the given view name. CController
getViewPath() Returns the directory containing view files for this controller. CController
hasAccess() TagsController
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the controller. CController
isCachingStackEmpty() CController
loadMenuModel() Load a particular published menu. TagsController
loadentity() Returns the data model based on the primary key given in the GET variable. TagsController
loadtag() Returns the data model based on the primary key given in the GET variable. TagsController
missingAction() Handles the request whose action is not recognized. CController
paginate() Generates pagination information. CController
processDynamicOutput() Postprocesses the dynamic output. CController
processOutput() Postprocesses the output generated by render(). CController
raiseEvent() Raises an event. CComponent
recordCachingAction() Records a method call when an output cache is in effect. CController
redirect() Redirects the browser to the specified URL or route (controller/action). CController
refresh() Refreshes the current page. CController
relateNode() relateNode TagsController
render() Renders a view with a layout. CController
renderDynamic() Renders dynamic content returned by the specified callback. CController
renderDynamicInternal() This method is internally used. CController
renderFile() Renders a view file. CBaseController
renderInternal() Renders a view file. CBaseController
renderPartial() Renders a view. CController
renderPartialWithHisOwnClientScript() Controller
renderText() Renders a static text string. CController
resolveViewFile() Finds a view file based on its name. CController
run() Runs the named action. CController
runAction() Runs the action after passing through all filters. CController
runActionWithFilters() Runs an action with the specified filters. CController
setAction() Sets the action currently being executed. CController
setPageState() Saves a persistent page state value. CController
setPageTitle() Sets the page title. CController
widget() Creates a widget and executes it. CBaseController

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
afterAction() This method is invoked right after an action is executed. CController
allowedAccess() The auth items that access is always allowed. Configured in srbac module's SBaseController
beforeAction() Checks if srbac access is granted for the current user SBaseController
createActionFromMap() Creates the action instance based on the action map. CController
getTagRootParent() Get the category root of a particular category/tag/node TagsController
getTagRoots() Get all category roots of a project TagsController
loadPageStates() Loads page states from a hidden input. CController
onUnauthorizedAccess() SBaseController
replaceDynamicOutput() Replaces the dynamic content placeholders with actual content. CController
savePageStates() Saves page states as a base64 string. CController

Events

Hide inherited events

EventDescriptionDefined By
onUnauthorizedAccess SBaseController

Method Details

accessRules() method
public array accessRules()
{return} array access control rules
Source Code: app/controllers/TagsController.php#34 (show)
public function accessRules()
{
    
    
$user Yii::app()->user;
    if(
$user==null||$user->id==null)$this->redirect(array('site/redirectlogin'));
    
$hasPrjAdmin $this->hasAccess($userroleAccess::ADMIN);
    
$hasPrjWrite $this->hasAccess($userroleAccess::WRITE);
    
$hasPrjRead $this->hasAccess($userroleAccess::READ);
    return array(
        
        array(
'deny',  //allow admin role actions only for system admin and project admin
                
'actions'=>array('publish''publishMenu''publishMenuAdmin''publishMenuCreate''publishMenuDelete''publishMenuUpdate''publishMenuView''publishThemeAdmin'),
                
//check user has system admin or project admin access
                
'expression'=>'!Yii::app()->user->checkAccess("UserAdmin") && !'.($hasPrjAdmin),
        
        ),
        array(
'deny',  //allow write role actions only for system admin and project admin, write
                
'actions'=>array('add''createRoot''dragRecord''move''remove''removeRecord''rename'),
                
//check user has system admin or project admin access
                
'expression'=>'!Yii::app()->user->checkAccess("UserAdmin") && !'.($hasPrjWrite).' && !'.($hasPrjAdmin),
        
        ),
        array(
'deny',  //allow read role actions only for system admin and project admin, write, read
                
'actions'=>array('tag''loadTree','reload''timemapUTag''searchInTag'),
                
//check user has system admin or project admin access
                
'expression'=>'!Yii::app()->user->checkAccess("UserAdmin") && !'.($hasPrjRead).' && !'.($hasPrjWrite).' && !'.($hasPrjAdmin),
        
        )
    );
}

Specifies the access control rules. This method is used by the 'accessControl' filter.

actionAdd() method
public void actionAdd()
Source Code: app/controllers/TagsController.php#499 (show)
public function actionAdd(){
    
$newTagTitle $_POST['title'];
    
$parentId=$_POST['id'];
    
$projectId Yii::app()->getGlobalState('currentProject');
    if(
$projectId!=null){
        
$tag = new tags();
        
$tag->name $newTagTitle;
        
$tag->projectId $projectId;
        
$tag->isRoot 0;
        if(
$tag->save()){
            
$tagsH = new tagsHierarchy();
             
$tagsH->ancestorId $tag->id;
             
$tagsH->descendantId $tag->id;
             
$tagsH->depth 0;
             
$tagsH->weight 0;
             
$tagsH->save();
             
//add tag to parent
            
$this->relateNode($tag->id$parentId);
            print 
$tag->id;
        }
    }
//when $projectId is not available go to login (to do) there are other occurs of currentproject 
}

Adds tag to tree.

actionCreateRoot() method
public void actionCreateRoot()
Source Code: app/controllers/TagsController.php#208 (show)
public function actionCreateRoot(){
    
$projectId Yii::app()->getGlobalState('currentProject');
    if(
$projectId!=null){
        
$tag=new tags();
        if(isset(
$_POST['tags']))
        {
            
$tag->attributes=$_POST['tags'];
            
$projectId Yii::app()->getGlobalState('currentProject');
            if(
$projectId!=null){
                
$tag->projectId $projectId;
                
$tag->isRoot 1;
                if(
$tag->save()){
                    
$tagsH = new tagsHierarchy();
                     
$tagsH->ancestorId $tag->id;
                     
$tagsH->descendantId $tag->id;
                     
$tagsH->depth 0;
                     
$tagsH->weight 0;
                     
                     
$tagsH->save();
                    
//print('saved');
                    
$criteria=new CDbCriteria;
                     
$condition='t.isRoot=1 and t.projectId='.$projectId;             
                     
$criteria->condition $condition;
                     
$criteria->order "t.name";
                     
$roots tags::model()->findAll($criteria);
                     
$selectedId $_GET['selectedId'];
                    foreach(
$roots as $root){
                        print 
'<div class="tagview"  style="width:100%;height:100%" id="tagRoot_'.$root->id.'"></div>';
                        
                        print 
'<script>$(function () {
                    
                            $("#tagRoot_'
.$root->id.'").jstree({
                                //core : { "initially_open" : [ "root" ] },
                                json_data : {
                                    //"data" : [ { "data" : "A node", "metadata" : { id : "23" }, "children" : [ "Child 1", "A Child 2" ] } ],        
                                    "ajax" : { "url" : "index.php?r=tags/loadTree&id='
.$root->id.'&selectedId='.$selectedId.'" },
                                    "progressive_render" : true
                                },        
                                contextmenu: {
                                    items:customMenu
                                },
                                dnd : {
                                    "drag_finish" : function (data) {
                                        //alert(data.o.id+"_"+data.r.attr("id"));
                                        $.ajax({
                                            async : false,
                                            type: "POST",
                                            url:  "index.php?r=tags/dragRecord",
                                            data : { 
                                                "recordId" : data.o.id, 
                                                "tagId" : data.r.attr("id").replace("node_","")
                                            }, 
                                            error : function (r, rstatus) {
                                                if(rstatus!="success") {
                                                    alert(rstatus);
                                                }
                                            },
                                            success: function (id, rstatus) {
                                                if(id=="3"){
                                                    alert("one or more relationships already exist.");
                                                }else if(id=="2"){
                                                    alert("relationship already exists.");
                                                }else if(!(rstatus=="success"&&id=="1")) {
                                                    alert(rstatus);
                                                }
                                            }
                                        });
                                        if(document.getElementById("tagContent"))
                                            $("#tagContent").load("index.php?r=record/reloadTagcontent&recordId="+data.o.id);
                                    }
                                },
                                plugins : [ "themes","json_data","ui","crrm","dnd","search","types","contextmenu"  ]
                            })
                            
                                    .bind("create.jstree", onCreateNode)
                                    .bind("remove.jstree", onRemoveNode)
                                    .bind("rename.jstree", onRenameNode)
                                    .bind("drag_finish.jstree", onDragFinish)
                                    .bind("move_node.jstree", onMoveNode)
                                    .bind("select_node.jstree", onClickNode)
                                    .bind("open_node.jstree", onOpenNode);;
                    
                        });</script>'
;
                    
                    }
                
                }else{
                    
$errors $tag->getErrors();
                    foreach(
$errors as $e)
                        print(
$e[0]);
                }
            }
        }    
    }
}

Creates tags tree root under the project. See also components/multiTrees

actionDragRecord() method
public void actionDragRecord()
Source Code: app/controllers/TagsController.php#643 (show)
public function actionDragRecord(){
    
$recordId $_POST["recordId"];
    
$tagId $_POST["tagId"];
    
//add batch records in holding
    
if($recordId=='inhold'){
        
$existItem false;
        if(
$_SESSION['hold']!=null&&sizeof($_SESSION['hold'])>0){
            foreach (
$_SESSION['hold'] as $id){
                
$criteria=new CDbCriteria;
                
$condition='t.tagId='.$tagId.' and t.recordId='.$id;
                
$criteria->condition $condition;
                
$tagsS tagsStatic::model()->findAll($criteria);
                if(!(
sizeof($tagsS)>0)){
                    
$tagsStatic = new tagsStatic();
                    
$tagsStatic->recordId $id;
                    
$tagsStatic->tagId $tagId;
                    
$tagsStatic->save();
                }else{
                    
$existItem=true;
                }
            }
            if(
$existItem)
                print 
3;
        }
        
    }else{
//add single record
        
$criteria=new CDbCriteria;
        
$condition='t.tagId='.$tagId.' and t.recordId='.$recordId;             
         
$criteria->condition $condition;
         
$tagsS tagsStatic::model()->findAll($criteria);
         if(!(
sizeof($tagsS)>0)){        
            
$tagsStatic = new tagsStatic();
            
$tagsStatic->recordId $recordId;
            
$tagsStatic->tagId $tagId;
            if(
$tagsStatic->save()){
                print 
1;
            }
         }else{
             print 
2;
         }
    }
}

Add record to tag after dragging

actionLoadTree() method
public void actionLoadTree()
Source Code: app/controllers/TagsController.php#382 (show)
public function actionLoadTree(){
    
//print "<li id='0'><a href='#'>Root node</a><ul><li id='1'><a href='#'>Child node</a></li><li id='2'><a href='#'>Child node2</a></li></ul></li>";
    
$id$_GET['id']? $_GET['id']:1;
    
$selectedId $_GET['selectedId']? $_GET['selectedId']:0;
    
$tagAns $this->getAncestors($selectedId);
    
$criteria=new CDbCriteria;
     
$condition='t.id='.$id;             
     
$criteria->condition $condition;
     
$tags tags::model()->findAll($criteria);
     foreach(
$tags as $tag){
         
$childTree $this->getTree($tag->id$selectedId);
         
//print "<li id='".$tag->id."'><a href='#'>".$tag->name."</a>".$childTree."</li>";
         //print '[{"data" : "A node", 
        //        "metadata" : { "id" : "23" },
        //        "children" : [ "Child 1", "A Child 2" ]}]';
         
         
if($childTree!=""){
             
$results '[ {
                           "data": {
                             "title": "'
.$tag->name.'",
                             "attr": {"id":"node_'
.$tag->id.'", "href" : "#" }
                             
                           },'
;
             if(
$tag->id!=$selectedId)
             foreach(
$tagAns as $tagAn)
                 if(
$tag->id==$tagAn->ancestorId)
                     
$results .= '"state" : "open",';
             
$results .= '"attr": {"id":"node_'.$tag->id.'", "istree":"1"},
                         "children":[
                             '
.$childTree.'
                         ]
                     }
             ]'
;
             print 
$results;
         }else{
             
$results '[ {
                         "data": {
                             "title": "'
.$tag->name.'",
                             "attr": {"id":"node_'
.$tag->id.'", "href" : "#" }
                         },'
;
             if(
$tag->id!=$selectedId)
             foreach(
$tagAns as $tagAn)
                 if(
$tag->id==$tagAn->ancestorId)
                     
$results .= '"state" : "open",';
             
$results .= '"attr": {"id":"node_'.$tag->id.'", "istree":"0"}
                         
                     }
             ]'
;
             print 
$results;
         }
     }
}

Loads tree for for a particular tag/category.

actionMove() method
public void actionMove()
Source Code: app/controllers/TagsController.php#525 (show)
public function actionMove(){
    
$movedId $_POST['a'];
    
$newParentId $_POST['p'];
    
$oldParentId $_POST['o'];
    
$position $_POST['position'];
    
//if newP == oldP only ajust weight
    
if($newParentId==$oldParentId){
        
$this->adjustWeightMove($newParentId$movedId$position);
    }else{
        
$this->deleteFParent($movedId$oldParentId);
        
$this->relateNode($movedId$newParentId1true$position+1);
    }
    
//adjust weight
}

Move tag in the tree.

actionPublish() method
public void actionPublish()
Source Code: app/controllers/TagsController.php#737 (show)
public function actionPublish(){
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
        
$criteria=new CDbCriteria;
        
$condition='t.tagId='.$tagId;
        
$criteria->condition $condition;   
        
$publish publishTag::model()->find($criteria);
        if(
$publish==null||$publish->id==null){
            
$publish = new publishTag;
            
$publish->tagId $tagId;
            
$publish->published 0;
            
$publish->save();
        }
        if(isset(
$_POST['publishTag'])){
            
$publish->attributes $_POST['publishTag'];
            
$publish->homecontent $_POST['publishTag']['homecontent'];
            if(
$_POST['publishTag']['published']==null)
                 
$publish->published 0;
             else
                 
$publish->published $_POST['publishTag']['published'];
            
$publish->save();
        }
    }
    
$this->render('publish', array('publish'=>$publish'tag'=>$tag));
}

Publish tag, changes publish attribute of the tag.

actionPublishmenu() method
public void actionPublishmenu()
Source Code: app/controllers/TagsController.php#766 (show)
public function actionPublishmenu(){

    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
        
$criteria=new CDbCriteria;
        
$condition='tagId='.$tagId;
        
$criteria->condition $condition;   
        
$dataProvider = new CActiveDataProvider('menu', array(
            
'criteria'=>$criteria,
        ));
    }
    
$this->render('publishmenu', array('dataProvider'=>$dataProvider'tag'=>$tag));
}

Shows menus of the published category site

actionPublishmenuadmin() method
public void actionPublishmenuadmin()
Source Code: app/controllers/TagsController.php#817 (show)
public function actionPublishmenuadmin(){
    
$model=new menuTag();
    
$model->unsetAttributes();  // clear any default values
    
if(isset($_GET['menu']))
        
$model->attributes=$_GET['menu'];
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
    }
    
$model->tagId $tagId;
    
$this->render('publishmenuadmin',array(
        
'model'=>$model'tag'=>$tag
    
));
}

Manages menu pages

actionPublishmenucreate() method
public void actionPublishmenucreate()
Source Code: app/controllers/TagsController.php#783 (show)
public function actionPublishmenucreate(){
    
$model=new menuTag;
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
    
// Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

        
if(isset($_POST['menuTag']))
        {
            
$model->attributes=$_POST['menuTag'];
            if(
$model->save())
                
$this->redirect(array('publishmenuadmin','tagId'=>$tagId));
        }
    }
    
$this->render('publishmenucreate',array(
        
'model'=>$model'tagId'=>$tagId'tag'=>$tag
    
));
}

Create menu/page for the published category site, redirected to menu admin page if successful

actionPublishmenudelete() method
public void actionPublishmenudelete()
Source Code: app/controllers/TagsController.php#857 (show)
public function actionPublishmenudelete(){
    
$delMenu=$this->loadMenuModel();
    
$delMenu->delete();
    
$model=new menuTag();
    
$model->unsetAttributes();  // clear any default values
    
if(isset($_GET['menu']))
        
$model->attributes=$_GET['menu'];
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
    }
    
$model->tagId $tagId;
    
$this->render('publishmenuadmin',array(
        
'model'=>$model'tag'=>$tag
    
));
}

Deletes a menu/page

actionPublishmenuupdate() method
public void actionPublishmenuupdate()
Source Code: app/controllers/TagsController.php#834 (show)
public function actionPublishmenuupdate(){
    
$model=$this->loadMenuModel();
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
    }
    
// Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    
if(isset($_POST['menuTag']))
    {
        
$model->attributes=$_POST['menuTag'];
        if(
$model->save())
            
$this->redirect(array('publishmenuupdate','menuId'=>$model->id'tagId'=>$tag->id));
    }

    
$this->render('publishmenuupdate',array(
        
'model'=>$model'tagId'=>$tag->id'tag'=>$tag
    
));
}

Updates menu page

actionPublishmenuview() method
public void actionPublishmenuview()
Source Code: app/controllers/TagsController.php#805 (show)
public function actionPublishmenuview(){
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
    }
    
$this->render('publishmenuview',array(
        
'model'=>$this->loadMenuModel(),'tag'=>$tag
    
));
}

View a published menu

actionPublishthemeadmin() method
public void actionPublishthemeadmin()
Source Code: app/controllers/TagsController.php#876 (show)
public function actionPublishthemeadmin(){
    
$tagId $_GET['tagId'];    
    if(
$tagId!=null){
        
$tag tags::model()->findbyPK($tagId);    
        
$criteria=new CDbCriteria;
        
$condition='t.tagId='.$tagId;
        
$criteria->condition $condition;   
        
$publish publishTag::model()->find($criteria);
        if(
$publish==null||$publish->id==null){
            
$publish = new publishTag;
            
$publish->tagId $tagId;
            
$publish->published 0;
            
$publish->save();
        }
        if(isset(
$_POST['publishTag'])){
            
$publish->attributes $_POST['publishTag'];
            if(
$_POST['publishTag']['published']==null)
                 
$publish->published 0;
             else
                 
$publish->published $_POST['publishTag']['published'];
            
$publish->save();
        }
    }
    
$this->render('publishthemeadmin', array('publish'=>$publish'tag'=>$tag));
}

Manages published site themes, changes theme for the site.

actionReload() method
public void actionReload()
Source Code: app/controllers/TagsController.php#308 (show)
public function actionReload(){
    
$projectId Yii::app()->getGlobalState('currentProject');
    if(
$projectId!=null){
        
$criteria=new CDbCriteria;
         
$condition='t.isRoot=1 and t.projectId='.$projectId;             
         
$criteria->condition $condition;
         
$criteria->order "t.name";
         
$roots tags::model()->findAll($criteria);
         
$selectedId $_GET['selectedId'];
        foreach(
$roots as $root){
            print 
'<div class="tagview"  style="width:100%;height:100%" id="tagRoot_'.$root->id.'"></div>';
            
            print 
'<script>$(function () {
        
                $("#tagRoot_'
.$root->id.'").jstree({
                    //core : { "initially_open" : [ "root" ] },
                    json_data : {
                        //"data" : [ { "data" : "A node", "metadata" : { id : "23" }, "children" : [ "Child 1", "A Child 2" ] } ],        
                        "ajax" : { "url" : "index.php?r=tags/loadTree&id='
.$root->id.'&selectedId='.$selectedId.'" },
                        "progressive_render" : true
                    },        
                    contextmenu: {
                        items:customMenu
                    },
                    dnd : {
                        "drag_finish" : function (data) {
                            //alert(data.o.id+"_"+data.r.attr("id"));
                            $.ajax({
                                async : false,
                                type: "POST",
                                url:  "index.php?r=tags/dragRecord",
                                data : { 
                                    "recordId" : data.o.id, 
                                    "tagId" : data.r.attr("id")
                                }, 
                                error : function (r, rstatus) {
                                    if(rstatus!="success") {
                                        alert(rstatus);
                                    }
                                },
                                success: function (id, rstatus) {
                                    if(id=="3"){
                                        alert("one or more relationships already exist.");
                                    }else if(id=="2"){
                                        alert("relationship already exists.");
                                    }else if(!(rstatus=="success"&&id=="1")) {
                                        alert(rstatus);
                                    }
                                }
                            });
                            if(document.getElementById("tagContent"))
                                $("#tagContent").load("index.php?r=record/reloadTagcontent&recordId="+data.o.id);
                        }
                    },
                    plugins : [ "themes","json_data","ui","crrm","dnd","search","types","contextmenu"  ]
                })
                
                        .bind("create.jstree", onCreateNode)
                        .bind("remove.jstree", onRemoveNode)
                        .bind("rename.jstree", onRenameNode)
                        .bind("drag_finish.jstree", onDragFinish)
                        .bind("move_node.jstree", onMoveNode)
                        .bind("select_node.jstree", onClickNode)
                        .bind("open_node.jstree", onOpenNode);;
        
            });</script>'
;
        }
    }                
}

Reload tags tree for the project.

actionRemove() method
public void actionRemove()
Source Code: app/controllers/TagsController.php#577 (show)
public function actionRemove(){
    
$deleteId $_POST["id"];
    
//$parentId = $_POST["p"];
    
$isTree $_POST["istree"];
    
//adjust weight
    
$criteria=new CDbCriteria;
    
$condition='t.depth=1 and t.descendantId='.$deleteId;
    
$criteria->condition $condition;
    
$tagH tagsHierarchy::model()->find($criteria);
    if(
$tagH!=null){
        
$criteria=new CDbCriteria;
        
$condition='t.ancestorId='.$tagH->ancestorId.' and t.depth=1 and t.descendantId!='.$deleteId;
        
$criteria->condition $condition;
        
$tagHs tagsHierarchy::model()->findAll($criteria);
        foreach(
$tagHs as $tagHD){
            if(
$tagHD->weight>$tagH->weight){
                
$tagHD->weight $tagHD->weight-1;
                
$tagHD->save();
            }
        }
    }
    
//delete
    
if($isTree){
        
        
//find descendant delete their tagsH, tags, tagsStatic
        
$this->deleteTree($deleteId);
        
    }else{
        
$criteria=new CDbCriteria;
         
$condition='t.ancestorId='.$deleteId.' or t.descendantId='.$deleteId;             
         
$criteria->condition $condition;
         
$tagHs tagsHierarchy::model()->findAll($criteria);
         foreach(
$tagHs as $tagH){
             
$tagH->delete();
         }
    }
//delete tagsStatic                 
     
$criteria=new CDbCriteria;
    
$condition='t.tagId='.$deleteId;             
     
$criteria->condition $condition;
     
$tagsS tagsStatic::model()->findAll($criteria);
     if(
$tagsS!=null)
         foreach(
$tagsS as $tags){
             
$tags->delete();
         }
    
$tag tags::model()->findbyPk($deleteId);
    if(
$tag!=null)
        
$tag->delete();
    print 
1;
}

Remove tag tree or tag.

actionRemoveRecord() method
public void actionRemoveRecord()
Source Code: app/controllers/TagsController.php#689 (show)
public function actionRemoveRecord(){
    
$recordId $_GET["recordId"];
    
$tagId $_GET["tagId"];
    
$descendants $this->getDescendants($tagId);
    
$desBracket "(";
    foreach(
$descendants as $des){
        if(
$desBracket!="("){
            
$desBracket.=",";
        }
        
$desBracket.=$des->descendantId;
    }
    
$desBracket .= ")";
      
    
$criteria=new CDbCriteria;
    
$condition='t.tagId IN '.$desBracket.' and t.recordId='.$recordId;             
     
$criteria->condition $condition;
     
$tagsS tagsStatic::model()->findAll($criteria);
     foreach(
$tagsS as $tagS){
         
$tagS->delete();
     }
     
//reload tree after remove
    
$tag tags::model()->findbyPk($tagId);
    
$descendants $this->getDescendants($tagId);
    
$desBracket "(";
    foreach(
$descendants as $des){
        if(
$desBracket!="("){
            
$desBracket.=",";
        }
        
$desBracket.=$des->descendantId;
    }
    
$desBracket .= ")";
    
$criteria=new CDbCriteria;
     
$condition='tagsStatic.tagId IN '.$desBracket;     
     
$criteria->condition $condition;
     
$criteria->order 'tagsStatic.id';
     
$criteria->select "distinct entity.*";
    
$staticRecords entity::model()->with('tagsStatic')->together()->findAll($criteria);
    
$pages=new CPagination(entity::model()->with('tagsStatic')->together()->count($criteria));
    
$pages->pageSize=self::PAGE_SIZE;
    
$pages->applyLimit($criteria);
    
    
$this->renderPartialWithHisOwnClientScript('tagSContent', array('tag'=>$tag'staticRecords'=>$staticRecords'pages'=>$pages),false,true);
     
//print $this->getTagSContent($tagId);
}

Removes record from tag

actionRename() method
public void actionRename()
Source Code: app/controllers/TagsController.php#631 (show)
public function actionRename(){
    
$renameId $_POST["id"];
    
$newName $_POST["newname"];
    
$tag tags::model()->findbyPk($renameId);
    
$tag->name $newName;
    if(
$tag->save()){
        print 
1;
    }
}

Rename tag

actionSearchInTag() method
public void actionSearchInTag()
Source Code: app/controllers/TagsController.php#117 (show)
public function actionSearchInTag(){
    
$tagId $_GET['id'];
    
//get ready to envoke searchTagIn function in entity 
    
$searchmodel=new entity('searchTagIn');
    
$searchmodel->unsetAttributes();  // clear any default values
    
if(isset($_GET['entity']))
        
$searchmodel->attributes=$_GET['entity'];
    
$standard 1001;
    
$entityType 2001;
    
    
$form = new SearchForm();
    if(isset(
$_GET['SearchForm'])){
        
$form->attributes=$_GET['SearchForm'];
    
        if(
$form->validate()){
            
$searchmodel->keyword $form->keyword;
        }else{
            exit(
0);
        }
    }
    
$sort $_GET['searchInShow_sort'];
    if(
$sort==null||$sort==""){
        
$sort="id";
    }
    
//envoke searchTagIn function in entity
    
$dataProvider $searchmodel->searchTagIn($tagId,$standard,$entityType,$sort);
    
//get tag data
    
$tag tags::model()->findbyPk($tagId);
    if(
$tag!=null){
        
$tagRoot $this->getTagRootParent($tagId);
        if(
tagRoot!=null)$rootId $tagRoot->id;
        
$selectedTA = array($rootId$tagId);
    
        
$rootParent=$tagRoot;
    }
    
$projectId Yii::app()->getGlobalState('currentProject');
    
$currentProject entity::model()->findbyPk($projectId);
    
$roots $this->getTagRoots($projectId);
    
//render tag page with search results
    
$this->render('tag', array('keyword'=>$searchmodel->keyword'rootParent'=>$rootParent'tag'=>$tag'staticRecords'=>$dataProvider->data'pages'=>$dataProvider->pagination'currentProject'=>$currentProject'roots'=>$roots'selectedTA'=>$selectedTA));
    

}

Searchs keyword from the search box on top of the tag page

actionTag() method
public void actionTag()
Source Code: app/controllers/TagsController.php#67 (show)
public function actionTag(){
    
    if(
$_GET['id']){
        
$tagId $_GET['id'];
        
$tag tags::model()->findbyPk($tagId);
        if(
$tag!=null){
            
//get root of the category
            
$tagRoot $this->getTagRootParent($tagId);
            if(
tagRoot!=null)$rootId $tagRoot->id;
            
$selectedTA = array($rootId$tagId);
            
            
$descendants $this->getDescendants($tagId);
            
$desBracket "(";
            foreach(
$descendants as $des){
                if(
$desBracket!="("){
                    
$desBracket.=",";
                }
                
$desBracket.=$des->descendantId;
            }
            
$desBracket .= ")";
            
$criteria=new CDbCriteria;
             
$condition='tagsStatic.tagId IN '.$desBracket;     
             
$criteria->condition $condition;
             
$criteria->order 'tagsStatic.id';
             
$criteria->select "t.*";
             
$criteria->distinct true;
             
$criteria->join "LEFT OUTER JOIN tagsStatic tagsStatic ON (tagsStatic.recordId=t.id)";
             
//$criteria->with = array('tagsStatic'=>array('select'=>array('id', 'tagId', 'recordId')));
                         
            //$pages=new CPagination(entity::model()->with('tagsStatic')->together()->count($criteria));
            
$pages=new CPagination(entity::model()->count($criteria));
            
$pages->pageSize=self::PAGE_SIZE;
            
$pages->applyLimit($criteria);
            
            
//$staticRecords = entity::model()->with('tagsStatic')->together()->findAll($criteria);
            //get all records of the category and its subcategories
            
$staticRecords entity::model()->findAll($criteria);
            
            
$rootParent=$this->getTagRootParent($tagId);
        }
    }
    
$projectId Yii::app()->getGlobalState('currentProject');
    
$currentProject entity::model()->findbyPk($projectId);
    
$roots $this->getTagRoots($projectId);
    
$this->render('tag', array('rootParent'=>$rootParent'tag'=>$tag'staticRecords'=>$staticRecords'pages'=>$pages'currentProject'=>$currentProject'roots'=>$roots'selectedTA'=>$selectedTA));

}

Shows records in a category/tag

actionTimemapUTag() method
public void actionTimemapUTag()
Source Code: app/controllers/TagsController.php#176 (show)
public function actionTimemapUTag(){
    
$tag tags::model()->findbyPK($_GET['tagId']);
    
    
$descendants $this->getDescendants($tag->id);
    
$desBracket "(";
    foreach(
$descendants as $des){
        if(
$desBracket!="("){
            
$desBracket.=",";
        }
        
$desBracket.=$des->descendantId;
    }
    
$desBracket .= ")";
    
    
$criteria=new CDbCriteria;
     
$condition='tagsStatic.tagId IN '.$desBracket;
     
$criteria->condition $condition;
     
$criteria->order 'tagsStatic.id';
     
$criteria->select "distinct entity.*";
     
$criteria->distinct true;
    
$staticRecords entity::model()->with('tagsStatic','entityType')->together()->findAll($criteria);
    
$pages=new CPagination(entity::model()->with('tagsStatic','entityType')->together()->count($criteria));
    
$pages->pageSize=self::PAGE_SIZE;
    
$pages->applyLimit($criteria);
    
$currentProject entity::model()->findbyPK(Yii::app()->getGlobalState('currentProject'));
    
$this->render('timemapUTag',array('tag'=>$tag,'currentProject'=>$currentProject,'recordsmodel'=>$staticRecords'pages'=>$pages));

    
}

display timemap under tag

adjustWeightMove() method
public void adjustWeightMove($parentId, $movedId, $position)
$parentId
$movedId
$position
Source Code: app/controllers/TagsController.php#542 (show)
public function adjustWeightMove($parentId$movedId$position){
    
$criteria=new CDbCriteria;
    
$condition='t.ancestorId='.$parentId.' and t.descendantId='.$movedId.' and t.depth=1';
    
$criteria->condition $condition;
    
$tagH tagsHierarchy::model()->find($criteria);
    
$orgPosition $tagH->weight;
    
$newPosition $position +1;
    
    
    
$criteria=new CDbCriteria;
    
$condition='t.ancestorId='.$parentId.' and t.depth=1 and t.descendantId!='.$movedId;
    
$criteria->condition $condition;
    
$tagHs tagsHierarchy::model()->findAll($criteria);
    foreach(
$tagHs as $tagHD){
        if(
$newPosition<$orgPosition){//moving up
            
$tagH->weight $newPosition;
            
$tagH->save();
            if((
$tagHD->weight>=$newPosition) && ($tagHD->weight<$orgPosition)){
                
$tagHD->weight $tagHD->weight+1;
                
$tagHD->save();
            }
        }else if(
$newPosition>$orgPosition){//moving down
            
$tagH->weight $newPosition-1;
            
$tagH->save();
            if((
$tagHD->weight>$orgPosition) && ($tagHD->weight<$newPosition)){
                
$tagHD->weight $tagHD->weight-1;
                
$tagHD->save();
            }
        }
    }
    
}

Adjust postion when move under same parent

deleteFParent() method
public void deleteFParent(integer $id, integer $parentId)
$id integer id of the node to be deleted
$parentId integer parent id of the node
Source Code: app/controllers/TagsController.php#1049 (show)
public function deleteFParent($id$parentId){
        
//adjust weight
        
$criteria=new CDbCriteria;
        
$condition='t.ancestorId='.$parentId.' and t.depth=1 and t.descendantId!='.$id;
        
$criteria->condition $condition;
        
$tagH tagsHierarchy::model()->find($criteria);
        
        
$criteria=new CDbCriteria;
        
$condition='t.ancestorId='.$parentId.' and t.depth=1 and t.descendantId!='.$id;
        
$criteria->condition $condition;
        
$tagHs tagsHierarchy::model()->findAll($criteria);
        foreach(
$tagHs as $tagHD){                
            if(
$tagHD->weight>$tagH->weight){
                
$tagHD->weight $tagHD->weight-1;
                
$tagHD->save();
            }                
        }
        
//delete 
        
$descendants $this->getDescendants($id);
        foreach(
$descendants as $des){
            
$criteria=new CDbCriteria;
             
$condition='t.ancestorId='.$parentId.' and t.descendantId='.$des->descendantId;             
             
$criteria->condition $condition;
             
$tagHs tagsHierarchy::model()->findAll($criteria);
             foreach(
$tagHs as $tagH){
                 
$tagH->delete();
             }
        }
        
}

Deletes a node from parent.

deleteTree() method
public void deleteTree(integer $deleteId)
$deleteId integer id of tag to be deleted
Source Code: app/controllers/TagsController.php#1143 (show)
public function deleteTree($deleteId){

    
$criteria=new CDbCriteria;
    
$condition='t.ancestorId='.$deleteId;
    
$criteria->condition $condition;
    
$tagHs tagsHierarchy::model()->findAll($criteria);
    foreach(
$tagHs as $tagH){
        
//delete $tagH->descendantId
        
if($tagH->descendantId!=$deleteId)
            
$this->deleteTree($tagH->descendantId);
        
//delete tagsStatic
        
$criteria=new CDbCriteria;
        
$condition='t.tagId='.$tagH->descendantId;
        
$criteria->condition $condition;
        
$tagsS tagsStatic::model()->findAll($criteria);
        if(
$tagsS!=null)
            foreach(
$tagsS as $tags){
            
$tags->delete();
        }
        
//delete descendant tags
        
$tag tags::model()->findbyPk($tagH->descendantId);
        if(
$tag!=null){
            
$tag->delete();

        }
        
//delete decendant related tagH
        
$criteria=new CDbCriteria;
        
$condition='t.ancestorId='.$tagH->descendantId.' or t.descendantId='.$tagH->descendantId;
        
$criteria->condition $condition;
        
$tagHs tagsHierarchy::model()->findAll($criteria);
        foreach(
$tagHs as $tagH){
            
$tagH->delete();
        }
    }
}

Find descendant delete their tagsH, tags, tagsStatic

filters() method
public array filters()
{return} array action filters
Source Code: app/controllers/TagsController.php#22 (show)
public function filters()
{
    return array(
        
'accessControl'// perform access control for CRUD operations
    
);
}

getAncestors() method
public void getAncestors(integer $id)
$id integer node id
Source Code: app/controllers/TagsController.php#1095 (show)
public function getAncestors($id){
    if(
$id!=null){
        
$criteria=new CDbCriteria;
         
$condition='t.descendantId='.$id;         
         
$criteria->order"t.depth, t.weight";    
         
$criteria->condition $condition;
         
$tagHs tagsHierarchy::model()->findAll($criteria);
         return 
$tagHs;
    }else return array();
}

Gets ancestor nodes of a particular category/tag/node

getDescendants() method
public void getDescendants(integer $id)
$id integer node id
Source Code: app/controllers/TagsController.php#1083 (show)
public function getDescendants($id){
    
$criteria=new CDbCriteria;
     
$condition='t.ancestorId='.$id;         
     
$criteria->order"t.depth, t.weight";    
     
$criteria->condition $condition;
     
$tagHs tagsHierarchy::model()->findAll($criteria);
     return 
$tagHs;
}

Gets descendant nodes of a particular category/tag/node

getTagRootParent() method
protected void getTagRootParent(integer $tagId)
$tagId integer
Source Code: app/controllers/TagsController.php#1122 (show)
protected function getTagRootParent($tagId){
    
$criteria=new CDbCriteria;
    
$condition='t.descendantId='.$tagId;
    
$criteria->order 't.depth DESC';             
     
$criteria->condition $condition;
     
$tagHs tagsHierarchy::model()->findAll($criteria);
     
$rootId;
     foreach(
$tagHs as $tagH){
         
$rootId $tagH->ancestorId;
         break;
     }
     if(
$rootId!=null){
         
$rootP tags::model()->findbyPk($rootId);
         return 
$rootP;
     }else     
         return 
null;
}

Get the category root of a particular category/tag/node

getTagRoots() method
protected void getTagRoots(integer $projectId)
$projectId integer
Source Code: app/controllers/TagsController.php#1109 (show)
protected function getTagRoots($projectId){
    
$criteria=new CDbCriteria;
     
$condition='t.isRoot=1 and t.projectId='.$projectId;             
     
$criteria->condition $condition;
     
$criteria->order "t.name";
     
$roots tags::model()->findAll($criteria);
    return 
$roots;
    
}

Get all category roots of a project

getTree() method
public void getTree($id $id, $selectedId $selectedId)
$id $id a tag id
$selectedId $selectedId a selected tag under the tree
Source Code: app/controllers/TagsController.php#440 (show)
public function getTree($id$selectedId){

    
$tagAns $this->getAncestors($selectedId);
    
$criteria=new CDbCriteria;
     
$condition='t.ancestorId='.$id.' and t.depth=1';         
     
$criteria->condition $condition;
     
$criteria->order 't.weight';
     
$tags tagsHierarchy::model()->with('descendantTag')->together()->findAll($criteria);
     
$tree "";
     if(
sizeof($tags)>0){
         
//$tree = $tree.'<ul>';
         
foreach($tags as $tag){
             
$dTag $tag->descendantTag;
             if(
$dTag!=null&&$dTag->id!=null){
                 
$childTree $this->getTree($dTag->id$selectedId);
                 if(
$tree!=""){
                     
$tree $tree.",";
                 }
                 if(
$childTree!=""){
                     
//$tree = $tree."<li id='".$dTag->id."' istree='1'><a href='#'>".$dTag->name."</a>".$childTree."</li>";
                     
$tree $tree.'{
                                 "data": {
                                     "title": "'
.$dTag->name.'",
                                     "attr": {"id":"node_'
.$dTag->id.'", "href" : "#", "istree":"1" }
                                 },'
;
                     if(
$dTag->id!=$selectedId)
                     foreach(
$tagAns as $tagAn)
                         if(
$dTag->id==$tagAn->ancestorId)
                             
$tree $tree.'"state" : "open",';
                     
$tree $tree.'"attr": {"id":"node_'.$dTag->id.'", "istree":"1"},
                                 "children":[
                                     '
.$childTree.'
                                 ]
                     }'
;
                 }else{     
                     
//$tree = $tree."<li id='".$dTag->id."' istree='0'><a href='#'>".$dTag->name."</a></li>";
                     
$tree $tree.'{
                                 "data": {
                                     "title": "'
.$dTag->name.'",
                                     "attr": {"id":"node_'
.$dTag->id.'", "href" : "#", "istree":"0" }
                                 },'
;
                     if(
$dTag->id!=$selectedId)
                     foreach(
$tagAns as $tagAn)
                         if(
$dTag->id==$tagAn->ancestorId)
                             
$tree $tree.'"state" : "open",';
                     
$tree $tree.'"attr": {"id":"node_'.$dTag->id.'", "istree":"1"}
                     }'
;
                 }
             }
         }
         
//$tree = $tree.'</ul>';
     
}
     return 
$tree;
}

Output tree htmldata of the decendant tree under tree $id

hasAccess() method
public void hasAccess(unknown_type $user, unknown_type $access)
$user unknown_type
$access unknown_type
Source Code: app/controllers/TagsController.php#1183 (show)
public function hasAccess($user$access){
    
$prjId Yii::app()->getGlobalState('currentProject');
    if(isset(
$_GET['prjId'])){
        
$prjId $_GET['prjId'];
        
Yii::app()->setGlobalState('currentProject'$prjId);
    }else{
        if(isset(
$_GET['tagId'])||isset($_POST['tagId'])){
            
$tagId = ($_GET['tagId']!=null) ? $_GET['tagId'] : $_POST['tagId'];
            
$model $this->loadtag($tagId);
            
$prjId $model->projectId;
            
Yii::app()->setGlobalState('currentProject'$prjId);                
        }                    
    }
    
$hasAccess 0;
    if(
$prjId!=null){
        
$criteria=new CDbCriteria;
        
$condition='t.entityId='.$prjId.' and userRole.userId='.$user->id;
        
$criteria->condition $condition;
        
$roles=role::model()->with('userRole')->findAll($criteria);
        if(
$roles!=null)
            foreach(
$roles as $role){
                
$roleAccesses $role->roleAccess;
                foreach(
$roleAccesses as $roleAccess){
                    if(
$roleAccess->access == $access){
                        
$hasAccess 1;
                    }
    
                }
            }
    }
    return 
$hasAccess;
}

loadMenuModel() method
public void loadMenuModel()
Source Code: app/controllers/TagsController.php#905 (show)
public function loadMenuModel()
{        
    if(isset(
$_GET['menuId']))
        
$menumodel=menuTag::model()->findbyPk($_GET['menuId']);
    if(
$menumodel===null)
        throw new 
CHttpException(404,'The requested page does not exist.');

    return 
$menumodel;
}

Load a particular published menu.

loadentity() method
public void loadentity(integer $id=NULL)
$id integer the primary key value. Defaults to null, meaning using the 'id' GET variable
Source Code: app/controllers/TagsController.php#919 (show)
public function loadentity($id=null)
{
    if(
$this->_model===null)
    {
        if(
$id!==null || isset($_GET['id'])){
            
$id = ($id!=null) ? $id $_GET['id'];
            
$this->_model=entity::model()->findbyPk($id);

        }if(
$this->_model===null)
            throw new 
CHttpException(404,'The requested page does not exist.');
    }
    return 
$this->_model;
}

Returns the data model based on the primary key given in the GET variable. If the data model is not found, an HTTP exception will be raised.

loadtag() method
public void loadtag(integer $id=NULL)
$id integer the primary key value. Defaults to null, meaning using the 'id' GET variable
Source Code: app/controllers/TagsController.php#937 (show)
public function loadtag($id=null)
{
    if(
$this->_tagmodel===null)
    {
        if(
$id!==null || isset($_GET['id'])){
            
$id = ($id!=null) ? $id $_GET['id'];
            
$this->_tagmodel=tags::model()->findbyPk($id);

        }if(
$this->_tagmodel===null)
            throw new 
CHttpException(404,'The requested page does not exist.');
    }
    return 
$this->_tagmodel;
}

Returns the data model based on the primary key given in the GET variable. If the data model is not found, an HTTP exception will be raised.

relateNode() method
public void relateNode(integer $insertId, integer $parentId, $add=1, $replace=true, $position=0)
$insertId integer
$parentId integer
$add
$replace
$position
Source Code: app/controllers/TagsController.php#973 (show)
public function relateNode($insertId$parentId$add=1$replace=true$position=0){
    
$criteria=new CDbCriteria;
     
$condition='t.ancestorId='.$parentId.' and t.depth=1';             
     
$criteria->condition $condition;
     
$getWeightQ=tagsHierarchy::model()->findAll($criteria);
     if(
$position){
         
$weight=$position;
         
//adjust weight             
         
$criteria=new CDbCriteria;
         
$condition='t.ancestorId='.$parentId.' and t.depth=1 and t.descendantId!='.$insertId;
         
$criteria->condition $condition;
         
$tagHs tagsHierarchy::model()->findAll($criteria);
         foreach(
$tagHs as $tagHD){
             if(
$tagHD->weight>=$position){
                 
$tagHD->weight $tagHD->weight+1;
                 
$tagHD->save();
             }
         }
         
     }else
         
$weight sizeof($getWeightQ)+$add;
     
     
$criteria=new CDbCriteria;
     
$condition='t.descendantId='.$parentId;             
     
$criteria->condition $condition;
     
$getAncestors tagsHierarchy::model()->findAll($criteria);
     
     
/*$tagsH = new tagsHierarchy();
     $tagsH->ancestorId = $insertId;
     $tagsH->descendantId = $insertId;
     $tagsH->depth = 0;
     $tagsH->weight = 0;
     $tagsH->save();*/
     
$descendants $this->getDescendants($insertId);
     
     foreach(
$getAncestors as $ancestor){
         foreach(
$descendants as $des){
             
$criteria=new CDbCriteria;
             
$condition='t.ancestorId='.$ancestor->ancestorId.' and t.descendantId='.$des->descendantId;
             
$criteria->condition $condition;
             
$getExistingThs tagsHierarchy::model()->findAll($criteria);
             
//equivalent to sql replace into delete existing primary keys (ancestorId, descendantId) row and insert new row or insert new row only when there are no existing row
             
if(sizeof($getExistingThs)>0&&$replace){
                 foreach(
$getExistingThs as $eThs){
                     
$eThs->depth $ancestor->depth+$add+$des->depth;
                     
/*if($des->descendantId==$insertId)
                         $eThs->weight = $weight+$add;
                     else     
                         $eThs->weight = $des->depth;*/
                     
$eThs->weight $weight;
                     
$eThs->save();
                     
                     
                 }
             }else{                 
                 
$tagsH = new tagsHierarchy();
                 
$tagsH->ancestorId $ancestor->ancestorId;
                 
$tagsH->descendantId $des->descendantId;
                 
$tagsH->depth $ancestor->depth+$add+$des->depth;
                 
/*if($des->descendantId==$insertId)
                     $tagsH->weight = $weight+$add;
                 else 
                     $tagsH->weight = $des->weight;*/
                 
$tagsH->weight $weight;
                 
$tagsH->save();
                 
             }
         }
     }
}

relateNode

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.