public static function getCardbyCardID($idCart) { $model = Cards::model()->findByPk($idCart); return $model; }
/** * Updates the card and the associated data * @param string $id The card ID * @return JSON */ public function actionUpdateCard($id = NULL) { header('Content-Type: application/json'); $card = $this->getBaseCardConfig($id); $cardData = CJSON::decode($this->getBaseCardById($id)); // Determine the runtime directory $runtimeDirectory = Yii::getPathOfAlias('application.runtime'); $downloadPath = $runtimeDirectory . DIRECTORY_SEPARATOR . 'cards' . DIRECTORY_SEPARATOR . $card['folderName'] . '.zip'; if (!is_writable($runtimeDirectory)) { throw new CHttpException(500, Yii::t('Dashboard.main', 'Runtime directory is not writable')); } $targetFile = fopen($downloadPath, 'w'); // Initiate the CURL request $ch = curl_init($cardData['repository'] . '/archive/master.zip'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILE, $targetFile); curl_exec($ch); // Extract the file $zip = new ZipArchive(); $res = $zip->open($downloadPath); // If we can open the file if ($res === true) { $extractionPath = str_replace('.zip', '', $downloadPath); // Extract it to the appropriate location $extraction = $zip->extractTo($extractionPath); // If we can extract it if ($extraction) { // Update all the cards $cardData = CJSON::decode($this->getBaseCardById($id)); $cards = Cards::model()->findAllByAttributes(array('name' => $id)); foreach ($cards as $c) { $currentData = CJSON::decode($c['data']); $activeSize = $currentData['activeSize']; $newData = $cardData; $newData['activeSize'] = $activeSize; $c->data = CJSON::encode($newData); $c->save(); } unlink($downloadPath); echo CJSON::encode(array('updated' => true)); return true; } } echo CJSON::encode(array('updated' => false, 'reason' => $res)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Cards the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Cards::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
?> </legend> <div class="meta-container"> <?php foreach ($cards as $card) { ?> <?php $card->value = CJSON::decode($card->value); ?> <div class="pure-control-group"> <?php echo CHtml::tag('label', array('class' => 'inline'), Cii::titleize($card->value['class'])); ?> <?php $count = Cards::model()->countByAttributes(array('name' => $card->key)); ?> <p class="text-small inline" style="top: -8px;"><?php echo $card->value['name']; ?> </p> <span class="pure-button pure-button-error pure-button-xsmall pure-button-link-xs pull-right remove-button" id="<?php echo $card->key; ?> "> <span class="icon-remove"></span> </span> <span class="pure-button pure-button-warning pure-button-xsmall pure-button-link-xs pull-right"> <?php echo $count; ?>