public function create(CuratedListModel $curatedList, SiteModel $site, UserAccountModel $creator)
 {
     global $DB;
     try {
         $DB->beginTransaction();
         $stat = $DB->prepare("SELECT max(slug) AS c FROM curated_list_information WHERE site_id=:site_id");
         $stat->execute(array('site_id' => $site->getId()));
         $data = $stat->fetch();
         $curatedList->setSlug($data['c'] + 1);
         $stat = $DB->prepare("INSERT INTO curated_list_information (site_id, slug, title,description,created_at,is_deleted) " . "VALUES (:site_id, :slug, :title,:description, :created_at,'0') RETURNING id");
         $stat->execute(array('site_id' => $site->getId(), 'slug' => $curatedList->getSlug(), 'title' => substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'description' => $curatedList->getDescription(), 'created_at' => \TimeSource::getFormattedForDataBase()));
         $data = $stat->fetch();
         $curatedList->setId($data['id']);
         $stat = $DB->prepare("INSERT INTO curated_list_history (curated_list_id, title, description, user_account_id  , created_at, is_deleted, is_new) VALUES " . "(:curated_list_id, :title, :description, :user_account_id  , :created_at, '0', '1')");
         $stat->execute(array('curated_list_id' => $curatedList->getId(), 'title' => substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'description' => $curatedList->getDescription(), 'user_account_id' => $creator->getId(), 'created_at' => \TimeSource::getFormattedForDataBase()));
         $stat = $DB->prepare("INSERT INTO user_in_curated_list_information (user_account_id,curated_list_id,is_owner,created_at) " . " VALUES (:user_account_id,:curated_list_id,:is_owner,:created_at) ");
         $stat->execute(array('user_account_id' => $creator->getId(), 'curated_list_id' => $curatedList->getId(), 'is_owner' => '1', 'created_at' => \TimeSource::getFormattedForDataBase()));
         $DB->commit();
     } catch (Exception $e) {
         $DB->rollBack();
     }
 }
 public function update(CuratedListModel $curatedList, $fields, UserAccountModel $user = null)
 {
     $alreadyInTransaction = $this->db->inTransaction();
     // Make Information Data
     $fieldsSQL1 = array();
     $fieldsParams1 = array('id' => $curatedList->getId());
     foreach ($fields as $field) {
         $fieldsSQL1[] = " " . $field . "=:" . $field . " ";
         if ($field == 'title') {
             $fieldsParams1['title'] = substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
         } else {
             if ($field == 'description') {
                 $fieldsParams1['description'] = $curatedList->getDescription();
             } else {
                 if ($field == 'parent_area_id') {
                     $fieldsParams1['parent_area_id'] = $curatedList->getParentAreaId();
                 } else {
                     if ($field == 'is_deleted') {
                         $fieldsParams1['is_deleted'] = $curatedList->getIsDeleted() ? 1 : 0;
                     }
                 }
             }
         }
     }
     // Make History Data
     $fieldsSQL2 = array('curated_list_id', 'user_account_id', 'created_at');
     $fieldsSQLParams2 = array(':curated_list_id', ':user_account_id', ':created_at');
     $fieldsParams2 = array('curated_list_id' => $curatedList->getId(), 'user_account_id' => $user ? $user->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase());
     foreach ($this->possibleFields as $field) {
         if (in_array($field, $fields) || $field == 'title') {
             $fieldsSQL2[] = " " . $field . " ";
             $fieldsSQLParams2[] = " :" . $field . " ";
             if ($field == 'title') {
                 $fieldsParams2['title'] = substr($curatedList->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED);
             } else {
                 if ($field == 'description') {
                     $fieldsParams2['description'] = $curatedList->getDescription();
                 } else {
                     if ($field == 'is_deleted') {
                         $fieldsParams2['is_deleted'] = $curatedList->getIsDeleted() ? 1 : 0;
                     }
                 }
             }
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " 0 ";
         } else {
             $fieldsSQL2[] = " " . $field . "_changed ";
             $fieldsSQLParams2[] = " -2 ";
         }
     }
     try {
         if (!$alreadyInTransaction) {
             $this->db->beginTransaction();
         }
         // Information SQL
         $stat = $this->db->prepare("UPDATE curated_list_information  SET " . implode(",", $fieldsSQL1) . " WHERE id=:id");
         $stat->execute($fieldsParams1);
         // History SQL
         $stat = $this->db->prepare("INSERT INTO curated_list_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")");
         $stat->execute($fieldsParams2);
         if (!$alreadyInTransaction) {
             $this->db->commit();
         }
     } catch (Exception $e) {
         if (!$alreadyInTransaction) {
             $this->db->rollBack();
         }
         throw $e;
     }
 }
 protected function checkCuratedListInTest1(CuratedListModel $curatedList)
 {
     $this->assertEquals("test this!", $curatedList->getDescription());
     $this->assertEquals("test", $curatedList->getTitle());
 }