/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function getEdit($id) { $object = Object::find($id); $parent_id = $object->parent_id; $categories = Object::where('type', 'category')->where('id', '!=', $id)->get(); if ($imageObjectId = $object->getValue('_featured_image')) { // $featuredImage = getImageSrc($imageObjectId, 'thumbnail'); $featuredImage = 'cropped/' . getTheImageSize(getImageSrc($imageObjectId), '_featured_image'); } if ($imageObjectId = $object->getValue('_content_image')) { // $contentImage = getImageSrc($imageObjectId, 'thumbnail'); $contentImage = 'cropped/' . getTheImageSize(getImageSrc($imageObjectId), '_content_image'); } $toolTip = $object->getValue('_tooltip'); $keywords = $object->keywords->implode('content', ', '); return view('admin.category.create_edit', compact('object', 'parent_id', 'categories', 'featuredImage', 'contentImage', 'toolTip', 'keywords')); }
public function getSearchPage($fromLocation = false) { $categoryId = Input::get('categoryid'); $index = Input::get('index') ?: 0; $search = Input::get('query'); $offset = (int) Input::get('offset'); $limit = 10; $objects = null; if ($categoryId) { // Category Image $featuredImageUrl = ''; if ($categoryFeaturedImageId = ObjectMeta::getValue($categoryId, '_featured_image')) { // $featuredImageUrl = getImageSrc($categoryFeaturedImageId, 'thumbnail'); $featuredImageUrl = 'cropped/' . getTheImageSize(getImageSrc($categoryFeaturedImageId), '_featured_image'); } $objects = Object::whereNotIn('objects.type', ['object_type', 'image', 'category'])->where(function ($query) use($search) { $query->where('objects.title', 'LIKE', '%' . $search . '%')->orWhere('objects.content', 'LIKE', '%' . $search . '%')->orWhere('keywords.content', 'LIKE', '%' . $search . '%'); })->join('objects as obj', function ($join) { $join->on('obj.name', '=', DB::raw("concat( '_object_type_', objects.type )")); })->leftJoin('keywords', function ($join) { $join->on('obj.id', '=', 'object_id')->orOn('objects.id', '=', 'object_id'); })->join('object_meta', function ($join) { $join->on('object_meta.object_id', '=', 'obj.id')->where('object_meta.meta_key', '=', '_category_id'); })->join('objects as cat', function ($join) { $join->on('cat.id', '=', 'object_meta.meta_value'); })->where('object_meta.meta_value', $categoryId)->select(DB::raw("'{$featuredImageUrl}' AS featured_image"), 'cat.id AS catID', 'cat.title AS catTitle', 'cat.name AS catName', 'obj.id AS objID', 'obj.name AS objName', 'objects.id', 'objects.excerpt', 'objects.parent_id', 'objects.name', 'objects.type', 'objects.title', 'objects.score')->groupBy('objects.id')->orderBy('objects.score', 'DESC')->orderBy('objects.title', 'ASC'); if (!$fromLocation) { $objects->take($limit)->skip($offset); } $objects = $objects->get(); foreach ($objects as $object) { $this->processObject($object); } if (!$fromLocation) { foreach ($objects as &$object) { unset($object['address']); unset($object['address_city']); unset($object['address_country']); unset($object['address_street']); unset($object['catID']); // unset($object['catName']); unset($object['catTitle']); unset($object['email']); unset($object['objID']); unset($object['objName']); unset($object['occupation']); unset($object['parent_id']); unset($object['phone']); unset($object['promoted']); unset($object['type']); if ($featuredImageUrl == $object['featured_image']) { unset($object['featured_image']); } $object['excerpt'] = mb_substr($object['excerpt'], 0, 200); } } return ['items' => $objects, 'offset' => count($objects) >= $limit ? $offset + $limit : 0]; /* dd($objects->toArray()); // Category Image $featuredImageUrl = ''; if ($categoryFeaturedImageId = ObjectMeta::getValue($categoryId, '_featured_image')) { $featuredImageUrl = getImageSrc($categoryFeaturedImageId, 'thumbnail'); } // Get objects where in category $objects = Object::Where('type', 'object_type') ->whereExists(function ( $query ) use ( $categoryId ) { $query->select(DB::raw(1)) ->from('object_meta') ->whereRaw(DB::getTablePrefix() . 'object_meta.object_id = ' . DB::getTablePrefix() . 'objects.id') ->where('meta_key', '_category_id') ->where('meta_value', $categoryId); }) ->select(DB::raw('substr(name, 14) as field_name')) ->get() ->toArray(); $types = array_map(function($v) { return $v['field_name']; }, $objects); $objects = DB::table('objects') ->whereIn('type', $types) ->select( array( 'objects.id', DB::raw( '"'. $featuredImageUrl . '"' . ' as featured_image'), 'objects.name', 'objects.title', 'objects.excerpt', 'objects.content' ) ); // dd($objects->get()); $objects = DB::table('objects') ->whereIn('type', $types) ->where(function( $query ) use ( $search ) { $query->where('title', 'LIKE', '%' . $search . '%') ->orWhere('name', 'LIKE', '%' . $search . '%'); }) ->orderBy('score','DESC') ->select( array( 'objects.id', DB::raw( '"'. $featuredImageUrl . '"' . ' as featured_image'), 'objects.name', 'objects.title', 'objects.excerpt', 'objects.content' ) ) ->whereExists(function ( $query ) { $query->select(DB::raw(1)) ->from('object_meta') ->whereRaw(DB::getTablePrefix() . 'object_meta.object_id = ' . DB::getTablePrefix() . 'objects.id') ->where('meta_key', '_field_promoted') ->where('meta_value', '1'); })-> union($objects); dd($objects->toSql()); */ } else { if ($search) { $objects = Object::whereNotIn('objects.type', ['object_type', 'image', 'category'])->where(function ($query) use($search) { $query->where('objects.title', 'LIKE', '%' . $search . '%')->orWhere('objects.content', 'LIKE', '%' . $search . '%')->orWhere('keywords.content', 'LIKE', '%' . $search . '%'); })->join('objects as obj', function ($join) { $join->on('obj.name', '=', DB::raw("concat( '_object_type_', objects.type )")); })->leftJoin('keywords', function ($join) { $join->on('obj.id', '=', 'object_id')->orOn('objects.id', '=', 'object_id'); })->select('obj.id AS objID', 'obj.name AS objName', 'objects.id', 'objects.excerpt', 'objects.parent_id', 'objects.name', 'objects.type', 'objects.title')->orderBy('objects.score', 'DESC')->orderBy('objects.title', 'ASC')->groupBy('objects.id')->get(); $parentObjects = array_unique($objects->map(function ($v) { return $v->objID; })->toArray()); if ($parentObjects) { $_categories = ObjectMeta::whereIn('object_meta.object_id', $parentObjects)->where('object_meta.meta_key', '_category_id')->join('objects as cat', function ($join) { $join->on('cat.id', '=', 'object_meta.meta_value'); })->orderBy('cat.score', 'DESC')->orderBy('cat.title', 'ASC')->select('cat.id', 'cat.title', 'cat.name', 'object_meta.object_id')->get(); if ($_categories) { $categories = []; foreach ($_categories->toArray() as $item) { if (isset($categories[$item['id']])) { $categories[$item['id']]['parents'][] = $item['object_id']; } else { $categories[$item['id']] = array('id' => $item['id'], 'title' => $item['title'], 'name' => $item['name'], 'parents' => array($item['object_id'])); } } $objects = $objects->toArray(); $counter = 0; foreach ($categories as $k => $item) { foreach ($objects as $v) { if (in_array($v['objID'], $item['parents'])) { $v['excerpt'] = mb_substr($v['excerpt'], 0, 200); $categories[$k]['items'][] = $v; } } $categories[$k]['itemsCount'] = count($categories[$k]['items']); $counter += $categories[$k]['itemsCount']; $categories[$k]['items'] = array_slice($categories[$k]['items'], 0, 3); } if ($limit) { $categories = array_slice($categories, $offset, $limit); } return ['data' => $categories, 'count' => $counter, 'offset' => count($categories) >= $limit ? $offset + $limit : 0]; } } return []; } } // dd($objects); //dd($objects->toSql()); if ($objects) { $objects = $objects->get(); dd($objects); foreach ($objects as $object) { $this->processObject($object); } } return $objects; }
public function getCategories($id = null) { //Config::set('laravel-debugbar::config.enabled', false); $this->fetchCategories(); foreach ($this->items as $category) { if ($contentImageId = ObjectMeta::getValue($category->id, '_content_image')) { if ($contentImageUrl = getImageSrc($contentImageId)) { // if ($contentImageUrl = getImageSrc($contentImageId, 'medium') ) { $category['contentImageUrl'] = 'cropped/' . getTheImageSize($contentImageUrl, '_content_image'); // $category['contentImageUrl'] = $contentImageUrl; } } if ($featuredImageId = ObjectMeta::getValue($category->id, '_featured_image')) { if ($featuredImageUrl = getImageSrc($featuredImageId)) { // if ($featuredImageUrl = getImageSrc($featuredImageId, 'small')) { $category['featuredImageUrl'] = 'cropped/' . getTheImageSize($featuredImageUrl, '_featured_image'); // $category['featuredImageUrl'] = $featuredImageUrl; } } } $this->itemsParents[0] = []; $categories = $this->itemArray(); $this->items2 = $this->items->getDictionary(); /* $time11 = microtime(true); foreach($this->items2 as $k => &$v) { if($v->items_count) continue; $objects = Object::whereNotIn('objects.type', ['object_type', 'image','category']) ->join('objects as obj', function ($join){ $join->on('obj.name', '=', DB::raw("concat( '_object_type_', objects.type )")); }) ->join('object_meta', function ($join){ $join->on('object_meta.object_id', '=', 'obj.id') ->where('object_meta.meta_key', '=', '_category_id'); }) ->join('objects as cat', function ($join){ $join->on('cat.id', '=', 'object_meta.meta_value'); }) ->where('object_meta.meta_value', $k) ->select('objects.id', 'objects.name') ->limit(2) ; if($objects->count() != 1) continue; $v->url = $objects->first()->toArray(); } $time22 = microtime(true); */ $categories2 = $this->itemArray2(); $this->itemsParents2[0] = []; $breadCrumbs = []; $breadCrumbs[0] = []; foreach ($this->itemsParents as $itemID => $arr) { foreach ($arr as $subK) { $subItem = $this->items->getDictionary()[$subK]; $breadCrumbs[$itemID][] = ['id' => $subK, 'title' => $subItem->title, 'url' => $subItem->name, 'hasItems' => (bool) $subItem->items_count]; } } $currentItem = !$id ? false : ['id' => $id, 'title' => $this->items->getDictionary()[$id]['title'], 'contentImageUrl' => $this->items->getDictionary()[$id]['contentImageUrl'], 'featuredImageUrl' => $this->items->getDictionary()[$id]['featuredImageUrl']]; // echo "script execution time: ".($time22-$time11); //value in seconds return response()->json(['categories' => $categories2, 'parents' => $this->itemsParents, 'breadcrumbs' => $breadCrumbs, 'currentItem' => $currentItem]); }
function addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, $fieldName) { list($source_image_width, $source_image_height, $source_image_type) = getimagesize($destinationPath . $picture); $imageObjectInfo = array(); $imageObjectInfo['width'] = $source_image_width; $imageObjectInfo['height'] = $source_image_height; $imageObjectInfo['fileName'] = $filename; $imageObjectInfo['filePath'] = $newfileName . '.' . $extension; $imageObjectInfo['sizes'] = array(); $x = autoCrop($destinationPath, $picture, $fieldName); if ($x !== false) { $round = (int) \App\ResizesTinypng::max('round') + 1; insertIntoTableResizes($round, getTheImageSize($picture, $fieldName), $destinationPath . 'cropped/' . getTheImageSize($picture, $fieldName), 0, 'N', 0, false); $results_table = selectByRoundNumber($round); if (!empty($results_table)) { foreach ($results_table as $res_row) { $result_array = array('id' => intval($res_row['id']), 'round' => intval($res_row['round']), 'filename' => $res_row['file_name'], 'path' => $res_row['path'], 'runTiny' => intval($res_row['run_tiny']), 'error' => $res_row['error'], 'timeTiny' => intval($res_row['time_tiny']), 'timeAdded' => intval($res_row['created_at'])); $row_obj = array_to_object($result_array); $error_message = "N"; //START >> tinify images $tmp_path = str_replace(getcwd() . '/', "", $row_obj->path); //GET SERVER PATH $save_path = str_replace($row_obj->filename, "", $tmp_path); //OVERRIDE CURRENT LOCATION $flag = tinifyImage($row_obj->path, $save_path); if ($flag === false) { if ($error_message == "N") { $error_message = "Y - Compression failed"; } else { $error_message .= " - Compression failed"; } } //END << tinify image //UPDATE DB updateTableResizes($row_obj->id, $row_obj->round, $row_obj->filename, $row_obj->path, 1, $error_message, time(), $row_obj->timeAdded); } } } /* if ($source_image_width > 1920) {//} || $source_image_height > 1080) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1920, 1080); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['large'] = $imageInfo; } if ($source_image_width > 1024) { // || $source_image_height > 768) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1024, 768); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['medium'] = $imageInfo; } if ($source_image_width > 350) {//|| $source_image_height > 350) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 350, 350); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['small'] = $imageInfo; } if ($source_image_width > 300) {//|| $source_image_height > 350) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 300, 300); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['thumbnail'] = $imageInfo; } */ // Save image object if ($imageObjectId = ObjectMeta::getValue($object->id, $fieldName)) { $imageObject = Object::find($imageObjectId); } if (empty($imageObject)) { $imageObject = new Object(); } $imageObject->author_id = Auth::user()->id; $imageObject->type = 'image'; $imageObject->name = $newfileName . '.' . $extension; $imageObject->title = $filename; $imageObject->status = 'inherit'; $imageObject->guid = $newfileName; $imageObject->save(); ObjectMeta::setValue($imageObject->id, '_file_path', $newfileName . '.' . $extension); ObjectMeta::setValue($imageObject->id, '_image_info', serialize($imageObjectInfo)); ObjectMeta::setValue($object->id, $fieldName, $imageObject->id); return $imageObject; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function getEdit($id) { $data = Object::get(); $object = Object::find($id); if ($typeName = $object->type) { if ($type = Object::getType($typeName)->first()) { $fieldsRows = Object::getFields($type->id)->get(); $fields = array(); $fieldControls = array(); // Promoted $field = array(); $field['id'] = '_field_promoted'; $field['name'] = 'promoted'; $field['label'] = 'Promoted'; $field['type'] = 'boolean'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); foreach ($values as $key => $value) { if ($values[$key] == '1') { $values[$key] = 'on'; } } $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values')); // Occupation $field = array(); $field['id'] = '_field_occupation'; $field['name'] = 'occupation'; $field['label'] = 'Occupation'; $field['type'] = 'text'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); $fieldControls[] = view('admin.partials.form.text', compact('field', 'values')); // Address $uniqueId = Hash::getUniqueId(); $field = array(); $field['id'] = '_field_address'; $field['name'] = 'address'; $field['label'] = 'Address'; $field['type'] = 'map'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); $fieldControls[] = view('admin.partials.form.map', compact('field', 'values', 'uniqueId')); // French $field = array(); $field['id'] = '_field_french_speakers'; $field['name'] = 'french_speakers'; $field['label'] = 'French Speakers'; $field['type'] = 'boolean'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values')); // Address $field = array(); $field['id'] = '_field_phone'; $field['name'] = 'phone'; $field['label'] = 'Phone'; $field['type'] = 'tel'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); $fieldControls[] = view('admin.partials.form.tel', compact('field', 'values')); // Email $field = array(); $field['id'] = '_field_email'; $field['name'] = 'email'; $field['label'] = 'Email'; $field['type'] = 'email'; $field['instructions'] = ''; $field['required'] = 0; $values = $this->getFieldValues($id, $field); $fieldControls[] = view('admin.partials.form.email', compact('field', 'values')); foreach ($fieldsRows as $fieldRow) { $field = unserialize($fieldRow['meta_value']); $fields[] = $field; //$field['value'] = $object->getValue($field['id']); $values = array(); $valuesMeta = ObjectMeta::where('object_id', $id)->where('meta_key', 'LIKE', $field['id'] . '%')->get(); foreach ($valuesMeta as $valueMeta) { $valueMetaKey = str_replace($field['id'], '', $valueMeta['meta_key']); if (substr($valueMetaKey, 0, 1) == '-') { $valueMetaKey = substr($valueMetaKey, 1); } $value = $valueMeta['meta_value']; if ($value == '1') { $value = 'on'; } if ($valueMetaKey) { $values[$valueMetaKey] = $value; } else { $values[] = $value; } } $uniqueId = Hash::getUniqueId(); switch ($field['type']) { case 'text': $fieldControls[] = view('admin.partials.form.text', compact('field', 'values', 'uniqueId')); break; case 'wysiwyg': $fieldControls[] = view('admin.partials.form.wysiwyg', compact('field', 'values', 'uniqueId')); break; case 'map': $fieldControls[] = view('admin.partials.form.map', compact('field', 'values', 'uniqueId')); break; case 'tel': $fieldControls[] = view('admin.partials.form.tel', compact('field', 'values', 'uniqueId')); break; case 'boolean': $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values', 'uniqueId')); break; } } } } if (isset($object)) { if ($imageObjectId = $object->getValue('_featured_image')) { $featuredImage = getImageSrc($imageObjectId); $featuredImage = 'cropped/' . getTheImageSize($featuredImage, '_featured_image'); } if ($imageObjectId = $object->getValue('_content_image')) { $contentImage = getImageSrc($imageObjectId); $contentImage = 'cropped/' . getTheImageSize($contentImage, '_content_image'); } //d } //dd($object); return view('admin.object.create_edit', compact('object', 'fields', 'values', 'fieldControls', 'featuredImage', 'contentImage')); }