[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Documents/models/ -> Folder.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  
  11  class Documents_Folder_Model extends Vtiger_Base_Model {
  12  
  13      /**
  14       * Function returns duplicate record status of the module
  15       * @return true if duplicate records exists else false
  16       */
  17  	public function checkDuplicate() {
  18          $db = PearDatabase::getInstance();
  19          $folderName = $this->getName();
  20  
  21          $result = $db->pquery("SELECT 1 FROM vtiger_attachmentsfolder WHERE foldername = ?", array($folderName));
  22          $num_rows = $db->num_rows($result);
  23          if ($num_rows > 0) {
  24              return true;
  25          }
  26          return false;
  27      }
  28  
  29      /**
  30       * Function returns whether documents are exist or not in that folder
  31       * @return true if exists else false
  32       */
  33  	public function hasDocuments() {
  34          $db = PearDatabase::getInstance();
  35          $folderId = $this->getId();
  36  
  37          $result = $db->pquery("SELECT 1 FROM vtiger_notes
  38                          INNER JOIN vtiger_attachmentsfolder ON vtiger_attachmentsfolder.folderid = vtiger_notes.folderid
  39                          INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_notes.notesid
  40                          WHERE vtiger_attachmentsfolder.folderid = ?
  41                          AND vtiger_attachmentsfolder.foldername != 'Default'
  42                          AND vtiger_crmentity.deleted = 0", array($folderId));
  43          $num_rows = $db->num_rows($result);
  44          if ($num_rows>0) {
  45              return true;
  46          }
  47          return false;
  48      }
  49  
  50      /**
  51       * Function to add the new folder
  52       * @return Documents_Folder_Model
  53       */
  54  	public function save() {
  55          $db = PearDatabase::getInstance();
  56          $folderName = $this->getName();
  57          $folderDesc = $this->get('description');
  58  
  59          $currentUserModel = Users_Record_Model::getCurrentUserModel();
  60          $currentUserId = $currentUserModel->getId();
  61  
  62          $result = $db->pquery("SELECT max(sequence) AS max, max(folderid) AS max_folderid FROM vtiger_attachmentsfolder", array());
  63          $sequence = $db->query_result($result, 0, 'max') + 1;
  64          $folderId = $db->query_result($result,0,'max_folderid') + 1;
  65          $params = array($folderId,$folderName, $folderDesc, $currentUserId, $sequence);
  66  
  67          $db->pquery("INSERT INTO vtiger_attachmentsfolder(folderid,foldername, description, createdby, sequence) VALUES(?, ?, ?, ?, ?)", $params);
  68          
  69          $this->set('sequence', $sequence);
  70          $this->set('createdby', $currentUserId);
  71          $this->set('folderid',$folderId);
  72          
  73          return $this;
  74      }
  75  
  76      /**
  77       * Function to delete existing folder
  78       * @return Documents_Folder_Model
  79       */
  80  	public function delete() {
  81          $db = PearDatabase::getInstance();
  82          $folderId = $this->getId();
  83          $result = $db->pquery("DELETE FROM vtiger_attachmentsfolder WHERE folderid = ? AND foldername != 'Default'", array($folderId));
  84          return $this;
  85      }
  86  
  87      /**
  88       * Function return an instance of Folder Model
  89       * @return Documents_Folder_Model
  90       */
  91  	public static function getInstance() {
  92          return new self();
  93      }
  94  
  95      /**
  96       * Function returns an instance of Folder Model
  97       * @param foldername
  98       * @return Documents_Folder_Model
  99       */
 100  	public static function getInstanceById($folderId) {
 101          $db = PearDatabase::getInstance();
 102          $folderModel = Documents_Folder_Model::getInstance();
 103  
 104          $result = $db->pquery("SELECT * FROM vtiger_attachmentsfolder WHERE folderid = ?", array($folderId));
 105          $num_rows = $db->num_rows($result);
 106          if ($num_rows > 0) {
 107              $values = $db->query_result_rowdata($result, 0);
 108              $folderModel->setData($values);
 109          }
 110          return $folderModel;
 111      }
 112  
 113      /**
 114       * Function returns an instance of Folder Model
 115       * @param <Array> row
 116       * @return Documents_Folder_Model
 117       */
 118  	public static function getInstanceByArray($row) {
 119          $folderModel = Documents_Folder_Model::getInstance();
 120          return $folderModel->setData($row);
 121      }
 122  
 123      /**
 124       * Function returns Folder's Delete url
 125       * @return <String> - Delete Url
 126       */
 127  	public function getDeleteUrl() {
 128          $folderName = $this->getName();
 129          return "index.php?module=Documents&action=Folder&mode=delete&foldername=$folderName";
 130      }
 131  
 132      /**
 133       * Function to get the id of the folder
 134       * @return <Number>
 135       */
 136  	public function getId() {
 137          return $this->get('folderid');
 138      }
 139  
 140      /**
 141       * Function to get the name of the folder
 142       * @return <String>
 143       */
 144  	public function getName() {
 145          return $this->get('foldername');
 146      }
 147  
 148      /**
 149       * Function to get the description of the folder
 150       * @return <String>
 151       */
 152  	function getDescription() {
 153          return $this->get('description');
 154      }
 155      
 156      /**
 157       * Function to get info array while saving a folder
 158       * @return Array  info array
 159       */
 160  	public function getInfoArray() {
 161          return array('folderName' => $this->getName(),'folderid' => $this->getId());
 162      }
 163  
 164  }
 165  ?>


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