Backend\Core\Engine\Model::getExtras PHP Method

getExtras() public static method

Get extras
public static getExtras ( array $ids ) : array
$ids array The ids of the modules_extras to get.
return array
    public static function getExtras($ids)
    {
        // get db
        $db = self::getContainer()->get('database');
        // loop and cast to integers
        foreach ($ids as &$id) {
            $id = (int) $id;
        }
        // create an array with an equal amount of question marks as ids provided
        $extraIdPlaceHolders = array_fill(0, count($ids), '?');
        // get extras
        return (array) $db->getRecords('SELECT i.*
             FROM modules_extras AS i
             WHERE i.id IN (' . implode(', ', $extraIdPlaceHolders) . ')', $ids);
    }

Usage Example

Example #1
0
 /**
  * Update the widget so it shows the correct title and has the correct template
  */
 private function updateWidget()
 {
     $editUrl = Model::createURLForAction('Edit', 'ContentBlocks', (string) $this->locale) . '&id=' . $this->id;
     // update data for the extra
     // @TODO replace this with an implementation with doctrine
     $extras = Model::getExtras([$this->extraId]);
     $extra = reset($extras);
     $data = ['id' => $this->id, 'language' => (string) $this->locale, 'edit_url' => $editUrl];
     if (isset($extra['data'])) {
         $data = $data + (array) $extra['data'];
     }
     $data['custom_template'] = $this->template;
     $data['extra_label'] = $this->title;
     Model::updateExtra($this->extraId, 'data', $data);
 }