/** * Prepare some specific data. */ public function prepareData() { $this->slug = $this->id . ':' . $this->alias; $this->catslug = $this->getCatSlug(); // Calculate funded percent if (!$this->goal) { $this->fundedPercent = 0; } else { $this->fundedPercent = (string) Prism\Utilities\MathHelper::calculatePercentage($this->funded, $this->goal, 0); } // Calculate end date if ($this->funding_days > 0) { $fundingStartDateValidator = new Prism\Validator\Date($this->funding_start); if (!$fundingStartDateValidator->isValid()) { $this->funding_end = '1000-01-01'; } else { $fundingStartDate = new Crowdfunding\Date($this->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days); $this->funding_end = $fundingEndDate->toSql(); } } // Calculate days left $today = new Crowdfunding\Date(); $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end); }
/** * Method to load a row from the database by primary key and bind the fields * to the JTable instance properties. * * @param mixed $keys An optional primary key value to load the row by, or an array of fields to match. If not * set the instance property value is used. * @param boolean $reset True to reset the default values before loading the new row. * * @return boolean True if successful. False if row not found or on error (internal error state set in that case). * * @link http://docs.joomla.org/JTable/load * @since 11.1 */ public function load($keys = null, $reset = true) { parent::load($keys, $reset); $this->slug = $this->id . ':' . $this->alias; // Calculate funded percent if (!$this->goal) { $this->fundedPercent = 0; } else { $this->fundedPercent = (string) Prism\Utilities\MathHelper::calculatePercentage($this->funded, $this->goal, 0); } // Calculate end date if ($this->funding_days > 0) { $fundingStartDateValidator = new Prism\Validator\Date($this->funding_start); if (!$fundingStartDateValidator->isValid()) { $this->funding_end = '0000-00-00'; } else { $fundingStartDate = new Crowdfunding\Date($this->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days); $this->funding_end = $fundingEndDate->toSql(); } } // Calculate days left $today = new Crowdfunding\Date(); $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end); return true; }
/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return mixed Object on success, false on failure. */ public function getItem($id = 0) { if ((int) $id === 0) { $id = $this->getState($this->context . '.id'); } $storedId = $this->getStoreId($id); if (!array_key_exists($storedId, $this->item)) { $this->item[$storedId] = null; $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.short_desc, a.image, ' . 'a.funded, a.goal, a.user_id, a.funding_type, ' . 'a.funding_start, a.funding_end, a.funding_days, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug, ' . 'b.name AS user_name, ' . $query->concatenate(array('c.id', 'c.alias'), ':') . ' AS catslug ')->from($db->quoteName('#__crowdf_projects', 'a'))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where('a.id = ' . (int) $id)->where('a.published = 1')->where('a.approved = 1'); $db->setQuery($query, 0, 1); $result = $db->loadObject(); // Attempt to load the row. if ($result !== null and is_object($result)) { // Calculate funded percentage. $result->funded_percents = Prism\Utilities\MathHelper::calculatePercentage($result->funded, $result->goal, 0); // Calculate days left $today = new Crowdfunding\Date(); $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end); $this->item[$storedId] = $result; } } return $this->item[$storedId]; }
public function getItem($itemId, $userId) { $storedId = $this->getStoreId($itemId . $userId); if (!array_key_exists($storedId, $this->items)) { $db = $this->getDbo(); /** @var $db JDatabaseDriver */ // Create a new query object. $query = $db->getQuery(true); // Select the required fields from the table. $query->select('a.id, a.title, a.alias, a.short_desc, a.description, a.image, a.image_square, a.image_small, a.location_id, ' . 'a.goal, a.funded, a.funding_type, a.funding_start, a.funding_end, a.funding_days, ' . 'a.pitch_video, a.pitch_image, a.hits, a.created, a.featured, a.published, a.approved, a.ordering, a.catid, a.type_id, a.user_id, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug, ' . 'b.name AS user_name, ' . $query->concatenate(array('c.id', 'c.alias'), ':') . ' AS catslug'); $query->from($db->quoteName('#__crowdf_projects', 'a')); $query->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id'); $query->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id'); $query->where('a.id = ' . (int) $itemId); $query->where('a.user_id = ' . (int) $userId); $db->setQuery($query); $item = $db->loadObject(); if (is_object($item)) { // Calculate funding end date $startingDateValidator = new Prism\Validator\Date($item->funding_start); if ((int) $item->funding_days > 0 and $startingDateValidator->isValid()) { $fundingStartDate = new Crowdfunding\Date($item->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($item->funding_days); $item->funding_end = $fundingEndDate->format(Prism\Constants::DATE_FORMAT_SQL_DATE); } // Calculate funded percentage. $item->funded_percents = Prism\Utilities\MathHelper::calculatePercentage($item->funded, $item->goal, 0); // Calculate days left $today = new Crowdfunding\Date(); $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end); } else { $item = new stdClass(); } $this->items[$storedId] = $item; } return $this->items[$storedId]; }
/** * Method to get an object. * * @param integer $id The id of the object to get. * * @throws \RuntimeException * @return stdClass|null Object on success, null on failure. */ public function getItem($id = 0) { if ((int) $id === 0) { $id = $this->getState('id'); } if ($this->item === null) { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.short_desc, a.image, ' . 'a.funded, a.goal, a.pitch_video, a.pitch_image, ' . 'a.funding_start, a.funding_end, a.funding_days, ' . 'a.funding_type, a.user_id, a.type_id, ' . 'b.name AS user_name, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug, ' . $query->concatenate(array('c.id', 'c.alias'), ':') . ' AS catslug')->from($db->quoteName('#__crowdf_projects', 'a'))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where('a.id = ' . (int) $id)->where('a.published = 1')->where('a.approved = 1'); $db->setQuery($query, 0, 1); $result = $db->loadObject(); // Attempt to load the row. if (is_object($result)) { // Calculate ending date by days left. if ($result->funding_days > 0) { $fundingStartDate = new Crowdfunding\Date($result->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days); $result->funding_end = $fundingEndDate->format(Prism\Constants::DATE_FORMAT_SQL_DATE); } // Calculate funded percent $result->funded_percents = Prism\Utilities\MathHelper::calculatePercentage($result->funded, $result->goal, 0); // Calculate days left. $today = new Crowdfunding\Date(); $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end); $this->item = $result; } } return $this->item; }
public function prepareItems(array $items) { $result = array(); foreach ($items as $key => $item) { $result[$key] = $item; // Calculate funding end date if ((int) $item->funding_days > 0) { $fundingStartDate = new Crowdfunding\Date($item->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($item->funding_days); $result[$key]->funding_end = $fundingEndDate->format('Y-m-d'); } // Calculate funded percentage. $result[$key]->funded_percents = Prism\Utilities\MathHelper::calculatePercentage($item->funded, $item->goal, 0); // Calculate days left $today = new Crowdfunding\Date(); $result[$key]->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end); } return $result; }
/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return mixed Object on success, false on failure. */ public function getItem($id = 0) { if ((int) $id === 0) { $id = $this->getState($this->context . '.id'); } $storedId = $this->getStoreId($id); if (!array_key_exists($storedId, $this->item)) { $this->item[$storedId] = null; $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.short_desc, a.description, a.image, a.location_id, ' . 'a.funded, a.goal, a.pitch_video, a.pitch_image, ' . 'a.funding_start, a.funding_end, a.funding_days, a.funding_type, ' . 'a.catid, a.user_id, a.published, a.approved, a.hits, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug, ' . $query->concatenate(array('b.id', 'b.alias'), ':') . ' AS catslug')->from($db->quoteName('#__crowdf_projects', 'a'))->innerJoin($db->quoteName('#__categories', 'b') . ' ON a.catid = b.id')->where('a.id = ' . (int) $id); $db->setQuery($query, 0, 1); $result = $db->loadObject(); // Attempt to load the row. if ($result !== null and is_object($result)) { // Calculate end date if ((int) $result->funding_days > 0) { $fundingStartDateValidator = new Prism\Validator\Date($result->funding_start); if (!$fundingStartDateValidator->isValid()) { $result->funding_end = '0000-00-00'; } else { $fundingStartDate = new Crowdfunding\Date($result->funding_start); $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days); $result->funding_end = $fundingEndDate->format('Y-m-d'); } } // Calculate funded percentage. $result->funded_percents = Prism\Utilities\MathHelper::calculatePercentage($result->funded, $result->goal, 0); // Calculate days left. $today = new Crowdfunding\Date(); $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end); $this->item[$storedId] = $result; } } return $this->item[$storedId]; }