[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> Tag.php (source)

   1  <?php
   2  /*+***********************************************************************************

   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0

   4   * ("License"); You may not use this file except in compliance with the License

   5   * The Original Code is:  vtiger CRM Open Source

   6   * The Initial Developer of the Original Code is vtiger.

   7   * Portions created by vtiger are Copyright (C) vtiger.

   8   * All Rights Reserved.

   9   *************************************************************************************/
  10  vimport('~~/libraries/freetag/freetag.class.php');
  11  
  12  class Vtiger_Tag_Model extends Vtiger_Base_Model {
  13  
  14      private $_freetag = false;
  15  
  16      static $TAG_FETCH_LIMIT = 100;
  17  
  18  	function __construct() {
  19          $this->_freetag = new freetag();
  20      }
  21  
  22      /**

  23       * Function saves a tag to database

  24       */
  25  	public function save() {
  26          $this->_freetag->tag_object($this->get('userid'), $this->get('record'), $this->get('tagname'), $this->get('module'));
  27      }
  28  
  29      /**

  30       * Function deletes a tag from database

  31       */
  32  	public function delete() {
  33          $db = PearDatabase::getInstance();
  34          $db->pquery('DELETE FROM vtiger_freetagged_objects WHERE tag_id = ? AND object_id = ?',
  35                  array($this->get('tag_id'), $this->get('record')));
  36      }
  37  
  38      /**

  39       * Function returns the tags

  40       * @param type $userId

  41       * @param type $module

  42       * @param type $record

  43       * @return type

  44       */
  45  	public static function getAll($userId = NULL, $module = "", $record = NULL) {
  46          $tag = new self();
  47          return $tag->_freetag->get_tag_cloud_tags(self::$TAG_FETCH_LIMIT, $userId, $module, $record);
  48      }
  49      
  50  	public static function getTaggedRecords($tagId) {
  51          $recordModels = array();
  52          if(!empty($tagId)) {
  53              $db = PearDatabase::getInstance();
  54              $result = $db->pquery("SELECT vtiger_crmentity.* FROM vtiger_freetags 
  55                  INNER JOIN vtiger_freetagged_objects ON vtiger_freetags.id = vtiger_freetagged_objects.tag_id 
  56                  INNER JOIN vtiger_crmentity ON vtiger_freetagged_objects.object_id=vtiger_crmentity.crmid 
  57                      AND vtiger_crmentity.deleted=0 
  58                  WHERE tag_id = ?", array($tagId));
  59              $rows = $db->num_rows($result);
  60              for($i=0; $i<$rows; $i++) {
  61                  $row = $db->query_result_rowdata($result, $i);
  62                  $recordModel = Vtiger_Record_Model::getCleanInstance($row['setype']);
  63                  $recordModel->setData($row);
  64                  $recordModel->setId($row['crmid']);
  65                  $recordModels[$row['setype']][] = $recordModel;
  66              }
  67          }
  68          return $recordModels;
  69      }
  70  }
  71  
  72  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1