Example #1
0
 /**
  * Finds the Banner model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Banner the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Banner::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 public static function find()
 {
     return parent::find()->where([Banner::tableName() . '.isdel' => 0]);
 }
Example #3
0
 public function updatePosition($position)
 {
     $models = Banner::find()->where("id != :id", ["id" => $this->id])->orderBy("position")->all();
     $pos = 0;
     $mis = false;
     $low = false;
     $up = false;
     $mod = "-";
     $m = false;
     foreach ($models as $model) {
         $mis = $mis === false && $model->position != $pos ? $pos : $mis;
         $pos = $pos + 1;
         $m = $model;
     }
     $alter = $mis === false && $position > $pos ? false : true;
     if ($m) {
         $mis = $mis === false ? $m->position + 1 : $mis;
     }
     $mod = $position > $mis ? "-" : "+";
     $low = $position > $mis ? $mis : $position;
     $up = $position < $mis ? $mis : $position + 1;
     $res = true;
     if ($low !== false && $up !== false && $alter === true) {
         $res = $this->db->createCommand("UPDATE " . Banner::tableName() . " \n\t\t\t\t\t\tSET position = (position" . $mod . "1) \n\t\t\t\t\t\tWHERE position >= :low AND position < :up AND id != :id")->bindValues(["low" => $low, "up" => $up, "id" => $this->id])->execute();
     }
     return $res;
 }