public function restore()
 {
     if (!Input::has('batch')) {
         return Response::json(['message' => 'Need guid and batch'], 400);
     }
     $batch = preg_replace('/[^0-9-_]+/', '', Input::get('batch'));
     if (Input::has('guid')) {
         $guids = [preg_replace('/[^A-Z0-9-]+/', '', Input::get('guid'))];
     } else {
         $guids = array_map(function ($x) {
             return preg_replace('/[^A-Z0-9-]+/', '', $x);
         }, array_filter(scandir(public_path() . '/backups/' . $batch), function ($x) {
             return $x[0] != '.';
         }));
     }
     $simulations = new Collection();
     foreach ($guids as $id) {
         $path = public_path() . '/backups/' . $batch . '/' . $id . '.xml';
         if (!file_exists($path)) {
             return Response::json(['message' => 'Cannot find backup', 'guid' => $id, 'batch' => $batch, 'path' => $path], 400);
         }
         $xml = new DOMDocument();
         $xml->load($path);
         try {
             $simulations[] = Simulation::fromXml($xml);
         } catch (Exception $e) {
             return Response::json($e, 400);
         }
     }
     return Response::json($simulations->lists('Id'), 200);
 }
 /**
  * @param Collection $posts
  * @return array
  */
 protected static function buildContent(Collection $posts)
 {
     return implode(', ', $posts->lists('id')->toArray());
 }
Example #3
0
 public static function getAllEndChildrenCategory()
 {
     $allCategories = static::getAllCategories();
     $endChildrenCategory = new EloquentCollection();
     foreach ($allCategories as $category) {
         if ($category->isEndChild()) {
             $endChildrenCategory->push($category);
         }
     }
     return $endChildrenCategory->lists('title', 'id')->all();
 }
Example #4
0
 private function getCollectionIdentifierValues($resourceName, Collection $collection)
 {
     if (isset($this->configIdentifiers[$resourceName])) {
         $identifier = $this->configIdentifiers[$resourceName];
         if (isset($identifier["value"])) {
             return $collection->lists($identifier["value"]);
         }
     }
     if (isset($this->configIdentifier["value"])) {
         $key = $this->configIdentifier["value"];
         return $collection->lists($key);
     }
     return $collection->modelKeys();
 }