123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- class PartType {
- public static function manifest(){
- return array(
- 'uid' => 'part',
- 'label' => 'Composants',
- 'description' => 'Composants électroniques',
- 'fromExtension' => array('part'),
- 'toExtension' => 'md',
- 'icon' => 'fas fa-microchip',
- 'color' => '#ffffff',
- 'background' => '#2ecc71'
-
- );
- }
- //Import depuis un glisser déposé du fichier
- public static function fromFile($resource){
- // $resource->save();
- // $ext = getExt($resource->label);
- // $name = $resource->id.'.'.$ext;
- // file_put_contents(SKETCH_PATH.$name,$resource->content);
- // $resource->content = $name;
- // return $resource;
- }
- //Import depuis un flux json compressé de la ressource
- public static function fromJson($resource){
- // $resource->save();
- // $stream = base64_decode($resource->content);
- // $resource->content = $resource->id.'.png';
- // file_put_contents(SKETCH_PATH.$resource->content,$stream);
- // return $resource;
- }
-
- //export en fichier JSON compressé de la ressource
- public static function toJson($resource){
- // $resource = $resource->toArray();
- // $resource['content'] = base64_encode(file_get_contents(SKETCH_PATH.$resource['content']));
- // return $resource;
- }
- public static function toFile($resource){
- require_once(__DIR__.SLASH.'ResourcePart.class.php');
- require_once(__DIR__.SLASH.'Part.class.php');
- global $myUser;
- $infos = self::manifest();
-
- $content = '# '.strtoupper($resource->label).PHP_EOL.PHP_EOL;
-
- foreach(ResourcePart::loadAll(array('resource'=>$resource->id), null, null, array('*'), 1) as $resourcePart):
- $part = $resourcePart->join('part');
- $content .= '## '.$part->label.PHP_EOL;
- if(isset($part->link) && !empty($part->link)) $content .= "\t".'* Url: ' .$part->link.PHP_EOL;
- if(isset($part->brand) && !empty($part->brand)) $content .="\t".'* Marque: ' .$part->brand.PHP_EOL;
- if(isset($part->price) && !empty($part->price)) $content .="\t".'* Prix moyen: '.$part->price.'€'.PHP_EOL;
- $content .= '---';
- $content .= PHP_EOL;
- endforeach;
-
-
- return array(
- 'name'=> slugify($resource->label).'.'.$infos['toExtension'],
- 'content' => $content
- );
- }
-
- /* EDITION */
- public static function toHtml($resource,$sketch=null){
- $infos = self::manifest();
- $response = array();
- //.$resource->id
- $images = array();
-
- foreach(glob($resource->directory().SLASH.'*.*') as $file){
- $images[] = array(
- 'path' => 'hackpoint'.SLASH.'sketch'.SLASH.$resource->sketch.SLASH.$resource->id.SLASH.basename($file),
- 'url' => 'action.php?action=hackpoint_download_file&file='.base64_encode('sketch'.SLASH.$resource->sketch.SLASH.$resource->id.SLASH.rawurlencode(basename($file))),
- 'name' => basename($file),
- 'icon' => getExtIcon(getExt($file))
- );
- }
- $response['html'] = '
- <div class="row">
- <div class="col-md-12">
-
- <div class="btn btn-dark btn-add-part" onclick="part_part_add()"><i class="far fa-plus-square pr-1"></i> Ajouter un composant</div>
-
- <ul id="parts" data-entity-search="part_resource_part_search">
- <li data-id="{{id}}" data-part="{{part}}" class="hidden">
- <div class="part">
- <input type="text" data-type="part" data-force="false" placeholder="Nom du composant" value="{{label}}" class="form-control label">
- <div class="part-image" data-label="Image" data-stream="{{picture}}"></div>
- <input class="hidden" type="file">
-
- <div class="price w-100 mt-2">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text">Prix</span>
- </div>
- <input class="form-control" type="text" value="{{price}}">
- <div class="input-group-append">
- <span class="input-group-text">€</span>
- </div>
- </div>
- </div>
- <div class="brand w-100 mt-2 mb-3">
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text">Marque</span>
- </div>
- <input class="form-control" type="text" value="{{brand}}"/>
- </div>
- </div>
-
-
-
- <a onclick="part_part_find(this)" title="Chercher sur le net" class="link"><i class="fas fa-globe-americas pointer"></i></a>
- <div class="btn btn-delete" onclick="part_resource_part_delete(this);"><i class="far fa-trash-alt"></i></div>
- <div class="clear"></div>
- <div class="btn btn-dark w-100 mb-3 btn-save-part" onclick="part_part_save(this)"><i class="far fa-check-circle"></i>Valider</div>
- </div>
- </li>
- </ul>
- </div>
- </div>
- ';
- $response['javascript'] = 'part_resource_part_search();';
-
- return $response;
- }
- }
- ?>
|