55namespace Kanvas \Sdk \Traits ;
66
77use Exception ;
8- use Kanvas \Sdk \SystemModules ;
9- use Kanvas \Sdk \FileSystem ;
108use Kanvas \Sdk \Apps ;
11- use Kanvas \Sdk \Users as KanvasUsers ;
9+ use Kanvas \Sdk \FileSystem ;
1210use Kanvas \Sdk \FileSystemEntities ;
13- use Phalcon \ Di ;
11+ use Kanvas \ Sdk \ Kanvas ;
1412use Kanvas \Sdk \KanvasObject ;
13+ use Kanvas \Sdk \SystemModules ;
14+ use Kanvas \Sdk \Users as KanvasUsers ;
15+ use Phalcon \Di ;
1516
1617/**
1718 * Trait ResponseTrait.
@@ -37,7 +38,7 @@ trait FileSystemModelTrait
3738 *
3839 * @return void
3940 */
40- protected function associateFileSystem (): bool
41+ protected function associateFileSystem () : bool
4142 {
4243 if (!empty ($ this ->uploadedFiles ) && is_array ($ this ->uploadedFiles )) {
4344 foreach ($ this ->uploadedFiles as $ file ) {
@@ -66,9 +67,10 @@ protected function associateFileSystem(): bool
6667 * ];.
6768 *
6869 * @param array $files
70+ *
6971 * @return void
7072 */
71- public function attach (array $ files ): bool
73+ public function attach (array $ files ) : bool
7274 {
7375 $ appId = Apps::getIdByKey (getenv ('GEWAER_APP_ID ' ));
7476 $ systemModule = SystemModules::getSystemModuleByModelName (self ::class, (int )$ appId );
@@ -91,7 +93,6 @@ public function attach(array $files): bool
9193 }
9294
9395 if (!is_object ($ fileSystemEntities )) {
94-
9596 //If filesystem entity does not exist then create a new one
9697 FileSystemEntities::create ([
9798 'filesystem_id ' => $ file ['file ' ]->id ,
@@ -119,9 +120,10 @@ public function attach(array $files): bool
119120 * Given this entity define a new path.
120121 *
121122 * @param string $path
123+ *
122124 * @return string
123125 */
124- protected function filesNewAttachedPath (): ?string
126+ protected function filesNewAttachedPath () : ?string
125127 {
126128 return null ;
127129 }
@@ -131,9 +133,10 @@ protected function filesNewAttachedPath(): ?string
131133 *
132134 * @param array data
133135 * @param array whiteList
136+ *
134137 * @return boolean
135138 */
136- public function update ($ data = null , $ whiteList = null ): bool
139+ public function update ($ data = null , $ whiteList = null ) : bool
137140 {
138141 //associate uploaded files
139142 if (isset ($ data ['files ' ])) {
@@ -158,19 +161,47 @@ public function update($data = null, $whiteList = null): bool
158161 *
159162 * @return bool
160163 */
161- public function deleteFiles (): bool
164+ public function deleteFiles () : bool
162165 {
163166 $ appId = Apps::getIdByKey (getenv ('GEWAER_APP_ID ' ));
164167 $ currentCompanyId = KanvasUsers::getSelf ()->default_company ;
165168
166169 if ($ files = FileSystemEntities::getAllByEntityId ($ this ->getId (), (int )$ appId , $ currentCompanyId )) {
167170 foreach ($ files as $ file ) {
168171 FileSystemEntities::update ($ file ->id , [
169- " is_deleted " => 1
172+ ' is_deleted ' => 1
170173 ]);
171174 }
172175 }
173176
174177 return true ;
175178 }
179+
180+ /**
181+ * Get User Files.
182+ *
183+ * @return KanvasObject
184+ */
185+ public function getFiles () : KanvasObject
186+ {
187+ $ appsId = Apps::getIdByKey (Kanvas::getApiKey ());
188+ $ systemModule = SystemModules::getSystemModuleByModelName (self ::class, (int )$ appsId );
189+ return FileSystemEntities::find (['conditions ' => ["entity_id: {$ this ->id }" , "system_modules_id: {$ systemModule ->id }" , 'is_deleted:0 ' ]]);
190+ }
191+
192+ /**
193+ * Undocumented function.
194+ *
195+ * @param string $fieldName
196+ *
197+ * @todo Adapt this function to the sdk
198+ *
199+ * @return string|null
200+ */
201+ public function getFileByName (string $ fieldName ) : ?object
202+ {
203+ $ appsId = Apps::getIdByKey (Kanvas::getApiKey ());
204+ $ systemModule = SystemModules::getSystemModuleByModelName (self ::class, (int )$ appsId );
205+ return FileSystemEntities::find (['conditions ' => ["entity_id: {$ this ->id }" , "system_modules_id: {$ systemModule ->id }" , "field_name: {$ fieldName }" , 'is_deleted:0 ' ]]);
206+ }
176207}
0 commit comments