Exemple #1
0
 /**
  * Add an image to the grid
  *
  * @param string|array $imageData An image
  */
 protected function addRichImage($imageData)
 {
     $imageData = $this->present($imageData);
     if ($this->presenter) {
         return $this->nest($imageData);
     }
     // If we provided a rich thumbnail
     $link = Arrays::get($imageData, 'link');
     $label = Arrays::get($imageData, 'label');
     $caption = Arrays::get($imageData, 'caption');
     // Create image
     $image = Arrays::get($imageData, 'image');
     $image = HtmlImage::create($image);
     // Linked thumbnail
     if (!$caption and !$label and $link) {
         $image = Link::create($link, $image)->addClass('thumbnail');
         // Plain thumbnail
     } else {
         $thumbnail = Element::create('div', $image)->addClass('thumbnail');
         if ($label) {
             $thumbnail->nest(Element::create('h3', $label));
         }
         if ($caption) {
             $thumbnail->nest(Element::create('p', $caption));
         }
         $image = $thumbnail;
     }
     return $this->nest(Element::create('li', $image));
 }
Exemple #2
0
 /**
  * Get an option from the config file
  *
  * @param string $option The key of the option
  *
  * @return mixed Its value
  */
 public static function option($option)
 {
     // Get config file
     if (!static::$options) {
         static::$options = (include __DIR__ . '/../config/config.php');
     }
     return ArraysMethods::get(static::$options, $option);
 }
Exemple #3
0
 /**
  * Get a particular option in the array
  *
  * @param string $option An option
  *
  * @return mixed Its value
  */
 public function getOption($option = null)
 {
     $globalOptions = Menu::getOption();
     $combinedOptions = array_replace_recursive($globalOptions, $this->options);
     if (!$option) {
         return $combinedOptions;
     }
     return ArraysMethods::get($combinedOptions, $option);
 }
 /**
  * Group values from a collection according to the results of a closure
  */
 public static function group($collection, $grouper)
 {
     $collection = (array) $collection;
     $result = array();
     // Iterate over values, group by property/results from closure
     foreach ($collection as $key => $value) {
         $key = is_callable($grouper) ? $grouper($value, $key) : ArraysMethods::get($value, $grouper);
         if (!isset($result[$key])) {
             $result[$key] = array();
         }
         // Add to results
         $result[$key][] = $value;
     }
     return $result;
 }
 /**
  * Catch aliases and reroute them to the right methods
  */
 public static function __callStatic($method, $parameters)
 {
     // Get base class and methods class
     $callingClass = static::computeClassToCall(get_called_class(), $method, $parameters);
     $methodsClass = Method::getMethodsFromType($callingClass);
     // Defer to Methods class
     if (method_exists($methodsClass, $method)) {
         return Repository::callMethod($methodsClass, $method, $parameters);
     }
     // Check for an alias
     if ($alias = Method::getAliasOf($method)) {
         return Repository::callMethod($methodsClass, $alias, $parameters);
     }
     // Check for parsers
     if (method_exists('Underscore\\Parse', $method)) {
         return Repository::callMethod('Underscore\\Parse', $method, $parameters);
     }
     // Defered methods
     if ($defered = Dispatch::toNative($callingClass, $method)) {
         return call_user_func_array($defered, $parameters);
     }
     // Look in the macros
     if ($macro = ArraysMethods::get(static::$macros, $callingClass . '.' . $method)) {
         return call_user_func_array($macro, $parameters);
     }
     throw new BadMethodCallException('The method ' . $callingClass . '::' . $method . ' does not exist');
 }
 /**
  * Group values from a collection according to the results of a closure.
  */
 public static function group($collection, $grouper, $saveKeys = false)
 {
     $collection = (array) $collection;
     $result = [];
     // Iterate over values, group by property/results from closure
     foreach ($collection as $key => $value) {
         $groupKey = is_callable($grouper) ? $grouper($value, $key) : ArraysMethods::get($value, $grouper);
         $newValue = static::get($result, $groupKey);
         // Add to results
         if ($groupKey !== null && $saveKeys) {
             $result[$groupKey] = $newValue;
             $result[$groupKey][$key] = $value;
         } elseif ($groupKey !== null) {
             $result[$groupKey] = $newValue;
             $result[$groupKey][] = $value;
         }
     }
     return $result;
 }
Exemple #7
0
 /**
  * Custom post action to build upon
  */
 public function customUpdate()
 {
     // Filter out foreign input that aren't model-related
     $attributes = (array) DB::table($this->object->getTable())->first();
     $attributes = array_keys($attributes);
     // If no model already exists, attempt a SHOW COLUMNS
     if (!$attributes) {
         $attributes = array_pluck(DB::query('SHOW COLUMNS FROM ' . $this->object->getTable()), 'field');
     }
     // Fetch input and its rules
     $input = Input::all();
     $item_id = Arrays::get($input, 'id');
     $isAdd = !$item_id;
     $item = $isAdd ? new $this->model() : $this->object->find($item_id);
     // Autocomplete uniqueness rules
     $rules = $this->rules();
     foreach ($rules as $field => $rulz) {
         if (str_contains($rulz, 'unique:')) {
             $modifiedRules = preg_replace('#unique:([^,]+)([^|,])(\\||$)#', 'unique:$1$2,' . $field, $rulz);
             $modifiedRules = preg_replace('#unique:([^,]+)(,[^,]+)(\\||$)#', 'unique:$1$2,' . $item_id, $modifiedRules);
             $rules[$field] = $modifiedRules;
         }
     }
     // Get localized fields
     $model = $this->model;
     if (isset($model::$polyglot)) {
         $localization = Input::only($model::$polyglot);
     }
     // Validate input
     if ($rules) {
         $validation = Validator::make($input, $rules);
         if ($validation->fails()) {
             $return = Redirect::action($this->controller . '@' . ($isAdd ? 'getCreate' : 'getUpdate'), array($item->id))->withInput()->with('items', $item->id)->withErrors($validation);
             return array('new' => $isAdd, 'errors' => $validation, 'message' => null, 'model' => null, 'return' => $return, 'state' => false);
         }
     }
     // Save attributes
     $model = $item->fill($input);
     $model->touch();
     // Update localized fields
     if (isset($localization)) {
         $model->localize($localization);
     }
     // Create message
     $verb = $isAdd ? 'create' : 'update';
     //$message = Babel::restful($this->item, Arrays::get($input, 'name'), $verb);
     $message = 'The item ' . $input['name'] . ' was correctly updated';
     return array('errors' => false, 'message' => $message, 'model' => $model, 'new' => $isAdd, 'return' => $this->here, 'state' => true);
 }