示例#1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     BaseModel::unguard();
     $listImages = [['id' => 1, 'model_id' => 0, 'model' => '', 'filename' => 'test1.jpg', 'name' => 'Фотография 1', 'description' => 'Описание фотографии 1'], ['id' => 2, 'model_id' => 0, 'model' => '', 'filename' => 'test2.jpg', 'name' => 'Фотография 2', 'description' => 'Описание фотографии 2'], ['id' => 3, 'model_id' => 0, 'model' => '', 'filename' => 'test3.jpg', 'name' => 'Фотография 3', 'description' => 'Описание фотографии 3'], ['id' => 4, 'model_id' => 0, 'model' => '', 'filename' => 'test4.jpg', 'name' => 'Фотография 4', 'description' => 'Описание фотографии 4'], ['id' => 5, 'model_id' => 0, 'model' => '', 'filename' => 'test5.jpg', 'name' => 'Фотография 5', 'description' => 'Описание фотографии 5']];
     $dataBase = ['act' => true, 'part' => '', 'user_id' => 0, 'sort' => 0];
     DB::table('images')->truncate();
     foreach ($listImages as $row) {
         Model\Image::create(array_merge($dataBase, $row));
     }
 }
示例#2
0
 /**
  * Instantiate an Image from an image table id
  * @param int $imageId  id of image to create an Image instance from  
  * @return \Image
  */
 public static function constructById($imageId)
 {
     $row = Model\Image::getImageById($imageId);
     if (isset($row['id'])) {
         $image = self::constructByRow($row);
         $image->setId($row['id']);
         return $image;
     }
     return null;
 }
示例#3
0
 /**
  * Create an array of Images associated with this Pet instance
  * @throws Exception
  */
 public function loadImages()
 {
     $petId = 'pet:' . $this->id;
     $res = Model\Image::getImagesByPetId($petId);
     if ($res === false) {
         // log errors
         $msg = Core\Db::getErrorMessage();
         error_log("\n" . date('Y-m-d H:i:s', time()) . ": " . $msg, 3, LOG_PATH . '/mysql_error_log');
         throw new Exception($msg);
     }
     $this->images = array();
     foreach ($res as $imageRow) {
         $this->images[] = Image::constructByRow($imageRow);
     }
 }