/**
  * If content id and type provided then do join
  * return boolean
  * @param $result
  * @return bool
  */
 private function doMediaJoin($result)
 {
     if (isset($_GET['content_id']) && isset($_GET['content_type'])) {
         $media = $result['data'];
         if (!is_null($media)) {
             //Do join here
             $contentMedia = new ContentMedia();
             $contentMedia->content_id = $_GET['content_id'];
             $contentMedia->content_type = $_GET['content_type'];
             $contentMedia->media_id = $media['id'];
             if ($contentMedia->save(false)) {
                 //success
                 return true;
             } else {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Attached Content Media, by type
  * @return static
  */
 public function getContentMedia()
 {
     return $this->hasMany(ContentMedia::className(), ['content_id' => 'id'])->where('content_type = :type', [':type' => $this->className()]);
 }
Example #3
0
 /**
  * Attached Content Media, by type
  * @return static
  */
 public function getMediaContent()
 {
     return $this->hasOne(ContentMedia::className(), ['id' => 'content_id']);
     //->where('content_type = :type', [':type' => $this->className()]);
 }