1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
37:
38: 39: 40: 41: 42:
43: class FileSystemObject {
44:
45: public $id;
46: public $parentId;
47: public $type;
48: public $objId;
49: public $name;
50: public $createdBy;
51: public $lastUpdated;
52: public $updatedBy;
53: public $visibility;
54: public $title;
55: public $isParent = false;
56:
57: public static function (){
58: $linkHeader = X2Html::tag(
59: 'div', array('class' => 'file-system-object-link',), Yii::t('docs','Name'));
60: $attrHeaderContent = X2Html::tag(
61: 'span', array('class' => 'file-system-object-owner'), Yii::t('docs', 'Owner'))
62: . X2Html::tag(
63: 'span',
64: array('class' => 'file-system-object-last-updated'), Yii::t('docs', 'Last Updated'))
65: . X2Html::tag(
66: 'span',
67: array('class' => 'file-system-object-visibility'), Yii::t('docs', 'Visibility'));
68: $attrHeader = X2Html::tag(
69: 'div', array('class' => 'file-system-object-attributes'), $attrHeaderContent);
70: $headerContent = X2Html::tag(
71: 'div', array('class' => 'file-system-clear-fix'), $linkHeader . $attrHeader);
72: return X2Html::tag('div', array('class' => 'file-system-header page-title'), $headerContent);
73: }
74:
75: public function __construct($options) {
76: foreach ($options as $key => $value) {
77: if (property_exists(get_class(), $key)) {
78: $this->$key = $value;
79: }
80: }
81: }
82:
83: public function getIcon() {
84: return X2Html::fa($this->type === 'folder' ? 'folder-open' : 'file-text');
85: }
86:
87: public function getLink() {
88: if ($this->type === 'folder') {
89: return X2Html::link($this->name, '#', array(
90: 'class'=>'folder-link pseudo-link',
91: 'data-id'=>$this->objId,
92: ));
93: } else {
94: return X2Html::link(
95: $this->name,
96: Yii::app()->controller->createUrl('/docs/view', array('id' => $this->objId)));
97: }
98: }
99:
100: public function renderName () {
101: $options = array (
102: "class" => "file-system-object-name",
103: );
104:
105: if ($this->title && preg_match ('/^[a-zA-Z0-9 \-]+$/', $this->title))
106: $options['title'] = $this->title;
107: return $this->getIcon ().CHtml::tag ("span", $options, $this->getLink ());
108: }
109:
110: public function getOwner(){
111: if(!empty($this->createdBy)){
112: $user = User::getUserLinks($this->createdBy, false, true);
113: if(!empty($user)){
114: return $user;
115: }
116: }
117: return ' ';
118: }
119:
120: public function getVisibility(){
121: if(is_null($this->visibility)){
122: $this->visibility = 1;
123: }
124: $visibilities = X2PermissionsBehavior::getVisibilityOptions ();
125: return $visibilities[$this->visibility];
126: }
127:
128: public function getLastUpdateInfo(){
129: if(!empty($this->updatedBy) && !empty($this->lastUpdated)){
130: return Formatter::formatDateTime($this->lastUpdated);
131: }
132: return ' ';
133: }
134:
135: public function validDroppable() {
136: return $this->type === 'folder' &&
137: (is_null($this->objId) || $this->objId > 0 || $this->parentId > 0) &&
138: ($this->name != '..' || is_null($this->parentId) || $this->parentId > 0);
139: }
140:
141: public function validDraggable() {
142: return $this->name !== '..' && $this->objId > 0;
143: }
144:
145: }
146: