Exemple #1
0
 /**
  * Delete attachment from server and db.
  *
  * @var $attachment_id
  *
  * @return bool
  * @throws \Exception
  */
 public function actionDelete()
 {
     if (\Yii::$app->request->isPost && \Yii::$app->request->isAjax) {
         $attachment_id = \Yii::$app->request->post('attachment_id');
         //if attachment with id is exists
         if ($attachment = Attachment::findOne(["id" => $attachment_id])) {
             /* @var Attachment $attachment */
             $attachment->delete();
             echo \yii\helpers\Json::encode(['status' => '1']);
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * @return bool
  */
 public function saveAttachments()
 {
     if (is_array($this->attachments)) {
         $sequence = 0;
         foreach ($this->attachments as $attachment_id) {
             //save link to document and sequence
             if ($attachment = Attachment::findOne(['id' => $attachment_id])) {
                 $attachment->document_id = $this->primaryKey;
                 $attachment->sequence = $sequence;
                 $attachment->save();
                 $sequence++;
             }
         }
         return true;
     }
     return false;
 }