本文整理汇总了PHP中Element::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::save方法的具体用法?PHP Element::save怎么用?PHP Element::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aElement !== null) {
if ($this->aElement->isModified() || $this->aElement->isNew()) {
$affectedRows += $this->aElement->save($con);
}
$this->setElement($this->aElement);
}
if ($this->aOrderStatus !== null) {
if ($this->aOrderStatus->isModified() || $this->aOrderStatus->isNew()) {
$affectedRows += $this->aOrderStatus->save($con);
}
$this->setOrderStatus($this->aOrderStatus);
}
if ($this->aClient !== null) {
if ($this->aClient->isModified() || $this->aClient->isNew()) {
$affectedRows += $this->aClient->save($con);
}
$this->setClient($this->aClient);
}
if ($this->isNew()) {
$this->modifiedColumns[] = OrderPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = OrderPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += OrderPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例2: saveBook
public function saveBook()
{
$book = Input::get('book');
$chapters = Input::get('chapters');
$bookMdl = Book::find($book['id']);
$bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']);
$bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']));
$bookMdl->save();
foreach ($chapters as $key => $chapter) {
if ($chapter['id']) {
$chapMdl = Chapter::find($chapter['id']);
} else {
$chapMdl = new Chapter();
}
if ($chapter['id'] && $chapter['isDeleted']) {
$chapMdl->delete();
} else {
$chapMdl->book_id = $chapter['book_id'];
$chapMdl->title = $chapter['title'];
$chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null;
$chapMdl->order = $chapter['order'];
$chapMdl->save();
if (count($chapter['elements'])) {
foreach ($chapter['elements'] as $key => $element) {
if ($element['id']) {
$elementMdl = Element::find($element['id']);
} else {
$elementMdl = new Element();
}
if ($element['id'] && $element['isDeleted']) {
$elementMdl->delete();
} else {
$elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id'];
$elementMdl->order = $element['order'];
$elementMdl->type = $element['type'];
if ($element['type'] == 4 || $element['type'] == 5) {
$elementMdl->content = json_encode($element['content']);
} else {
$elementMdl->content = $element['content'];
}
$elementMdl->note = $element['note'];
$elementMdl->save();
}
}
}
}
}
echo json_encode(['ok']);
}
示例3: _contributorFieldsToElements
private function _contributorFieldsToElements($elementSetId)
{
$db = get_db();
$sql = "SELECT * FROM {$db->ContributionContributorFields}";
$res = $db->query($sql);
$contributorFields = $res->fetchAll();
$contribFieldElementMap = array();
foreach ($contributorFields as $index => $elementInfo) {
$element = new Element();
$element->name = $elementInfo['prompt'];
$element->element_set_id = $elementSetId;
$element->order = $index;
$element->save();
$contribFieldElementMap[$elementInfo['id']] = $element->id;
}
return $contribFieldElementMap;
}
示例4: save
public function save()
{
global $_CONF, $_PATHS;
if (is_object($this->__template)) {
$strServer = Setting::getValueByName('ftp_server');
$strUsername = Setting::getValueByName('ftp_username');
$strPassword = Setting::getValueByName('ftp_password');
$strRemoteFolder = Setting::getValueByName('ftp_remote_folder');
//*** Element.
$objElement = new Element();
$objElement->setParentId($this->__parent->getId());
$objElement->setAccountId($_CONF['app']['account']->getId());
$objElement->setPermissions($this->__permissions);
$objElement->setActive($this->active);
$objElement->setName($this->name);
$objElement->setUsername($this->username);
$objElement->setSort($this->sort);
$objElement->setTypeId(ELM_TYPE_LOCKED);
$objElement->setTemplateId($this->__template->getId());
$objElement->save(true, false);
//*** Activate default schedule.
$objSchedule = new ElementSchedule();
$objSchedule->setStartActive(0);
$objSchedule->setStartDate(APP_DEFAULT_STARTDATE);
$objSchedule->setEndActive(0);
$objSchedule->setEndDate(APP_DEFAULT_ENDDATE);
$objElement->setSchedule($objSchedule);
//*** Alias.
if ($objElement->isPage()) {
$objAlias = new Alias();
$objAlias->setAlias($this->alias);
$objElement->setAlias($objAlias);
}
foreach ($this->__fields as $intTemplateFieldId => $arrField) {
$objTemplateField = TemplateField::selectByPK($intTemplateFieldId);
$objField = new ElementField();
$objField->setElementId($objElement->getId());
$objField->setTemplateFieldId($objTemplateField->getId());
$objField->save();
foreach ($arrField as $intLanguage => $arrValue) {
$objValue = $objField->getNewValueObject();
switch ($objField->getTypeId()) {
case FIELD_TYPE_FILE:
case FIELD_TYPE_IMAGE:
//*** Upload file.
$arrPath = parse_url($arrValue['value']);
if ($arrPath !== false) {
$strFile = @file_get_contents(str_replace(" ", "%20", $arrValue['value']));
if ($strFile !== false) {
$strOriginalName = array_pop(explode("/", $arrPath['path']));
$strLocalValue = ImageField::filename2LocalName($strOriginalName);
$objImageField = new ImageField($intTemplateFieldId);
$arrSettings = $objImageField->getSettings();
if (file_put_contents($_PATHS['upload'] . $strOriginalName, $strFile) !== false) {
if (count($arrSettings) > 1) {
foreach ($arrSettings as $key => $arrSetting) {
$strFileName = FileIO::add2Base($strLocalValue, $arrSetting['key']);
if (copy($_PATHS['upload'] . $strOriginalName, $_PATHS['upload'] . $strFileName)) {
if ($objTemplateField->getTypeId() == FIELD_TYPE_IMAGE && (!empty($arrSetting['width']) || !empty($arrSetting['height']))) {
//*** Resize the image.
$intQuality = empty($arrSetting['quality']) ? 75 : $arrSetting['quality'];
ImageResizer::resize($_PATHS['upload'] . $strFileName, $arrSetting['width'], $arrSetting['height'], $arrSetting['scale'], $intQuality, true, NULL, false, $arrSetting['grayscale']);
}
//*** Move file to remote server.
$objUpload = new SingleUpload();
if (!$objUpload->moveToFTP($strFileName, $_PATHS['upload'], $strServer, $strUsername, $strPassword, $strRemoteFolder)) {
Log::handleError("File {$strFileName} could not be moved to remote server. " . $objUpload->errorMessage());
}
}
}
//*** Move original file.
if (rename($_PATHS['upload'] . $strOriginalName, $_PATHS['upload'] . $strLocalValue)) {
$objUpload = new SingleUpload();
if (!$objUpload->moveToFTP($strLocalValue, $_PATHS['upload'], $strServer, $strUsername, $strPassword, $strRemoteFolder)) {
Log::handleError("File {$strLocalValue} could not be moved to remote server. " . $objUpload->errorMessage());
}
}
//*** Unlink original file.
@unlink($_PATHS['upload'] . $strOriginalName);
} else {
if ($objTemplateField->getTypeId() == FIELD_TYPE_IMAGE && (!empty($arrSettings[0]['width']) || !empty($arrSettings[0]['height']))) {
$strFileName = FileIO::add2Base($strLocalValue, $arrSettings[0]['key']);
//*** Resize the image.
if (rename($_PATHS['upload'] . $strOriginalName, $_PATHS['upload'] . $strFileName)) {
$intQuality = empty($arrSettings[0]['quality']) ? 75 : $arrSettings[0]['quality'];
ImageResizer::resize($_PATHS['upload'] . $strFileName, $arrSettings[0]['width'], $arrSettings[0]['height'], $arrSettings[0]['scale'], $intQuality, true, NULL, false, $arrSettings[0]['grayscale']);
//*** Move file to remote server.
$objUpload = new SingleUpload();
if (!$objUpload->moveToFTP($strFileName, $_PATHS['upload'], $strServer, $strUsername, $strPassword, $strRemoteFolder)) {
Log::handleError("File {$strFileName} could not be moved to remote server.");
}
}
}
//*** Move original file.
if (file_exists($_PATHS['upload'] . $strOriginalName) && rename($_PATHS['upload'] . $strOriginalName, $_PATHS['upload'] . $strLocalValue)) {
//*** Move file to remote server.
$objUpload = new SingleUpload();
if (!$objUpload->moveToFTP($strLocalValue, $_PATHS['upload'], $strServer, $strUsername, $strPassword, $strRemoteFolder)) {
Log::handleError("File {$strLocalValue} could not be moved to remote server.");
}
//.........这里部分代码省略.........
示例5: save
public function save()
{
if (is_object($this->__template)) {
$objCms = PCMS_Client::getInstance();
//*** Element.
$objElement = new Element();
$objElement->setParentId($this->__parent->getId());
$objElement->setAccountId($objCms->getAccount()->getId());
$objElement->setPermissions($this->__permissions);
$objElement->setActive($this->active);
$objElement->setName($this->name);
$objElement->setUsername($this->username);
$objElement->setSort($this->sort);
$objElement->setTypeId(ELM_TYPE_ELEMENT);
$objElement->setTemplateId($this->__template->getId());
$objElement->save();
//*** Activate default schedule.
$objSchedule = new ElementSchedule();
$objSchedule->setStartActive(0);
$objSchedule->setStartDate(PCMS_DEFAULT_STARTDATE);
$objSchedule->setEndActive(0);
$objSchedule->setEndDate(PCMS_DEFAULT_ENDDATE);
$objElement->setSchedule($objSchedule);
foreach ($this->__fields as $apiName => $arrField) {
$objTemplateField = $this->__template->getFieldByName($apiName);
$objField = new ElementField();
$objField->setElementId($objElement->getId());
$objField->setTemplateFieldId($objTemplateField->getId());
$objField->save();
foreach ($arrField as $intLanguage => $arrValue) {
$objValue = $objField->getNewValueObject();
$objValue->setValue($arrValue['value']);
$objValue->setLanguageId($intLanguage);
$objValue->setCascade($arrValue['cascade']);
$objField->setValueObject($objValue);
//*** Activate the language.
$objElement->setLanguageActive($intLanguage, TRUE);
}
}
if (count($this->__fields) == 0) {
//*** Set all languages active if there are no fields.
$objLangs = $objCms->getLanguages();
foreach ($objLangs as $objLang) {
$objElement->setLanguageActive($objLang->getId(), TRUE);
}
}
return new __Element($objElement);
}
}
示例6: _element
/**
* Create an element.
*
* @param string $elementSetName The name of the parent element set.
* @param string $name The element name.
* @return Element
*/
protected function _element($elementSetName = 'Item Type Metadata', $name = 'Test Element')
{
// Get the parent element set.
$elementSet = $this->elementSetTable->findByName($elementSetName);
$element = new Element();
$element->element_set_id = $elementSet->id;
$element->name = 'New Element';
$element->save();
return $element;
}
示例7: installDefaults
/**
* Install default profile
*
* Install default item types, elements, and profiles for easy setup
*
* @param array An array of parameters with names and descriptions
* of the default values we are setting up
* @return void
*/
public function installDefaults($params)
{
if (!($itemType = get_db()->getTable('ItemType')->findByName($params['typeName']))) {
$itemType = new ItemType();
$itemType->name = $params['typeName'];
$itemType->description = $params['typeDesc'];
$id = $itemType->save();
}
require_once dirname(dirname(dirname(__FILE__))) . '/models/MmdProfile.php';
$profile = new MmdProfile();
$profile->setViewer($this);
$profile->name = $params['profileName'];
$profile->viewer = $this->name;
foreach ($this->_paramInfo as $param) {
//$element = new Element();
//check if element exists in Dublin Core
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', $param['name']);
if (empty($element)) {
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', ucfirst($param['name']));
}
if (empty($element)) {
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', strtoupper($param['name']));
}
if (empty($element)) {
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', $param['name']);
}
if (empty($element)) {
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', ucfirst($param['name']));
}
if (empty($element)) {
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', strtoupper($param['name']));
}
if (empty($element)) {
$element = new Element();
$element->setElementSet('Item Type Metadata');
$element->setName($param['name']);
$element->setDescription($param['description']);
try {
$element->save();
} catch (Exception $e) {
print_r($e);
die;
}
}
$itemType->addElementById($element->id);
if (isset($param['default']) && $param['default'] !== '') {
$profile->setAuxParam($param['name'], $param['default'], 1);
}
if (isset($param['files'])) {
$multiple = isset($param['multiple']) && $param['multiple'] != 'single' && $param['multiple'] ? 1 : 0;
$fileparam = array('multiple' => isset($param['multiple']) && $param['multiple'] != 'single' && $param['multiple'] ? 1 : 0, 'extensions' => $param['files']);
$profile->setAuxParam($param['name'], $fileparam, 2);
}
$profile->setAuxParam($param['name'], $element->id, 0);
}
$itemType->save();
$item_type_id = $itemType->id;
$profile->save();
$profile_id = $profile->id;
require_once dirname(dirname(dirname(__FILE__))) . '/models/MmdAssign.php';
$assign = new MmdAssign();
$assign->item_type_id = $item_type_id;
$assign->profile_id = $profile_id;
$assign->filetypes = $this->_allowedFiletypes;
$assign->save();
return 'Defaults installed successfully';
}
示例8: actionimportExcelTable
public function actionimportExcelTable($id, $issueId)
{
//step id
if (isset($_FILES['Excel'])) {
$post = Result::model()->importExcelTable($_FILES['Excel']);
//var_dump($post);
Yii::import('ext.phpexcel.IOFactory');
Yii::import('ext.phpexcel.*');
Yii::import('ext.phpexcel.XPHPExcel');
Yii::import('ext.phpexcel.shared.string');
$newsheet = XPHPExcel::createPHPExcel();
$inputFileName = $post;
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (PHPExcel_Reader_Exception $e) {
die('Error loadinng file: ' . $post);
//$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumnIndex = $sheet->getHighestColumn();
$index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
$highestColumn = $index[$highestColumnIndex];
$index = array_slice($index, 0, $highestColumn);
$element = new Element();
$element->stepId = $id;
$element->typeId = 13;
$element->save();
$elementId = $element->id;
$step = $this->loadModel($id);
for ($row = 1; $row <= $highestRow; $row++) {
$rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
}
$columns = array();
foreach ($index as $key => $position) {
$columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
}
//$salida=$step->addGrid($element, $rows, $columns);
$issue = new Issue();
for ($row = 1; $row <= $highestRow; $row++) {
foreach ($index as $key => $position) {
if ($row >= 1 && $position > 0) {
$result = new Result();
$result->elementId = $elementId;
$result->issueId = $issueId;
$result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
$result->colonne = $position - 1;
$result->ligne = $row - 2;
throw new CHttpException(403, 'row: ' . $result->ligne . '. Columna: ' . $result->colonne . '.Value: ' . $result->value);
$result->save();
}
}
}
//$this->redirect(array('view','id'=>$id));
} else {
throw new CHttpException(403, "Failure loading file");
}
}
示例9: importElements
public static function importElements($objElements, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, &$arrElementIds, &$arrElementFieldIds, $arrLinkFieldIds, $arrLanguageIds, $arrUserIds, $arrGroupIds, $arrStorageIds, $arrFeedIds, $intParentId = 0)
{
global $intDefaultLanguage;
$strElmntPattern = "/(\\?eid=)([0-9]+)/ie";
$strStoragePattern = "/(\\?mid=)([0-9]+)/ie";
foreach ($objElements->childNodes as $elementNode) {
if (!is_null($arrTemplateIds[$elementNode->getAttribute("templateId")])) {
$objElement = new Element();
$objElement->setAccountId($intAccountId);
$objElement->setParentId($intParentId);
$objElement->setActive($elementNode->getAttribute("active"));
$objElement->setIsPage($elementNode->getAttribute("isPage"));
$objElement->setName($elementNode->getAttribute("name"));
$objElement->setApiName($elementNode->getAttribute("apiName"));
$objElement->setDescription($elementNode->getAttribute("description"));
$objElement->setUsername($elementNode->getAttribute("username"));
$objElement->setTypeId($elementNode->getAttribute("typeId"));
$objElement->setTemplateId($arrTemplateIds[$elementNode->getAttribute("templateId")]);
$objElement->setSort($elementNode->getAttribute("sort"));
$objElement->save(false, false);
if ($elementNode->getAttribute("typeId") == 1) {
$objElement->setLanguageActive($intDefaultLanguage, 1);
}
$arrElementIds[$elementNode->getAttribute("id")] = $objElement->getId();
//*** Schedule.
$objSchedule = new ElementSchedule();
$objSchedule->setStartActive($elementNode->getAttribute("scheduleStartActive"));
$objSchedule->setStartDate($elementNode->getAttribute("scheduleStartDate"));
$objSchedule->setEndActive($elementNode->getAttribute("scheduleEndActive"));
$objSchedule->setEndDate($elementNode->getAttribute("scheduleEndDate"));
$objElement->setSchedule($objSchedule);
//*** Add fields to the element.
foreach ($elementNode->childNodes as $subNode) {
switch ($subNode->nodeName) {
case "fields":
$arrActiveLangs = array();
foreach ($subNode->childNodes as $fieldNode) {
switch ($fieldNode->nodeName) {
case "field":
$objField = new ElementField();
$objField->setElementId($objElement->getId());
$objField->setTemplateFieldId($arrTemplateFieldIds[$fieldNode->getAttribute("templateFieldId")]);
$objField->setSort($fieldNode->getAttribute("sort"));
$objField->save();
foreach ($fieldNode->childNodes as $languageNode) {
$objValue = $objField->getNewValueObject();
$objValue->setValue($languageNode->nodeValue);
$objValue->setLanguageId($arrLanguageIds[$languageNode->getAttribute("id")]);
$objValue->setCascade($languageNode->getAttribute("cascade"));
$objField->setValueObject($objValue);
$arrActiveLangs[$languageNode->getAttribute("id")] = $languageNode->getAttribute("active");
if (preg_match($strElmntPattern, $languageNode->nodeValue) > 0) {
array_push($arrElementFieldIds["largeText"], $objField->getId());
}
if (preg_match($strStoragePattern, $languageNode->nodeValue) > 0) {
array_push($arrElementFieldIds["largeText"], $objField->getId());
}
}
if (in_array($fieldNode->getAttribute("templateFieldId"), $arrLinkFieldIds)) {
array_push($arrElementFieldIds["link"], $objField->getId());
}
break;
}
}
foreach ($arrActiveLangs as $key => $value) {
$objElement->setLanguageActive($arrLanguageIds[$key], $value);
}
break;
case "feed":
foreach ($subNode->childNodes as $feedFieldNode) {
if ($feedFieldNode->nodeName == "feedfield") {
$objFeedField = new ElementFieldFeed();
$objFeedField->setElementId($objElement->getId());
$objFeedField->setTemplateFieldId($arrTemplateFieldIds[$feedFieldNode->getAttribute("templateFieldId")]);
$objFeedField->setFeedPath($feedFieldNode->getAttribute("feedPath"));
$objFeedField->setXpath($feedFieldNode->getAttribute("xpath"));
$objFeedField->setLanguageId($arrLanguageIds[$feedFieldNode->getAttribute("languageId")]);
$objFeedField->setCascade($feedFieldNode->getAttribute("cascade"));
$objFeedField->setSort($feedFieldNode->getAttribute("sort"));
$objFeedField->save();
}
}
$objFeed = new ElementFeed();
$objFeed->setElementId($objElement->getId());
$objFeed->setFeedId($arrFeedIds[$subNode->getAttribute("feedId")]);
$objFeed->setFeedPath($subNode->getAttribute("feedPath"));
$objFeed->setMaxItems($subNode->getAttribute("maxItems"));
$objFeed->setSortBy($subNode->getAttribute("sortBy"));
$objFeed->setAliasField($subNode->getAttribute("aliasField"));
$objFeed->save();
break;
case "meta":
$arrMetaFields = array("title", "keywords", "description");
foreach ($subNode->childNodes as $metaFieldNode) {
if ($metaFieldNode->nodeName == "language") {
$intLanguageId = $arrLanguageIds[$metaFieldNode->getAttribute("id")];
foreach ($arrMetaFields as $value) {
$objMeta = new ElementMeta();
$objMeta->setName($value);
$objMeta->setValue($metaFieldNode->getAttribute($value));
//.........这里部分代码省略.........
示例10: createFile
protected function createFile($step)
{
$file = new File('create');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['File'])) {
$file->attributes = $_POST['File'];
$stepId = $step->id;
$file->stepId = $stepId;
$file->attributes = $_POST['File'];
$upload = CUploadedFile::getInstance($file, 'fileSelected');
if (!$upload) {
return $file;
}
if (@getimagesize($upload->tempName)) {
$file->image = 1;
} else {
$file->image = 0;
}
$rnd = rand(0, 99999);
$fileName = "{$rnd}-{$upload}";
// random number + file name
$file->fileSelected = $upload;
$link = "step/" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $fileName);
$file->link = $link;
if ($upload->saveAs(Yii::app()->params['dfs'] . "/{$link}")) {
if ($step->addFile($file)) {
$element = new Element();
$element->fileId = $file->id;
$element->stepId = $step->id;
$element->typeId = 12;
$element->position = $step->elementCount + 1;
$element->save();
Yii::app()->user->setFlash('fileSubmitted', Yii::t('default', "Your file has been added"));
$this->refresh();
}
}
}
return $file;
}
示例11: saveNewName
function saveNewName()
{
if (!$this->session->userdata('logged_in')) {
$this->_fullOut('failure', array(), "not loged in");
return false;
}
$element = new Element($this->oh, $_POST['element_id']);
$element->main_name = $_POST['name'];
$element->save();
$this->_fullOut('success', $_POST);
}
示例12: getElement
protected function getElement($fieldId)
{
if (key_exists($fieldId, $this->fieldIdElementsMap)) {
return $this->fieldIdElementsMap[$fieldId];
}
//dig up the field's prompt with (yet) another query to the source API
$response = $this->service->contribution_contributor_fields->get($fieldId);
// @TODO, error handling. keep it here instead of another adapter
// to be able to cache
$fieldData = json_decode($response->getBody(), true);
$prompt = $fieldData['prompt'];
$element = get_db()->getTable('Element')->findByElementSetNameAndElementName(self::ELEMENT_SET_NAME, $prompt);
if ($element) {
$this->fieldIdElementsMap[$fieldId] = $element;
return $element;
}
//import the field as an element
$elementSet = $this->getElementSet();
$element = new Element();
$element->element_set_id = $elementSet->id;
$element->name = $prompt;
$element->description = '';
$element->comment = '';
$element->save();
$this->fieldIdElementsMap[$fieldId] = $element;
return $element;
}
示例13: actionimportExcelTableTraveler
public function actionimportExcelTableTraveler($id)
{
//step id
if (isset($_FILES['Excel'])) {
$post = Result::model()->importExcelTable($_FILES['Excel']);
Yii::import('ext.phpexcel.IOFactory');
Yii::import('ext.phpexcel.*');
Yii::import('ext.phpexcel.XPHPExcel');
Yii::import('ext.phpexcel.shared.string');
$newsheet = XPHPExcel::createPHPExcel();
$inputFileName = $post;
$reader = PHPExcel_IOFactory::createReader('Excel2007');
if (!$reader->canRead($inputFileName)) {
throw new CHttpException(403, "File not valid");
}
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumnIndex = $sheet->getHighestColumn();
if ($highestRow > 40) {
throw new CHttpException(403, "Rows limit exceed. ");
}
$index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
if ($highestColumnIndex > 'H') {
throw new CHttpException(403, "Column limit exceed. ");
}
$highestColumn = $index[$highestColumnIndex];
$index = array_slice($index, 0, $highestColumn);
$element = new Element();
$element->stepId = $id;
$element->typeId = 13;
$element->save();
$elementId = $element->id;
$step = $this->loadModel($id);
for ($row = 1; $row <= $highestRow; $row++) {
$rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
}
$columns = array();
foreach ($index as $key => $position) {
$columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
}
$salida = $step->addGrid($element, $rows, $columns);
//$issue= $this->loadIssue($issueId);
$this->redirect(array('/step/view', 'id' => $id));
//this one
} else {
throw new CHttpException(403, "Failure loading file");
}
}
示例14: createForcedElements
private function createForcedElements()
{
global $_CONF;
$objTemplates = $this->getSubTemplates();
foreach ($objTemplates as $objTemplate) {
if ($objTemplate->getForceCreation()) {
//*** Create a child element based on this template.
$objPermissions = new ElementPermission();
$objPermissions->setUserId($this->getPermissions()->getUserId());
$objPermissions->setGroupId($this->getPermissions()->getGroupId());
$objElement = new Element();
$objElement->setParentId($this->getId());
$objElement->setAccountId($_CONF['app']['account']->getId());
$objElement->setPermissions($objPermissions);
$objElement->setActive($this->getActive());
$objElement->setIsPage(0);
$objElement->setName($objTemplate->getName());
$objElement->setUsername($this->getUsername());
$objElement->setTypeId(ELM_TYPE_ELEMENT);
$objElement->setTemplateId($objTemplate->getId());
$objElement->save();
$objSchedule = new ElementSchedule();
$objSchedule->setStartActive(0);
$objSchedule->setStartDate(APP_DEFAULT_STARTDATE);
$objSchedule->setEndActive(0);
$objSchedule->setEndDate(APP_DEFAULT_ENDDATE);
$objElement->setSchedule($objSchedule);
$objElement->setLanguageActive(ContentLanguage::getDefault()->getId(), TRUE);
}
}
}
示例15: actionimportExcelTable
public function actionimportExcelTable($id, $issueId)
{
//step id
if (isset($_FILES['Excel'])) {
$post = Result::model()->importExcelTable($_FILES['Excel']);
//throw new CHttpException(403,$_FILES['File']);
Yii::import('ext.phpexcel.IOFactory');
Yii::import('ext.phpexcel.*');
Yii::import('ext.phpexcel.XPHPExcel');
Yii::import('ext.phpexcel.shared.string');
$newsheet = XPHPExcel::createPHPExcel();
//$inputFileName='c:\inetpub\wwwroot\vector2014\protected\extensions\examples\reader\sampledata\book1.xlsx';
$inputFileName = $post["tmp_name"];
Result::model()->alsjkd($inputFileName);
//var_dump($post);
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (PHPExcel_Reader_Exception $e) {
die('Error loading file: ' . $e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumnIndex = $sheet->getHighestColumn();
$index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
$highestColumn = $index[$highestColumnIndex];
$index = array_slice($index, 0, $highestColumn);
$element = new Element();
$element->stepId = $id;
$element->typeId = 13;
$element->save();
$elementId = $element->id;
$step = $this->loadModel($id);
for ($row = 1; $row <= $highestRow; $row++) {
$rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
}
$columns = array();
//for ($column =1 ; $column<=$highestColumn; $column++){
foreach ($index as $key => $position) {
$columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
}
$salida = $step->addGrid($element, $rows, $columns);
$issue = new Issue();
//$travelerId= $step->travelerId;
for ($row = 1; $row <= $highestRow; $row++) {
foreach ($index as $key => $position) {
if ($row >= 1 && $position > 0) {
$result = new Result();
$result->elementId = $elementId;
$result->issueId = $issueId;
$result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
//throw new CHttpException(403, 'row: '.$row.'. Columna: '.$position.'.Value: '.$result->value);
$result->colonne = $position - 1;
$result->ligne = $row - 2;
$result->save();
}
//throw new CHttpException (403,"exception: ". $iasdasdeId);
//$objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A',$row)->getValue();
}
}
$alsdjk = $LKSJAD;
} else {
$alsdjk = $LKSJAD;
throw new CHttpException(403, "Error in the file");
}
}