Beispiel #1
0
 /**
  * Renvoie la structure avec l'id $id
  * @param type $id
  * @return \Root\Src\Model\StructureModel
  */
 public static function loadStructureById($id)
 {
     $result = new StructureModel("", "");
     $statementResult = ConnectionModel::getConnection()->query('Select * from layout where id = :id', ['id' => $id]);
     if ($statementResult) {
         $result->hydrate($statementResult[0]);
     }
     return $result;
 }
 /**
  * Saves a structure
  *
  * @param StructureModel $structure
  *
  * @throws Exception
  * @return bool
  */
 public function saveStructure(StructureModel $structure)
 {
     if ($structure->id) {
         $structureRecord = StructureRecord::model()->findById($structure->id);
         if (!$structureRecord) {
             throw new Exception(Craft::t('No structure exists with the ID “{id}”.', array('id' => $structure->id)));
         }
     } else {
         $structureRecord = new StructureRecord();
     }
     $structureRecord->maxLevels = $structure->maxLevels;
     $success = $structureRecord->save();
     if ($success) {
         $structure->id = $structureRecord->id;
     } else {
         $structure->addErrors($structureRecord->getErrors());
     }
     return $success;
 }