Example #1
0
 function _upload_db($old, $to, $path, $size, $type)
 {
     $data = file_get_contents($old);
     $uniqid = md5($data);
     $query = new Query();
     $query->select('id,path')->from('file')->where(array('uniqid' => $uniqid));
     $command = $query->createCommand();
     $row = $command->queryRow();
     if (!$row) {
         copy($old, $to);
         $data = array('path' => $path, 'uniqid' => $uniqid, 'size' => $size, 'type' => $type, 'uid' => $this->uid, 'created' => time(), 'admin' => $this->admin);
         \Yii::$app->db->createCommand()->insert('file', $data)->execute();
     } else {
         if (!file_exists(root_path() . $row['path'])) {
             copy($old, root_path() . $row['path']);
         }
     }
     $query = new Query();
     $query->select('id,path,type')->from('file')->where(array('uniqid' => $uniqid));
     $command = $query->createCommand();
     $row = $command->queryRow();
     @unlink($old);
     return $row;
 }
Example #2
0
 public function actionAutocomplete($search = null, $id = null, $object_id = null)
 {
     /**
      * @todo Добавить отображение вложенности
      */
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new Query();
         $query->select(Property::tableName() . '.id, ' . Property::tableName() . '.name AS text')->from(Property::tableName())->andWhere(['like', Property::tableName() . '.name', $search])->limit(100);
         if (!is_null($object_id)) {
             $query->leftJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id');
             $query->andWhere([PropertyGroup::tableName() . '.id' => $object_id]);
         }
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Property::findOne($id)->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     echo Json::encode($out);
 }
 public function actionCustList($q = null, $CUST_KD = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['CUST_KD' => '', 'text' => '']];
     if (!is_null($q)) {
         $query = new Query();
         $query->select('CUST_KD, CUST_NM AS text')->from('customer')->where(['like', 'CUST_NM', $q])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $CUST_KD, 'text' => Customer::find($id)->CUST_NM];
     }
     return $out;
 }