public function actionUpload()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $result = [];
     $files = UploadedFile::getInstances(new File(), 'uploadedFiles');
     foreach ($files as $index => $file) {
         $model = new File();
         $model->uploadedFiles = [$file];
         $model->user_id = Yii::$app->user->id;
         $model->storage = File::STORAGE_OS;
         $model->extension = $file->extension;
         $model->type = File::defineType($model->extension);
         if ($model->upload()) {
             $item = ['id' => $model->id, 'url' => $model->getUrl(), 'type' => $model->getMimeType()];
             if ($releaseId = Yii::$app->request->get('rid')) {
                 $release = Release::findOne($releaseId);
                 if ($release && $release->artist->user_id == Yii::$app->user->id) {
                     if ($model->type == $model::TYPE_IMAGE) {
                         $cover = new Cover(['release_id' => $release->id, 'file_id' => $model->id, 'is_main' => false]);
                         $cover->save();
                         $item['image_id'] = $cover->id;
                     } elseif ($model->type == $model::TYPE_AUDIO) {
                         $track = new Track(['release_id' => $release->id, 'original_name' => $file->baseName, 'number' => $release->getTracks()->count() + 1, 'file_id' => $model->id]);
                         $track->save();
                         $item['track_id'] = $track->id;
                         $item['comname'] = $track->getComname();
                         $item['number'] = $track->number;
                     }
                 }
             }
             if ($artistId = Yii::$app->request->get('aid')) {
                 $photo = new Photo(['artist_id' => (string) $artistId, 'file_id' => $model->id, 'is_main' => false]);
                 $artist = Artist::findOne($artistId);
                 if ($artist && $artist->user_id == Yii::$app->user->id) {
                     $photo->save();
                     $item['image_id'] = $photo->id;
                 }
             }
             //                if ($model->type == $model::TYPE_AUDIO) {
             //                    $getID3 = new getID3();
             //                    $tags = $getID3->analyze($model->getPath(true))['tags']['id3v2'];
             //                    $item['meta'] = [
             //                        'title' => $tags['title'][0],
             //                        'number' => explode('/', $tags['track_number'][0])[0],
             //                        'disc' => explode('/', $tags['part_of_a_set'][0])[0],
             //                        'lyric' => $tags['unsynchronised_lyric'][0],
             //                        'info' => $tags['comment'][0],
             //                    ];
             //                }
             if ($model->type == $model::TYPE_AUDIO) {
                 $item['meta'] = ['title' => $file->baseName, 'number' => $index + 1, 'disc' => '', 'lyric' => '', 'info' => ''];
             }
             $result[] = $item;
         }
     }
     return $result;
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Release::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'artist_id' => $this->artist_id, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'original_name', $this->original_name])->andFilterWhere(['like', 'latin_name', $this->latin_name])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'info', $this->info]);
     return $dataProvider;
 }
 public function actionRelease()
 {
     $model = Release::findOne(Yii::$app->request->post('pk', ''));
     $ownerId = $model->artist->user_id;
     if (Yii::$app->request->post('name', '') == 'release-tags') {
         $releaseTags = (new \yii\db\Query())->select('tag_id')->from('release_tag')->where(['release_id' => $model->id])->column();
         $requestTags = Yii::$app->request->post('value', []);
         foreach ($requestTags as $tagId) {
             if (!in_array($tagId, $releaseTags)) {
                 $tag = Tag::findOne($tagId);
                 if ($tag) {
                     $model->link('tags', $tag);
                 }
             }
         }
         foreach ($releaseTags as $tagId) {
             if (!in_array($tagId, $requestTags)) {
                 Yii::$app->db->createCommand()->delete('release_tag', ['release_id' => $model->id, 'tag_id' => $tagId])->execute();
             }
         }
         return null;
     }
     return self::update($model, $ownerId);
 }
 public function getList()
 {
     $d = [];
     // GET LAST THREE YEARS OF DATA
     for ($i = 0; $i < 3; $i++) {
         $year = date("Y") - $i;
         $data = ['dependencia' => '901', "ejercicio" => $year];
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_URL, $this->apiContratos);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
         $result = curl_exec($ch);
         $excercise = json_decode($result);
         $d = array_merge($d, $excercise);
     }
     // SAVE THEM TO THE DB
     foreach ($d as $c) {
         $contract = Contract::firstOrCreate(['ocdsid' => $c->ocdsID, 'ejercicio' => $c->ejercicio, 'cvedependencia' => $c->cveDependencia, 'nomDependencia' => $c->nomDependencia]);
         // save extra data
         $meta = $this->getMetaDataX($contract);
         if (!empty($meta) && !property_exists($meta, 'error')) {
             // add extra data to contracts
             $contract->uri = $meta->uri;
             $contract->published_date = date("Y-m-d", strtotime($meta->publishedDate));
             // create the publisher
             $contract->publisher_id = Publisher::firstOrCreate(["scheme" => $meta->publisher->scheme, "name" => $meta->publisher->name, "uri" => $meta->publisher->uri, "uid" => $meta->publisher->uid]);
             // update contract
             $contract->update();
             // create releases
             foreach ($meta->releases as $r) {
                 $release = Release::firstOrCreate(["local_id" => $r->id, "contract_id" => $contract->id, "ocid" => $contract->ocdsid, "date" => date("Y-m-d", strtotime($r->date)), "initiation_type" => $r->initiationType, "language" => $r->language]);
                 if (count($r->awards)) {
                     foreach ($r->awards as $aw) {
                         $award = Award::firstOrCreate(["release_id" => $release->id, "local_id" => $aw->id]);
                         $award->title = $aw->title;
                         $award->description = $aw->description;
                         $award->status = $aw->status;
                         $award->date = date("Y-m-d", strtotime($aw->date));
                         $award->value = $aw->value->amount;
                         $award->currency = $aw->value->currency;
                         $award->update();
                         if (count($aw->items)) {
                             foreach ($aw->items as $it) {
                                 $item = $award->items()->firstOrCreate(['local_id' => $it->id]);
                                 $item->quantity = $it->quantity;
                                 $item->description = $it->description;
                                 $item->unit = $it->unit->name;
                                 $item->update();
                             }
                         }
                         if (count($aw->suppliers)) {
                             foreach ($aw->suppliers as $sup) {
                                 $supplier = Supplier::firstOrCreate(["award_id" => $aw->id, "rfc" => $sup->identifier->id]);
                                 $supplier->name = $sup->name;
                                 $supplier->street = $sup->address->streetAddress;
                                 $supplier->locality = $sup->address->locality;
                                 $supplier->region = $sup->address->region;
                                 $supplier->zip = $sup->address->postalCode;
                                 $supplier->country = $sup->address->countryName;
                                 $supplier->contact_name = $sup->contactPoint->name;
                                 $supplier->email = $sup->contactPoint->email;
                                 $supplier->phone = $sup->contactPoint->telephone;
                                 $supplier->fax = $sup->contactPoint->faxNumber;
                                 $supplier->url = $sup->contactPoint->url;
                                 $supplier->update();
                             }
                         }
                     }
                 }
                 if (count($r->contracts)) {
                     foreach ($r->contracts as $single) {
                         $single_contract = SingleContract::firstOrCreate(["local_id" => $single->id, "release_id" => $release->id]);
                         $single_contract->award_id = $single->awardID;
                         $single_contract->title = $single->title;
                         $single_contract->description = $single->description;
                         $single_contract->status = $single->status;
                         $single_contract->contract_start = $single->period ? date("Y-m-d", strtotime($single->period->startDate)) : null;
                         $single_contract->contract_end = $single->period ? date("Y-m-d", strtotime($single->period->endDate)) : null;
                         $single_contract->amount = $single->value->amount;
                         $single_contract->currency = $single->value->currency;
                         $single_contract->date_signed = $single->dateSigned ? date("Y-m-d", strtotime($single->dateSigned)) : null;
                         $single_contract->documents = count($single->documents);
                         // ? implode(',',$r->tender->submissionMethod) : null;
                         $single_contract->update();
                         if (count($single->items)) {
                             foreach ($single->items as $it) {
                                 $item = $single_contract->items()->firstOrCreate(['local_id' => $it->id]);
                                 $item->quantity = $it->quantity;
                                 $item->description = $it->description;
                                 $item->unit = $it->unit->name;
                                 $item->update();
                             }
                         }
                     }
                 }
                 // create planning
                 if ($r->planning) {
                     $planning = Planning::firstOrCreate(["release_id" => $release->id]);
                     $planning->amount = $r->planning->budget->amount->amount;
                     $planning->currency = $r->planning->budget->amount->currency;
                     $planning->project = $r->planning->budget->project;
                     $planning->update();
                     //$release->planning_id = $planning->id;
                 }
                 // create tender
                 if ($r->tender) {
                     $tender = Tender::firstOrCreate(["release_id" => $release->id]);
                     $tender->local_id = $r->tender->id;
                     $tender->title = $r->tender->title;
                     $tender->description = $r->tender->description;
                     $tender->status = $r->tender->status;
                     $tender->amount = $r->tender->value ? $r->tender->value->amount : null;
                     $tender->currency = $r->tender->value ? $r->tender->value->currency : null;
                     $tender->procurement_method = $r->tender->procurementMethod;
                     $tender->award_criteria = $r->tender->awardCriteria;
                     $tender->tender_start = $r->tender->tenderPeriod ? date("Y-m-d", strtotime($r->tender->tenderPeriod->startDate)) : null;
                     $tender->tender_end = $r->tender->tenderPeriod ? date("Y-m-d", strtotime($r->tender->tenderPeriod->endDate)) : null;
                     $tender->enquiry_start = $r->tender->enquiryPeriod ? date("Y-m-d", strtotime($r->tender->enquiryPeriod->startDate)) : null;
                     $tender->enquiry_end = $r->tender->enquiryPeriod ? date("Y-m-d", strtotime($r->tender->enquiryPeriod->endDate)) : null;
                     $tender->award_start = $r->tender->awardPeriod ? date("Y-m-d", strtotime($r->tender->awardPeriod->startDate)) : null;
                     $tender->award_end = $r->tender->awardPeriod ? date("Y-m-d", strtotime($r->tender->awardPeriod->endDate)) : null;
                     $tender->has_enquiries = $r->tender->hasEnquiries;
                     $tender->eligibility_criteria = $r->tender->eligibilityCriteria;
                     $tender->submission_method = count($r->tender->submissionMethod) ? implode(',', $r->tender->submissionMethod) : null;
                     $tender->number_of_tenderers = $r->tender->numberOfTenderers;
                     $tender->update();
                     if (count($r->tender->tenderers)) {
                         foreach ($r->tender->tenderers as $tn) {
                             $tenderer = Tenderer::firstOrCreate(["rfc" => $tn->identifier->id]);
                             $tenderer->name = $tn->name;
                             $tenderer->street = $tn->address->streetAddress;
                             $tenderer->locality = $tn->address->locality;
                             $tenderer->region = $tn->address->region;
                             $tenderer->zip = $tn->address->postalCode;
                             $tenderer->country = $tn->address->countryName;
                             $tenderer->contact_name = $tn->contactPoint->name;
                             $tenderer->email = $tn->contactPoint->email;
                             $tenderer->phone = $tn->contactPoint->telephone;
                             $tenderer->fax = $tn->contactPoint->faxNumber;
                             $tenderer->url = $tn->contactPoint->url;
                             $tenderer->update();
                         }
                     }
                     if (count($r->tender->items)) {
                         foreach ($r->tender->items as $it) {
                             $item = $tender->items()->firstOrCreate(['local_id' => $it->id]);
                             $item->quantity = $it->quantity;
                             $item->description = $it->description;
                             $item->unit = $it->unit->name;
                             $item->update();
                         }
                     }
                 }
                 // create buyer
                 if ($r->buyer) {
                     $buyer = Buyer::firstOrCreate(["local_id" => $r->buyer->identifier->id, "name" => $r->buyer->name]);
                     $buyer->uri = $r->buyer->identifier->uri;
                     $buyer->update();
                     $release->buyer_id = $buyer->id;
                     $release->update();
                 }
             }
         }
     }
     echo ":D";
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRelease()
 {
     return $this->hasOne(Release::className(), ['id' => 'release_id']);
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReleases()
 {
     return $this->hasMany(Release::className(), ['artist_id' => 'id']);
 }
 private function saveReleases($contract, $data)
 {
     $releases = [];
     foreach ($data->releases as $rel) {
         $release = Release::firstOrCreate(["local_id" => $rel->id, "contract_id" => $contract->id, "ocid" => $contract->ocdsid, "date" => date("Y-m-d", strtotime($rel->date)), "initiation_type" => $rel->initiationType, "language" => $rel->language]);
         $this->info("se creó el release v{$release->local_id} de: {$contract->ocdsid}");
         $buyer = $this->saveBuyer($rel);
         $this->info("se creó el comprador para el release v{$release->local_id} de: {$contract->ocdsid}");
         $release->buyer_id = $buyer ? $buyer->id : null;
         $release->update();
         $releases[] = $release;
         $this->saveAwards($release, $rel);
         $this->info("se crearon los awards para el release v{$release->local_id} de: {$contract->ocdsid}");
         $this->saveContracts($release, $rel);
         $this->info("se crearon los contratos para el release v{$release->local_id} de: {$contract->ocdsid}");
         $this->savePlanning($release, $rel);
         $this->info("se creó la planeación para el release v{$release->local_id} de: {$contract->ocdsid}");
         $this->saveTender($release, $rel);
         $this->info("se creó la licitación para el release v{$release->local_id} de: {$contract->ocdsid}");
     }
     return $releases;
 }
示例#8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReleases()
 {
     return $this->hasMany(Release::className(), ['id' => 'release_id'])->viaTable('release_tag', ['tag_id' => 'id']);
 }
示例#9
0
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getArtist()
    {
        return $this->hasOne(Artist::className(), ['id' => 'artist_id']);
    }
    public function getTags()
    {
        return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable('release_tag', ['release_id' => 'id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTracks()
    {
        return $this->hasMany(Track::className(), ['release_id' => 'id']);
    }
    public function getComname()
    {
        return Utils::mergeNames($this->original_name, $this->latin_name);
    }
}
Event::on(Release::className(), Release::EVENT_BEFORE_DELETE, function ($event) {
    foreach ($event->sender->tracks as $item) {
        $item->delete();
    }
    foreach ($event->sender->covers as $item) {
        $item->delete();
    }
});
 /**
  * Finds the Release model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Release the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Release::findOne($id)) !== null) {
         if ($model->artist->user_id != Yii::$app->user->id) {
             throw new ForbiddenHttpException();
         }
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#11
0
 public function actionReleases()
 {
     return $this->render('releases', ['releases' => Release::find()->all()]);
 }
示例#12
0
 /**
  * Finds the Release model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Release the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Release::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }