PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/models/Configuration.php

https://github.com/charlesportwoodii/CiiMS
PHP | 130 lines | 68 code | 15 blank | 47 comment | 0 complexity | 6925438a37b48b528e8b09d3e31da88c MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * This is the model class for table "configuration".
  4. *
  5. * The followings are the available columns in table 'configuration':
  6. * @property string $key
  7. * @property string $value
  8. * @property string $created
  9. * @property string $updated
  10. */
  11. class Configuration extends CiiModel
  12. {
  13. /**
  14. * Returns the static model of the specified AR class.
  15. * @param string $className active record class name.
  16. * @return Configuration the static model class
  17. */
  18. public static function model($className=__CLASS__)
  19. {
  20. return parent::model($className);
  21. }
  22. /**
  23. * @return string the associated database table name
  24. */
  25. public function tableName()
  26. {
  27. return 'configuration';
  28. }
  29. /**
  30. * @return array validation rules for model attributes.
  31. */
  32. public function rules()
  33. {
  34. // NOTE: you should only define rules for those attributes that
  35. // will receive user inputs.
  36. return array(
  37. array('key, value, created, updated', 'required'),
  38. array('key', 'length', 'max'=>64),
  39. // The following rule is used by search().
  40. array('key, value, created, updated', 'safe', 'on'=>'search'),
  41. );
  42. }
  43. /**
  44. * @return array relational rules.
  45. */
  46. public function relations()
  47. {
  48. // NOTE: you may need to adjust the relation name and the related
  49. // class name for the relations automatically generated below.
  50. return array(
  51. );
  52. }
  53. /**
  54. * @return array customized attribute labels (name=>label)
  55. */
  56. public function attributeLabels()
  57. {
  58. return array(
  59. 'key' => Yii::t('ciims.models.Configuration', 'Key'),
  60. 'value' => Yii::t('ciims.models.Configuration', 'Value'),
  61. 'created' => Yii::t('ciims.models.Configuration', 'Created'),
  62. 'updated' => Yii::t('ciims.models.Configuration', 'Updated'),
  63. );
  64. }
  65. /**
  66. * Retrieves a list of models based on the current search/filter conditions.
  67. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  68. */
  69. public function search()
  70. {
  71. $criteria=new CDbCriteria;
  72. $criteria->compare('t.key',$this->key,true);
  73. $criteria->compare('value',$this->value,true);
  74. $criteria->compare('created',$this->created,true);
  75. $criteria->compare('updated',$this->updated,true);
  76. $criteria->order = "created DESC";
  77. return new CActiveDataProvider($this, array(
  78. 'criteria'=>$criteria,
  79. ));
  80. }
  81. /**
  82. * Generates a unique id
  83. * @return string
  84. */
  85. public function generateUniqueId()
  86. {
  87. $rnd_id = crypt(uniqid(mt_rand(),1));
  88. $rnd_id = strip_tags(stripslashes($rnd_id));
  89. $rnd_id = str_replace(".","",$rnd_id);
  90. $rnd_id = strrev(str_replace("/","",$rnd_id));
  91. $rnd_id = str_replace("$", '', substr($rnd_id,0,20));
  92. return $rnd_id;
  93. }
  94. /**
  95. * This will do a full recursive deletion of a card from bothe the filesystem and from
  96. * @param string $name The folder name in runtiome
  97. * @return boolean If the recursive delete was successful or not
  98. */
  99. public function fullDelete($name)
  100. {
  101. $path = Yii::getPathOfAlias('application.runtime.cards.' . $name);
  102. try {
  103. // Delete the directory path
  104. CiiFileDeleter::removeDirectory($path);
  105. // Delete the cache
  106. Yii::app()->cache->delete('dashboard_cards_available');
  107. Yii::app()->cache->delete('cards_in_category');
  108. // Delete the record
  109. return $this->delete();
  110. } catch (Exception $e) {
  111. return false;
  112. }
  113. return false;
  114. }
  115. }