public function findBySponsorId($sponsorId) { $sql = 'select f.* from files f, sponsor_files sf' . ' where f.id = sf.file_id and sf.sponsor_id = :sponsorId'; $results = $this->fetch($sql, ['sponsorId' => $sponsorId]); foreach ($results as $result) { $file = new \Conftrack\Model\File($this->getDb()); $file->load($result, false); $this->add($file); } }
public function handleUpload($fileData) { $uploadPath = APP_PATH . '/upload/sponsor/' . $this->id; if (realpath($uploadPath) === false) { mkdir($uploadPath); } $hash = sha1(file_get_contents($fileData['tmp_name'])); move_uploaded_file($fileData['tmp_name'], $uploadPath . '/' . $hash); // Now save a record for it in files $file = new \Conftrack\Model\File($this->getDb()); $file->load(['name' => $fileData['name'], 'hash' => $hash]); $file->save(); $sponsorFile = new \Conftrack\Model\SponsorFile($this->getDb()); $sponsorFile->load(['sponsor_id' => $this->id, 'file_id' => $file->id]); $sponsorFile->save(); }